Announcement Announcement Module
Collapse
No announcement yet.
Back button not working as expected when not using subflows Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Back button not working as expected when not using subflows

    Hello,

    i recently started using Spring Webflow and encountered a problem:

    My first view-state displays a list represented by a model (implementing Serializable) holding a List<String> and a button. Upon pressing the button, a new view containing an input field and a "Submit"-button is entered. The flow basically loops between those views so the user can add new elements into the list until he/she gets bored.

    If i am using no subflow i can use the Back button after adding a new element to the list, press "Submit" again and end up with a duplicate in my list.

    If am using a subflow, i am not getting any duplicates.

    My model (DataModel.java):
    Code:
    public class DataModel implements Serializable {
    	// variables
    	private List<String> list = new ArrayList<String>();
    	
    	// constructors
    	public DataModel() {}
    	
    	// methods
    	public void addToList(String tItem) { 
    		if(tItem == null || tItem.isEmpty()) { return; }
    		this.list.add(tItem); 
    	}
    	
    	public List<String> getList() { return this.list; }
    }
    my first view (listShow.xhtml):
    Code:
    <h:form>
    	<t:dataTable value="#{dataModel.list}" var="item" styleClass="dataTable">
    		<h:column>
    			<h:outputText value="#{item}"/>
    		</h:column>
    	</t:dataTable>
    	<t:commandButton action="newEntry" value="Add new entry"/>
    </h:form>
    my second view (listNew.xhtml):
    Code:
    <h:form>
    	<h:outputText value="New entry: "/><h:inputText value="#{flowScope.item}"/>
    	<div style="margin-top:10px; ">
    		<t:commandButton action="submit" value="Submit"/>
    		<t:commandButton action="cancel" value="Cancel"/>
    	</div>
    </h:form>


    now here's the flow that's not working as expected:
    Code:
    <var name="dataModel" class="path.to.DataModel"/>
    
    <view-state id="list-show" view="listShow.xhtml">
    	<transition on="newEntry" to="list-new"/>
    </view-state>
    
    <view-state id="list-new" view="listNew.xhtml">
    	<transition on="submit" to="list-show">
    		<evaluate expression="dataModel.addToList(flowScope.item)"/>
    	</transition>
    	<transition on="cancel" to="list-show"/>
    </view-state>
    and the solution using subflows that works just fine:
    Code:
    <var name="dataModel" class="path.to.DataModel"/>
    
    <view-state id="list-show" view="listShow.xhtml">
    	<transition on="newEntry" to="list-new"/>
    </view-state>
        
    <subflow-state id="list-new" subflow="temp2-flow">
    	<transition on="submit" to="list-show">
    		<evaluate expression="dataModel.addToList(currentEvent.attributes.newItem)"/>
    	</transition>
    	<transition on="cancel" to="list-show"/>
    </subflow-state>
    
    ==============================================
    
    <view-state id="list-new" view="listNew.xhtml">
    	<transition on="submit" to="submit"/>
    	<transition on="cancel" to="cancel"/>
    </view-state>
    	
    <end-state id="submit">
    	<output name="newItem" value="flowScope.item"/>
    </end-state>
    	
    <end-state id="cancel"/>
    I was under the impression that both solutions would work the way i except them to do (no duplicates). Is it intended that that's not the case or am i doing something wrong?
Working...
X