Write an on-entry action in the view and retrieve current state id by RequestContext.
<view-state id="currentView" view="currentView" model="modelObject">
<on-entry>
<evaluate expression="yourObject.methodName(flowRequestContext, flowScope.modelObject)"/>
</on-entry>
<transition on="previous" to="someStateOrView"/>
<transition on="next" to="someStateOrView"/>
</view-state>
public class YourObject{
...
public void methodName(RequestContext requestContext, ModelObject model){
model.setPreviousView(requestContext.getCurentState().getId());
....
}
}
Get the previousView value from your model and append it to your url as this will be set the moment flow enters into this view.