Ron,

We did something similar to the page that you have posted.  We only clone
the struts-config mappings.  So for example, we have a SelectionPage (top)
and a Detail Page.  Validations are different for the selection and detail
pages, but the action and form classes are the same.  Lastly, our editor
action classes all extend from a base editor class where we implement the
common things.

The important common function to this tast is the method for handling
validation failures.  The method (1) invokes a commonly named method that
is present in each editor action class to prepare for a return to the
detail page and (2) determines the correct forward based on the submitted
dispatch action.

All of our editor mappings take the following form:
(Note: we use multiple mappings for Selection vs Detail mappings so that we
can have simpler control in applying the validations - there might be a
better way.)
                                                                            
 For the accessing and submitting from the Selection Page                   
      <action                                                               
        path="/FooTop"                                                      
        type="com.myco.editors.FooAction"                                   
        name="FooTopForm"                                                   
        scope="request"                                                     
        input="/FooTop.do?dispatchAction=top"                               
        validate="true"                                                     
        parameter="dispatchAction">                                         
        <forward name="edit"   path=".editor.fooUpdate"/>                   
        <forward name="create"   path=".editor.fooCreate"/>                 
        <forward name="view"   path=".editor.fooView"/>                     
        <forward name="top"   path=".editor. fooTop"/>                      
      </action>                                                             
  For Detail Page Submissions:                                              
      <action                                                               
        path="/FooActionEdit"                                               
        type="com.myco.editors.FooAction"                                   
        name="FooDetailForm"                                                
        scope="request"                                                     
        input                                                               
 ="/FooValidationFailure.do?failureAction=handleValidationFailure"          
        validate="true"                                                     
        parameter="dispatchAction">                                         
        <forward name="edit"   path=".editor.fooUpdate"/>                   
        <forward name="create"   path=".editor.fooCreate"/>                 
        <forward name="view"   path=".editor.fooView"/>                     
        <forward name="top"   path=".editor. fooTop"/>                      
      </action>                                                             
  For Handling Validation Failures:                                         
      <action                                                               
        path="/FooValidationFailure"                                        
        type="com.myco.editors.FooAction"                                   
        name="FooDetailForm"                                                
        scope="request"                                                     
        validate="false"                                                    
        parameter="failureAction">                                          
        <forward name="edit"   path=".editor.fooUpdate"/>                   
        <forward name="create"   path=".editor.fooCreate"/>                 
        <forward name="view"   path=".editor.fooView"/>                     
        <forward name="top"   path=".editor. fooTop"/>                      
      </action>                                                             
                                                                            
                                                                            








|---------+---------------------------->
|         |           Ron Grabowski    |
|         |           <[EMAIL PROTECTED]|
|         |           oo.com>          |
|         |                            |
|         |           05/17/2004 02:00 |
|         |           PM               |
|         |           Please respond to|
|         |           "Struts Users    |
|         |           Mailing List"    |
|         |                            |
|---------+---------------------------->
  
>------------------------------------------------------------------------------------------------------------------------------|
  |                                                                                    
                                          |
  |       To:       struts <[EMAIL PROTECTED]>                                         
                                     |
  |       cc:                                                                          
                                          |
  |       Subject:  Re: Using DispatchActions with validation                          
                                          |
  
>------------------------------------------------------------------------------------------------------------------------------|




> From: "Nicholas L Mohler"
> <[EMAIL PROTECTED]>
> Date: Mon, 17 May 2004 09:27:11 -0400
>
> Hi Jacob,
>
> I asked almost the same question when we were
> implementing validation.  We
> had the same issue with preparing things before
> creating the user page.  We
> ended up creating an input that forwarded to a
> mapping that was basically a
> duplicate of the one with the validation failure.
> The only differences
> were (1) There was no validation in the second
> mapping and (2) the second
> mapping used a different parameter so that we could
> return to the exact
> page (edit/create) that created the validation
> failure.
>
> You are on the same path that we used.  It isn't as
> elegant as it could be,
> but it is less code than if we did it all "by hand".
>
> I don't know if I have the right class name, but I
> would think that you
> could extend the RequestProcessor and have it behave
> a little differently
> when the validation fails...
> Nick

Are you duplicating pages and/or entries in the
structs-config.xml?

I implemented this for my project:

 http://tinyurl.com/33cbw

Example:

<action
path="/FooCRUDOperation"
type="com.myco.editors.FooAction"
name="FooForm"
scope="request"
input="/FooCRUDInput.do"
parameter="dispatchAction">
<forward name="edit" path=".editor.foo.Update"/>
<forward name="edit"   path=".editor.fooCreate"/>
<forward name="view"   path=".editor.fooView"/>
<forward name="top"   path=".editor.fooTop"/>
</action>

The pages are pre-populated correctly and errors are
shown on the appropriate page (i.e. when you're on the
Edit page and an error occurs, the user is taken back
to the Edit page with their previously entered data
along with the error messages on top).

I extended LookUpDispatchAction to DoTheRightThing
when "dispatchAction" was missing from the request:

LIST MODE: /FooCRUDOperation
EDIT MODE: /FooCRUDOperation?id=4

Is there a better way to do things?

- Ron




__________________________________
Do you Yahoo!?
SBC Yahoo! - Internet access at a great low price.
http://promo.yahoo.com/sbc/

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






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

Reply via email to