Erik Weber wrote:

if you have a single JSP that houses a form that is used for different commands (add, update), you are still going to need two separate form elements in validation.xml, causing redundancy (until "field inheritance" is implemented at least), correct?

That is correct, although if you are using the "trick" way I mentioned you could "sort" of get around this by setting up a "baseEmployeeValidation" in your valiation.xml that you know will be common amongst all the particular forms in question. Then you can create a couple sub ones for the specifics (ie = "updateEmployeeValidation", "insertEmployeeValiation"). Then, since you are calling the validation manually you simply call the baseEmployeeValidation and then the appropriate custom valiation in your action. I haven't tried this, but it should work.


Although I just took a brief look at the API and I'm not sure if you call validate() more than once if you end up with a new Instance of the ValidationResults being set to the ValidationForm's instance of "validatorResults." If it reuses the same instance and just adds on to the map then that would be cool. If not, then the best you could do with this trick would be to call the base common validation and if no errors return then proceed on to validate the next custom validation. The drawback to this is say the user completes a large form and submits. It's possible he'll get a validation error saying "something is wrong" and then he could submit after fixing it and get a new error (based on the custom portion). Sort of annoying because it should come back all at once. Anyway an attempt at this might look like: (not tested at all)...

validate(..) {
ServletContext application = getServlet().getServletContext();
ActionErrors errors = new ActionErrors();
String parameter = request.getParameter( mapping.getParameter() );

//set up Validator and test the base stuff common to both the add
//update. Remember, we know the name of the base Validation..

Validator validator = Resources.initValidator( "baseEmployeeValiation", this, application, request, errors, page);
try {
validatorResults = validator.validate();
} catch (ValidatorException e) {
log.error(e.getMessage(), e);
}


//you might in the above also be able to test this custom
//stuff, just haven't looked at how validator.validate() deals
//with validatorResults if validate is called more than once

//parameter would be your dispatch parameter represening the
//"custom" unique part that needs validation..ie "addEmployee"
//or "updateEmployee"

if ( validatorResults.isEmpty() ) { //no errors from the base test
 validator = Resources.initValidator( parameter, this, application,
 request, errors, page);
 try {
  validatorResults = validator.validate();
 } catch (ValidatorException e) {
  log.error(e.getMessage(), e);
 }
}

 return errors;
}


Probably easier just to delcare the two different validations in the xml and copy and paste the common validations into both:) Extends sure would be nice.


--
Rick

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



Reply via email to