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
What is apache struts vulnerability?
Explain struts?
What do you mean by the abstract package in struts2, and what is its utilization?
How is the mvc design pattern used in struts framework?
What are the conditions for actionform to work correctly?
How does struts work?
State an example of struts configuration file as an action parameter for action servlet.
At the point, you should go for struts framework?
What is the purpose of action-mappings tag in struct-config.xml?
What are the struts2 configuration properties that control file uploading process?
What is the difference between struts and spring? Explain
How can we group related actions in one group in Struts?
Give an alternative way to protect jsp’s with not much features from direct access.
Explain about the process of functioning of the struts program?
Which technologies can be used at view layer in struts?