<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: Start process of Ivycomponent in ManagedBean</title><link>https://answers.axonivy.com/questions/2736/start-process-of-ivycomponent-in-managedbean</link><description>&lt;p&gt;Hi everyone,
I had a dialog, and an ivyComponent. component is included into dialog
When i try to call process in Logic of Dialog like this, it work fine.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;    FacesContext context = FacesContext.getCurrentInstance();
    ExpressionFactory elFactory = context.getApplication().getExpressionFactory();
    ELContext elContext = context.getELContext();
    MethodExpression methodExpression = elFactory
            .createMethodExpression(elContext, "#{logic.mainMethod()}", String.class, new Class[0]);
    MethodInfo info = methodExpression.getMethodInfo(elContext);
    methodExpression.invoke(elContext, new Object[0]);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But when i try to call componentMethod() in component logic, it show method not found error : method not  found &lt;strong&gt;example.main.componentMethod().&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Update : each dialog had it own ManagedBean, and i fail to call when i use component ManagedBean.&lt;/p&gt;
&lt;p&gt;Seem like current context is not belong to component, have anyone meet this before ?&lt;/p&gt;
&lt;p&gt;Thank you :)&lt;/p&gt;
&lt;p&gt;&lt;img alt="alt text" src="http://answers.axonivy.com/upfiles/Capture.PNG"&gt;&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/2736/start-process-of-ivycomponent-in-managedbean" rel="self"></atom:link><language>en</language><lastBuildDate>Mon, 10 Jul 2017 03:19:36 -0400</lastBuildDate><item><title>Comment by docvominh on trungdv's answer</title><link>https://answers.axonivy.com/questions/2736/start-process-of-ivycomponent-in-managedbean#2741</link><description>&lt;p&gt;hi &lt;a href="http://answers.axonivy.com/users/118/trungdv"&gt;&lt;a href="http://answers.axonivy.com/users/118/trungdv"&gt;@trungdv&lt;/a&gt;&lt;/a&gt;,
i add some logic to check if "prepareFile" not done, uploadDocument will not be run :)
but i meet some new issue, that i can not add FacesMessage to ivy Component.
my code&lt;/p&gt;
&lt;p&gt;FacesContext context = FacesContext.getCurrentInstance();
        context.addMessage(null,new FacesMessage(FacesMessage.SEVERITY_ERROR, "MESSAGE CONTENT", "MESSAGE CONTENT"));&lt;/p&gt;
