How to create validations?what are struts validation
components?

Answers were Sorted based on User's Feedback



How to create validations?what are struts validation components?..

Answer / 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

How to create validations?what are struts validation components?..

Answer / n.ramakrishna goud

We can create two types of validations
1).Manually
2).Automated
we can create manual validation by implementing the
validate method in ActionForm ,DynaActionForm,Validator
or DynaValidatorForm
Also ,
we can use the automated validation like
Integer,email,creditcard etc., by providing the validation
in the following xml files.,
validation.xml
validation_rules.xml

Is This Answer Correct ?    11 Yes 6 No

Post New Answer

More Struts Interview Questions

Explain the life cycle of a request in struct2 application?

0 Answers  


what is the main reason for developing struts? what is advantages over Basic MVC architecture based JAVA Application?

1 Answers  


Why do we use struts?

0 Answers  


project architechture in java

3 Answers   AC, IBM, INDUS, Satyam,


how to develop the submit and search operations in single jsp using struts?

0 Answers   Wipro,






What is token used for?

0 Answers  


Explain how can we upload files in struts2 application?

0 Answers  


Can you call Action class methods from Struts config.xml?

1 Answers   iGate,


What is struts?

0 Answers  


What is struts in j2ee?

0 Answers  


Can explain about the validations and in your project where did u used the validations?

4 Answers   NIIT,


Does Struts2 action and interceptors are thread safe?

0 Answers  


Categories