Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Struts Wiki" for change 
notification.

The following page has been changed by MichaelJouravlev:
http://wiki.apache.org/struts/StrutsCatalogInputOutputSeparation

------------------------------------------------------------------------------
  What if we need to use one form? Say, we have a wizard or a dialog, which 
shares data. No problem, this even easier than to have two forms. Just define 
the form with session scope, and it will retain all input data between requests.
  
  attachment:actioncombo08.gif
+ ==== Follows the example from a working CRUD application. ====
+ {{{
+ <!--
+   Create Item. Creates new object with random ID, temporarily
+   saves it in the session, attaches item ID to redirected URL
+   and redirects to editing.
+   Input: none
+   validation: none
+ -->
+ <action path  = "/createItem"
+   type  = "com.superinterface.items.CreateItemAction"
+   validate = "false">
+   <forward name="itemCreated" path="/editItem.do" redirect="true"/>
+ </action>
+ 
+ <!--
+   Edit Item. Presents new or existing item for editing.
+   Item is looked up by ID. 
+   Input: item id
+   validation: item must exist in the item list
+ -->
+ <action path  = "/editItem"
+   type  = "org.apache.struts.actions.ForwardAction"
+   name  = "itemFormOutput"
+   input = "itemError"
+   parameter = "/WEB-INF/items/editItem.jsp">
+   <forward name="itemError" path="/WEB-INF/items/error.jsp"/>
+ </action>
+ 
+ <!--
+   Store Item. Persists item in the storage. If item has "New" status,
+   it is persisted, if item has "Stored" status, it is updated.
+   On success redirects to home page, on error returns to editing.
+   Input: item id, item value
+   validation: input form fields are validated
+ -->
+ <action path  = "/storeItem"
+   type  = "com.superinterface.items.StoreItemAction"
+   name  = "itemFormInput">
+   <forward name="itemStored" path="/itemList.do" redirect="true"/>
+   <forward name="storeError" path="/editItem.do" redirect="true"/>
+ </action>
+ }}}
+ 
+ Let's check out the output action first, editItem. Notice, that it does not 
care where it was called from and was it forwarded to or redirected to. All it 
knows, that it recieves object id in the ID property of its form bean. Well, I 
cheated a little, using the same form bean for input and for output in this 
case. 
+ 
+ If item is not found, action forward to error page. If a user reloads error 
page, editItem action would try to locate the item again, which does not change 
server state, but can improve situation if the item is found. On the other 
hand, it would be cleaner to use redirection to error page, so that database 
would not be bothered if error page is reloaded. If item is found, editItem 
shows it.
+ 
+ Updated item is submitted to storeItem action. It is an input action and uses 
form bean to collect browser data. If data is incorrect, errors are generated 
and saved in the session, then control is redirected back to output action, 
editItem, which redisplays the item along with the errors. If data is correct, 
item is stored in the database and control is redirected to the home page. Home 
page can be reloaded, this will not incur item resubmit.
+ 
+ createItem creates new item. This would be an input action, but it has no 
input parameters. It does not have output data either, since it redirects to 
editItem which is output action for createItem.
  
  See also: StrutsMultipleActionForms
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to