Spring Web Flow: Call bean's method as target action

Viewed 581

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.

1 Answers

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>
Related