&lt;p&gt;warning :
There are some unhandled FacesMessages, this means not every FacesMessage had a chance to be rendered.
These unhandled FacesMessages are: 
- MESSAGE CONTENT&lt;/p&gt;
&lt;p&gt;I afraid that current context is belong to father dialog.&lt;/p&gt;
&lt;p&gt;Thank you&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">docvominh</dc:creator><pubDate>Mon, 10 Jul 2017 03:19:36 -0400</pubDate><guid>https://answers.axonivy.com/questions/2736/start-process-of-ivycomponent-in-managedbean#2741</guid></item><item><title>Comment by docvominh on trungdv's answer</title><link>https://answers.axonivy.com/questions/2736/start-process-of-ivycomponent-in-managedbean#2740</link><description>&lt;p&gt;hi &lt;a href="http://answers.axonivy.com/users/118/trungdv"&gt;&lt;a href="http://answers.axonivy.com/users/118/trungdv"&gt;@trungdv&lt;/a&gt;&lt;/a&gt;,&lt;/p&gt;
&lt;p&gt;thank for your ideal, i will try it soon and reply to you.&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">docvominh</dc:creator><pubDate>Sat, 08 Jul 2017 09:28:28 -0400</pubDate><guid>https://answers.axonivy.com/questions/2736/start-process-of-ivycomponent-in-managedbean#2740</guid></item><item><title>Comment by trungdv on trungdv's answer</title><link>https://answers.axonivy.com/questions/2736/start-process-of-ivycomponent-in-managedbean#2739</link><description>&lt;p&gt;hi &lt;a href="http://answers.axonivy.com/users/844/docvominh"&gt;&lt;a href="http://answers.axonivy.com/users/844/docvominh"&gt;@docvominh&lt;/a&gt;&lt;/a&gt;
That's great when it works for your case. &lt;/p&gt;
&lt;p&gt;What about exeption case? when something wrong happen in prepareFile, can we stop processing uploadDocument?&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">trungdv</dc:creator><pubDate>Fri, 07 Jul 2017 06:33:32 -0400</pubDate><guid>https://answers.axonivy.com/questions/2736/start-process-of-ivycomponent-in-managedbean#2739</guid></item><item><title>Answer by docvominh</title><link>https://answers.axonivy.com/questions/2736/start-process-of-ivycomponent-in-managedbean/2738</link><description>&lt;p&gt;Hi &lt;a href="http://answers.axonivy.com/users/118/trungdv"&gt;&lt;a href="http://answers.axonivy.com/users/118/trungdv"&gt;@trungdv&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Thanks for your comment.&lt;/p&gt;
&lt;p&gt;I really like to do everything in ManagedBean.  Fortunately, i found new way to achieve my goal.&lt;/p&gt;
&lt;p&gt;use actionListener to call ManagedBean method, and action to call ivy method, when managedBean is done, ivy method start to call.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;p:commandButton actionListener="#{sPDocumentBean.prepareFile}" action="#{logic.uploadDocument}" value="Save"/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Thank you :)&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">docvominh</dc:creator><pubDate>Fri, 07 Jul 2017 05:32:40 -0400</pubDate><guid>https://answers.axonivy.com/questions/2736/start-process-of-ivycomponent-in-managedbean/2738</guid></item><item><title>Answer by trungdv</title><link>https://answers.axonivy.com/questions/2736/start-process-of-ivycomponent-in-managedbean/2737</link><description>&lt;p&gt;hi &lt;a href="http://answers.axonivy.com/users/844/docvominh"&gt;&lt;a href="http://answers.axonivy.com/users/844/docvominh"&gt;@docvominh&lt;/a&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I have nearly the same case and i can call ivy method by this function:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;public static Object evalELExpressionAsObject(String expression, FacesContext context)  {
        ExpressionFactory expressionFactory = context.getApplication().getExpressionFactory();
        ELContext elContext = context.getELContext();
        ValueExpression vex = expressionFactory.createValueExpression(elContext, expression, Object.class);
        Object result = (Object) vex.getValue(elContext);
        return result;
    }
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here is calling:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;evalELExpressionAsObject("#{logic.doSomething()}", FacesContext.getCurrentInstance());
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;but in my experience, we only can call methods if they belong to Main Page (in your example) and can't call method of ComponentProcess component. &lt;/p&gt;
&lt;p&gt;Because ivy have the mechanism to resolve keyword #data and #logic in correct context (see &lt;a href="http://answers.axonivy.com/questions/2549/mechanism-to-resolve-data-and-logic-of-htmluserdialog)"&gt;http://answers.axonivy.com/questions/2549/mechanism-to-resolve-data-and-logic-of-htmluserdialog)&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;So when you evaluate those twos manually, it will take the biggest context (the page). &lt;/p&gt;
&lt;p&gt;P/S: once i can get the method of sub-component sucessfully but it lead to a lot of issue with security in ivy, so i suggest you should not do that (it look like a hack). You can introduce a managed bean for your component and you can call methods from there.&lt;/p&gt;
&lt;p&gt;Cheers,&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">trungdv</dc:creator><pubDate>Thu, 06 Jul 2017 23:04:09 -0400</pubDate><guid>https://answers.axonivy.com/questions/2736/start-process-of-ivycomponent-in-managedbean/2737</guid></item></channel></rss>