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

What is struts framework in java?

528


Where can I get help with struts?

559


What kind of mvc is struts 2?

553


In struts.xml, what does the attribute "method" stands for in the "action" tag?

521


Is struts compatible with other java technologies?

526






How do struts work?

518


What is the purpose of plug-in tag in struct-config.xml?

484


What is struts 2 framework in java?

537


Whats the difference between the default namespace and the root namespace?

515


Explain about the process of functioning of the struts program?

585


In which method of action class the business logic is executed?

542


What are the pros of struts 2?

555


Can you explain struts.properties in struts2?

526


Explain about struts dispatch action?

544


What is the use of Struts.xml configuration file?

507