Saturday, March 17, 2007

struts validation

using struts validation frame work as well as the validation method in validatorform
=====================================================================================
1) add the validation rules in the validation framework
2) for more validations override the validation method of the ValidatorForm as follows

public ActionErrors validate(ActionMapping map,HttpServletRequest req){

// get the validation errors from the frame work
ActionErrors objActionErros = super.validate(map,req);

// start custom validations
String strPageNumber = req.getParameter("page");
if(strPageNumber!=null && !strPageNumber.eqlus("2")){
if(objActionErros==null){
objActionErros = new ActionErrors();
}
objActionErros.add("errors",new ActionError("errors.wrongpage"));// this key will be in the message resource file
}

return objActionErros;
}

Comments: Post a Comment

Subscribe to Post Comments [Atom]





<< Home

This page is powered by Blogger. Isn't yours?

Subscribe to Comments [Atom]