
Originally Posted by
Rajendra
Not able to find the method context.getLastEvent().It gives me compile error saying not able to find method getLastEvent()
I am using SWF 2.0.5 v. Is it same as getCurrentEvent() in SWF v2.0.5?
Thanks
Same problem here... I'm using Spring Web Flow 2.3.0...
I my webflow-config.xml I have this:
HTML Code:
<webflow:flow-executor id="flowExecutor" flow-registry="flowRegistry">
<webflow:flow-execution-attributes>
<webflow:always-redirect-on-pause value="false" />
<!-- <webflow:redirect-in-same-state value="false"/> -->
</webflow:flow-execution-attributes>
<webflow:flow-execution-listeners>
<webflow:listener ref="jpaFlowExecutionListener" />
<webflow:listener ref="facesContextListener" />
<webflow:listener ref="myFlowListener" />
</webflow:flow-execution-listeners>
</webflow:flow-executor>
myFlowListener:
HTML Code:
package ch.itartis.relman.web.flow.listener;
import java.util.LinkedList;
import org.springframework.webflow.definition.StateDefinition;
import org.springframework.webflow.engine.ViewState;
import org.springframework.webflow.execution.FlowExecutionListenerAdapter;
import org.springframework.webflow.execution.FlowSession;
import org.springframework.webflow.execution.RequestContext;
public class myFlowListener extends FlowExecutionListenerAdapter {
private String viewStatesName = "GLOBAL_BACK_LISTENER_VIEW_STATES";
private String backEventId = "cancel";
public void setViewStatesName(String viewStatesName) {
this.viewStatesName = viewStatesName;
}
public void setBackEventId(String backEventId) {
this.backEventId = backEventId;
}
@Override
public void sessionStarted(final RequestContext context, final FlowSession session) {
session.getScope().put(viewStatesName, new LinkedList<String>());
}
@Override
public void stateEntered(final RequestContext context, final StateDefinition previousState,
final StateDefinition state) {
if (!(previousState instanceof ViewState))
return;
@SuppressWarnings("unchecked")
final LinkedList<String> viewStates = (LinkedList<String>) context.getFlowScope().get(viewStatesName);
if (viewStates == null)
throw new IllegalStateException("viewStates is null");
final String previousStateId;
if (context.getCurrentEvent().getId().equals(backEventId)) {
viewStates.removeLast();
previousStateId = viewStates.getLast();
} else {
previousStateId = previousState.getId();
viewStates.add(previousStateId);
}
context.getFlowScope().put("previousViewStateId", previousStateId);
}
}
And in my mainflow, I use this as a global transition:
HTML Code:
<transition on="cancel" to="${flowScope.previousViewStateId}"/>
The Exception I get:
HTML Code:
14:04:23.995 [http-9080-2] DEBUG o.s.webflow.engine.Transition - Executing [Transition@efff29 on = cancel, to = ${flowScope.previousViewStateId}]
14:04:23.995 [http-9080-2] DEBUG o.s.w.engine.impl.FlowExecutionImpl - Attempting to handle [org.springframework.webflow.execution.FlowExecutionException:
Exception thrown in state 'createContact' of flow 'main'] with root cause [java.lang.IllegalArgumentException: Cannot find state with id '${flowScope.previ
ousViewStateId}' in flow 'main' -- Known state ids are 'array<String>['home', 'error', 'createContact', 'editContact', 'readContact', 'listContacts', 'cont
actConfirmed', 'createAccount', 'editAccount', 'readAccount', 'listAccounts', 'accountConfirmed']']
14:04:24.002 [http-9080-2] DEBUG o.s.w.e.s.TransitionExecutingFlowExecutionExceptionHandler - Handling flow execution exception org.springframework.webflow
.execution.FlowExecutionException: Exception thrown in state 'createContact' of flow 'main'
What am I doing wrong? Please help me.