How to create validations?what are struts validation
components?

Answer Posted / tarun

The validation in struts is done by 2 ways. one is
programmatic validation and Declarative validation. I
programmatic validation we override the
validate(ActionMapping am, HttpServletRequest req) method
provided by ActionClass. This method returns the ActionErros.
For Example :

public ActionErrors validate(ActionMapping am,
HttpServletRequest req){
ActionErrors ae = new ActionErrors();
if(username==null ||
username.equals("")){ae.add("unameError", new
ActionMessage("uname.empty"));}

if(password==null || password.equals("")){
ae.add("passError", new ActionMessage("pass.empty"));
}else if(password.length()<5){
ae.add("passError", new ActionMessage("pass.minlength"));
}
return ae;
}
The values of pass.minlength , pass.empty, uname.empty will
be described in the properities file.

And in the case of declarative validation we extend the form
bean class from anyone of these classes DynaValidatorForm,
DynaValidatorActionForm

the first two classes are defined in
org.apache.struts.validator.*;
In this case we need validator.xml and validator-rules.xml
and properties file.

Is This Answer Correct ?    17 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Does apache tomcat use struts?

505


How is the action mapping specified?

547


Give the details of xml files used in validator framework?

585


What does it cost to replace struts?

498


How do struts work?

519






Can we handle exceptions in Struts programmatically?

516


What is structs 2 validation framework?

563


What is xml based validation in struts2?

556


What is difference between struts1 and struts2?

498


What is the difference in using Action interface and ActionSupport class for our action classes, which one you would prefer?

564


What is the use of execAndWait interceptor?

555


What does modeldriven interceptor?

586


What are action classes in struts?

517


Which configuration files are used in struts?

519


Why struts 1 classes are not thread safe whereas struts 2 classes are thread safe?

501