Hello,

 

I'm using a single Action Mapping for both "adding" and "editing" an entity.
The mapping looks like this:

 

    <action path="/editAuthorityLevel"

            type="com.wellsfargo.pcsweb.controller.EditAuthorityLevelAction"

            name="authorityLevelForm"

            input="/editAuthorityLevel.jsp"

            scope="request">

      <forward name="success" path="/editAuthorityLevel.jsp"/>

    </action>

 

The idea is, if we come into ../editAuthorityLevel from a link that says
"Add Authority Level", then there'll be no form parameters, the
authorityLevelId consequently will be null, and the EditAuthorityLevelAction
class can do nothing in this case.  If, on the other hand, we come into
../editAuthorityLevel from a form that says "Edit Authority Level", then the
form fields (especially "authorityLevelId") will not be null.  In this case,
if looks up the appropriate bean and populates the form with the
corresponding values.  

 

This works great until I introduce form validation.  If I implement the
form's validate() method so that it returns a non-empty ActionErrors if
required fields are not filled in, then this happens when coming in from the
"Add Authority Level" link.  When this happens, Struts skips the
EditAuthorityLevelAction class and tries to go directly to
../editAuthorityLevel.jsp.  This is bad because EditAuthorityLevelAction
populates several page beans that the JSP needs.

 

The central problem is this:  I'm using the ActionForm to shuttle data from
the Model side to the View side.  In one case, it's used to swizzle data out
of the model and show it in the JSP's "edit" form.  In the other case, it's
used to collect data from the form and send it (through the Action) back to
the model.  Only in the latter case do I care about form validation.  Yet
Struts imposes validation in both directions.  How do I get around this?

 

Cheers,

David A. Ventimiglia

Wells Fargo Private Client Services

(415) 396-0414 (work)

 

Reply via email to