I would, except I don't know how to turn validation off in the Action Mapping in struts-config.xml. As long as I use the same ActionForm for both "show me a blank form so I can add" and "show me a populated form so I can edit", and that ActionForm implements validate(), then there's validation. Is there a way to turn this off?
The alternative, which may not be so bad, is for the validate() method to inspect the form fields and to decide to actually check for empty fields if we're in "show me a populated form so I can edit" mode. Actually, that's not bad at all because it fits with the overall semantics. In other words, I was originally thinking the validation rule is: "The Authentication Level's 'Name' field may not be empty." But upon further reflection, it's clear the validation rule is really: "The Authentication Level's 'Name' field may not be empty, UNLESS this is the special case of the 'Insert Row'." Where 'Insert Row' is defined to be a bean whose primary key (eg., authenticationLevelId) is null. Cheers, David -----Original Message----- From: Zeltser, Mark [mailto:[EMAIL PROTECTED]] Sent: Friday, April 05, 2002 12:45 PM To: 'Struts Users Mailing List' Subject: RE: Form Validation Question How about creating 2 mappings where second mapping will have validation turned off? Mark. -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Friday, April 05, 2002 3:36 PM To: [EMAIL PROTECTED] Subject: Form Validation Question 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) ---------------------------------------------------------------------------- -- This message is intended only for the personal and confidential use of the designated recipient(s) named above. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communication is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product, an official confirmation of any transaction, or as an official statement of Lehman Brothers. Email transmission cannot be guaranteed to be secure or error-free. Therefore, we do not represent that this information is complete or accurate and it should not be relied upon as such. All information is subject to change without notice. -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>