3

I have a JSF+Spring Web Flow application and I'd like to move from one view to another one using a method defined in the view's bean.

So, my flow.xml is like the following:

<flow ...>
     <var name="myBean" class="mypackage.myclass" />
     <view-state id="list">
         <transition on="myEvent" to="#{myBean.onMyEvent()}"
     </view-state>
</flow>

In the bean I've defined:

public String onMyEvent(final SelectEvent event) {
    //Do something
    return "input";
}

The button is simply:

<h:commandButton id="myButton" action="myEvent" ajax="false" value="myButton" />

When I push on the button that contains the action="myEvent" I get the error:

EL1004E: Method call: Method onMyEvent() cannot be found on type [...]

So, what's wrong with my code? How can I call a method in my bean on some event?

Thanks.

Alessandro
  • 4,382
  • 8
  • 36
  • 70
  • Look at the method signature in the error and the one in your code. Notice a difference? – Kukeltje Jan 11 '19 at 18:26
  • @Kukeltje Yes but the action should be the one specified in the `flow.xml`. So I believe that's right, isn't? – Alessandro Jan 14 '19 at 08:15
  • 1
    No idea, I don't use complex setups like this. JSF has its own 'flows' which do not require relatively complex solutions like these. But your solution is exactly what I meant. – Kukeltje Jan 14 '19 at 09:21

1 Answers1

0

Finally, I solved using the org.springframework.webflow.engine.RequestControlContext that can handle event manually like in the following example:

Front-end side (call to the bean's method):

<h:ajax event="rowSelect" listener="#{myBean.onMyEvent}" />

Bean (forward to the Spring Web Flow handler):

public void onMyEvent(final SelectEvent event) {
    // Fill the bean for next view
    final RequestContext requestContext = RequestContextHolder.getRequestContext();
    requestContext.getFlowScope().put("nextBean", nextBean);
    final RequestControlContext rec = (RequestControlContext) requestContext;
    rec.handleEvent(new Event(this, "myEvent")); // the action managed by Spring Web Flow
}

And finally in the flow.xml (manage the transition to the next view)

<view-state id="myView">
    <transition on="myEvent" to="nextView" />
</view-state>
Alessandro
  • 4,382
  • 8
  • 36
  • 70