Results 1 to 5 of 5

Thread: Need Confirmation of Understanding

  1. #1
    Join Date
    Sep 2005
    Location
    West Bloomfield, MI
    Posts
    32

    Default Need Confirmation of Understanding

    I'm either really proud of myself for figuring out what's obvious to everyone else, or I've botched this big time and don't know it. Could someone who knows better than I do confirm one way or the other? :-)

    Goals:
    1) Simple query->results->select->add/edit->modify->query loop;
    2) Use database-querying service at all levels;
    3) Leverage webflow entirely -- no coding where not needed

    I've broken this into two flows: search-players-flow and edit-player-flow. I had to write a single FormAction class in order to override createFormObject and pull the data from a database -- but I felt like there was probably a way to do this from the XML using my business service; I couldn't figure out how to attach the result of that service call (a Player object) to the form itself without the override.

    Here's my the search-players-flow:
    Code:
    <flow xmlns="http://www.springframework.org/schema/webflow"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://www.springframework.org/schema/webflow
                              http://www.springframework.org/schema/webflow/spring-webflow-1.0.xsd">
    
        <start-state idref="findPlayers"/>
    
        <view-state id="findPlayers" view="players/findPlayersForm">
            <render-actions>
                <action bean="formAction" method="setupForm"/>
            </render-actions>
            <transition on="search" to="displayPlayersList">
                <action bean="formAction" method="bindAndValidate"/>
            </transition>
        </view-state>
    
        <view-state id="displayPlayersList" view="players/findPlayersResults">
            <render-actions>
                <bean-action bean="playerService" method="findPlayersByExample">
                    <method-arguments>
                        <argument expression="${flowScope.form.player}"/>            
                    </method-arguments>
                    <method-result name="players"/>
                </bean-action>
            </render-actions>
            <transition on="select" to="editPlayer"/>
        </view-state>
    
        <subflow-state id="editPlayer" flow="edit-player-flow">
            <attribute-mapper>
                <input-mapper>
                    <mapping source="${requestParameters.id}" target="playerId" from="string" to="int"/>
                </input-mapper>
            </attribute-mapper>
            <transition on="finish" to="findPlayers"/>
        </subflow-state>
    
        <import resource="search-players-beans.xml"/>
    </flow>
    Here's the edit-player-flow (Note: the use of the decision state here justified in that detection of add/edit is not a business decision):
    Code:
    <flow xmlns="http://www.springframework.org/schema/webflow"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://www.springframework.org/schema/webflow
                              http://www.springframework.org/schema/webflow/spring-webflow-1.0.xsd">
    
        <input-mapper>
            <input-attribute name="playerId"/>
        </input-mapper>
    
        <start-state idref="branchToAddOrEdit"/>
    
        <decision-state id="branchToAddOrEdit">
            <if test="${flowScope.playerId == 0}" then="displayAddPlayerDetails" else="displayEditPlayerDetails"/>
        </decision-state>
    
        <view-state id="displayEditPlayerDetails" view="players/modifyPlayerForm">
            <render-actions>
                <bean-action bean="playerService" method="findPlayerById">
                    <method-arguments>
                        <argument expression="${flowScope.playerId}"/>            
                    </method-arguments>
                    <method-result name="player"/>
                </bean-action>
                <action bean="playerFormAction" method="setupForm"/>
            </render-actions>
            <transition on="modify" to="finish">
                <action bean="playerFormAction" method="bindAndValidate"/>
                <bean-action bean="playerService" method="createOrUpdatePlayer">
                    <method-arguments>
                        <argument expression="${flowScope.form.player}"/>            
                    </method-arguments>
                    <method-result name="player"/>
                </bean-action>
            </transition>
        </view-state>
    
        <view-state id="displayAddPlayerDetails" view="players/modifyPlayerForm">
            <render-actions>
                <action bean="playerFormAction" method="setupForm"/>
            </render-actions>
            <transition on="modify" to="finish">
                <action bean="playerFormAction" method="bindAndValidate"/>
                <bean-action bean="playerService" method="createOrUpdatePlayer">
                    <method-arguments>
                        <argument expression="${flowScope.form.player}"/>            
                    </method-arguments>
                    <method-result name="player"/>
                </bean-action>
            </transition>
        </view-state>
        
        <end-state id="finish"/>
        
        <import resource="edit-player-beans.xml"/>
    </flow>
    Thoughts?

    Thanks,
    Dan

  2. #2
    Join Date
    Sep 2004
    Location
    Leuven, Belgium
    Posts
    1,853

    Default

    Looks good.

    I had to write a single FormAction class in order to override createFormObject and pull the data from a database -- but I felt like there was probably a way to do this from the XML using my business service; I couldn't figure out how to attach the result of that service call (a Player object) to the form itself without the override.
    A custom FormAction to load your form object is typical SWF usage.

    Erwin

  3. #3
    Join Date
    Sep 2005
    Location
    West Bloomfield, MI
    Posts
    32

    Default

    Quote Originally Posted by klr8 View Post
    A custom FormAction to load your form object is typical SWF usage.
    Thanks, Erwin. It feels like there ought to be away to bind an object in some scope to your form object without writing code for the simplest of cases. For example, my form object has a setPlayer(Player) method, and I have a Player object in my scope. If I could call the setter with this object, my form would be pre-loaded, end of story.

    Dan

  4. #4
    Join Date
    Sep 2004
    Location
    Leuven, Belgium
    Posts
    1,853

    Default

    You should be able to call the setter with OGNL. Check the OGNL docs for more info:
    http://www.ognl.org

    Erwin

  5. #5
    Join Date
    Feb 2007
    Posts
    20

    Default

    I am in a similar situation. I have an edit form with the object already in scope (form populated). But when I do the binding a new instance of this object is created, without updating the original object.

    I'm new with SWF and now becomes critical in my project.

    Thanks.
    Code:
    <input-mapper>
    		<input-attribute name="id"/>
    	</input-mapper>
    	
    	<start-state idref="editFacultate" />
    
    	<view-state id="editFacultate" view="facultateEdit">
    		<render-actions>
    		
    			<bean-action bean="webFlowFacade" method="getFaculty">
    				<method-arguments>
    					<argument expression="flowScope.id" />
    				</method-arguments>
    				<method-result name="facultate" />
    			</bean-action>
    		</render-actions>
    		<transition on="backToFacultatiList" to="backToFacultatiList" />
    		<transition on="commit" to="commitFacultate">
    			<action bean="facultateAction" method="bind"/>
    		</transition>
    	</view-state>
    	
    	<action-state id="commitFacultate">
    		<action bean="facultateAction" method="commitFacultate"/>
    		<transition on="success" to="backToFacultatiList"/>
    		<transition on="error" to="editFacultate"/>
    	</action-state>
    And this is the action class.

    Code:
    	private DAOFactory daoFactory;
    	/**
    	 * 	The object that makes scope of this action
    	 */
    	private Facultate facultate;
    	
    	
    	public Event commitFacultate(RequestContext context) {
    		//facultate = daoFactory.getFacultateDao ().getById ((Long)context.getFlowScope ().get ( "id" ));
    		facultate = (Facultate) context.getFlowScope ().get ( "facultate" );
    		FacultateDaoInterface daoImpl = 
    			daoFactory.getFacultateDao ();
    		daoImpl.update ( facultate );
            return success();
        }
    Last edited by iga3k; Feb 22nd, 2007 at 04:24 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •