You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Mick Wever <mi...@machina.no> on 2003/10/23 15:27:31 UTC

validating form fields with rules from a different form

I got two fields in a form that are used injunction with a 'find' button
to fill out the rest of the fields in the form.
The rest of the fields in the form are required injunction with the
'submit' button, but the two fields are not.

These two fields are typical across a number of forms so they have their
own form (FindForm) and validation declaration.

Both the submit and find actions are performed inside the same action
class. 
My problem is, given I'm processing the 'find', how do I validate these
fields given they also exist in another form?

First off I thought about nesting a form inside a form, problem here is
that one action can't have two forms.

So in my action class I wrote a simple validate method that fetches the
validateActions from the other form:

<pre>
private void validateFinnMeNr(HttpServletRequest request, ActionErrors errors, Object meNr){
   ValidatorResources vr = Resources.getValidatorResources(request.getSession().getServletContext(),request);
   Form findForm = vr.get(getLocale(request), "FindForm");
   Field meNrField = (Field)findForm.getFieldMap().get("meNr");
*  ValidatorAction required = vr.getValidatorAction("required");
*  ValidatorAction integer = vr.getValidatorAction("integer");
*  FieldChecks.validateRequired(meNr, required, meNrField, errors, request); 
*  FieldChecks.validateInteger(meNr, integer, meNrField, errors, request);
}
</pre>

It feels like I doing this the long way round.
If it can't be done delcarative, then atleast I should be able to do the 
lines marked '*' quicker, something like:

<pre>
Field meNrField = (Field)findForm.getFieldMap().get("meNr");
meNrField.validateAllDependancies(meNr, errors, request);
</pre>

Is this possible?

Mick.


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org