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:
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"> <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>
Thoughts?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>
Thanks,
Dan


Reply With Quote
