I'm using a form bean, ABCFormBean of type ValidatorForm, in 5 jsp pages. In struts config, i've defined the action tag and its input attribute value = "URL of the first of the JSP pages". I use the validation framework for form validation and the validation errors get displayed in the page specified in the input attribute. So far so good...
But now i want the errors in the 3rd page to be displayed after validation in the 3rd page itself rather than the page specified in the input attribute. Can somebody help me at this seemingly tricky situation?
I don't thing what you are looking is possible with Form Validation. Form validation is carried out before the action is called. Struts uses the mapping element to find the page to be redirected if validation fails. One way I think of handling this - Define/write logic to validate only fields that are required for the current page in action form (it can be as well in action). Don't use the form validation. - From the action class call the right method for validating the current page form. If the method returns non-empty actionErrors/Messages then find out what page the user is currently in and forward the request to the same page.
Karthik Kumar Somasundaram
posted 14 years ago
This is not an uncommon issue.. There must be a work around provided in the validation framework. It has been long since we used the validate method of the action class for form validation. Its is not adviced by the architecture we follow in the company. They require the use of validation framework(validation.xml and validation-rules file).
If anybody proficient in the validation framework can help us out, it will be beneficial for many who come across this common problem.
posted 14 years ago
Karthik, It's been while from the last update, I am not sure if you were able to find a solution to this problem, I tried few things and found out that this isn't impossible to do. The problem is all the ActionConfig's are frozen and we won't be able to make changes to the action config - meaning it's not directly possible to change the "input" attribute of the action.
There is a work around (comes with maintenance issue) is to create your own extension to ActionServlet class and override init() method. In this method you copy the exact code as in base class except for commenting out the "freeze()" method calls. You need to configure your extension in web.xml