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.

    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]);

But when i try to call componentMethod() in component logic, it show method not found error : method not found example.main.componentMethod().

Update : each dialog had it own ManagedBean, and i fail to call when i use component ManagedBean.

Seem like current context is not belong to component, have anyone meet this before ?

Thank you :)

alt text

This question is marked "community wiki".

asked 06.07.2017 at 09:47

docvominh's gravatar image

docvominh
(suspended)
accept rate: 0%

edited 06.07.2017 at 09:53


hi @docvominh

I have nearly the same case and i can call ivy method by this function:

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;
    }

Here is calling:

evalELExpressionAsObject("#{logic.doSomething()}", FacesContext.getCurrentInstance());

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.

Because ivy have the mechanism to resolve keyword #data and #logic in correct context (see http://answers.axonivy.com/questions/2549/mechanism-to-resolve-data-and-logic-of-htmluserdialog)

So when you evaluate those twos manually, it will take the biggest context (the page).

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.

Cheers,

link

answered 06.07.2017 at 23:04

trungdv's gravatar image

trungdv
(suspended)
accept rate: 52%

edited 06.07.2017 at 23:06

hi @docvominh That's great when it works for your case.

What about exeption case? when something wrong happen in prepareFile, can we stop processing uploadDocument?

(07.07.2017 at 06:33) trungdv trungdv's gravatar image

hi @trungdv,

thank for your ideal, i will try it soon and reply to you.

(08.07.2017 at 09:28) docvominh docvominh's gravatar image

hi @trungdv, 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

FacesContext context = FacesContext.getCurrentInstance(); context.addMessage(null,new FacesMessage(FacesMessage.SEVERITY_ERROR, "MESSAGE CONTENT", "MESSAGE CONTENT"));

warning : There are some unhandled FacesMessages, this means not every FacesMessage had a chance to be rendered. These unhandled FacesMessages are: - MESSAGE CONTENT

I afraid that current context is belong to father dialog.

Thank you

(10.07.2017 at 03:19) docvominh docvominh's gravatar image

Hi @trungdv

Thanks for your comment.

I really like to do everything in ManagedBean. Fortunately, i found new way to achieve my goal.

use actionListener to call ManagedBean method, and action to call ivy method, when managedBean is done, ivy method start to call.

<p:commandButton actionListener="#{sPDocumentBean.prepareFile}" action="#{logic.uploadDocument}" value="Save"/>

Thank you :)

link

answered 07.07.2017 at 05:32

docvominh's gravatar image

docvominh
(suspended)
accept rate: 0%

edited 07.07.2017 at 05:34

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×79

Asked: 06.07.2017 at 09:47

Seen: 2,825 times

Last updated: 10.07.2017 at 03:19