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
How exceptions are handled in struts application?
Explain the necessity of empty tag?
What design patterns are used in struts?
What are the major differences between html tags and strut specific html tags?
What is the apache struts vulnerability?
What is the difference between Jakarta Struts and Apache Struts? Which one is better to use?
What are the core classes of the struts framework?
What is controller in struts2?
What is the use of web xml in struts2?
In how many ways duplicate form submission can occurs?
What is the purpose of @createifnull annotation annotation?
What are the sections into which a strut configuration file can be divided?
What is action class? What are the types of action class?
What is struts-default package and what are it’s benefits?
What are the benefits of the struts system?