I am struts2 for developing my application.
Sample code of action class would be
class sampleAction extends Action {
private List<Employee> employee;
public validate(){
--logic for validation
}
public String prepopulate(){
--logic for populating value of employee list
}
--getters and setters
}
Now my problem is on page load i call prepopulate function and populate the value of employee list. After page submit validate method is called and during that if some error happens control redirects to jsp. but this time the value of employee list is empty. I am using this list for autocompleter tag in struts2.
I have never used Struts 2 built-in validation mechanism, as I prefer client-side validation to avoid an extra round trip. This is purely a personal choice and not a standard.
First I will suggest you not to use
Actionand useActionSupport:ActionSupportprovides a lot of functionality out of the box and you need not to do everything yourself.I am assuming that you are using
defaultStackand if this is the case than it provides out of the boxPrepare Interceptorwhich takes care of preparing any values before the action itself is called.In your case,
validateis called before theexecutemethod, so you never will get a chance to re-fill the values you need in your JSP.All you need to make sure that you have
prepare()method in your action class. Here are more details for this interceptor:Prepare Interceptor
FAQ: How do we repopulate controls when validation fails