This problem has appeared in several previous posts where the solution was to overwrite the validate method in the ActionForm class. I would rather not go with this option as I would prefer to use DynaValidatorForm with a validator plug-in. So I was wondering is there a solution to the following problem which would allow me to continue using a validator plug-in...
I have a register.jsp page in my application which allows users to register as members of my website. The register.jsp page has several html select lists (for example the user can select his/her country of residence).
Now the problem, the register.jsp uses a DynaValidatorForm so if the user forgets to enter one of the required fields (eg. password) a reminder text is displayed beside the empty field. When this happens however, my select lists dissappear. The box is still there but it no longer contains the list of countries.
Here is what I think is going on. In the execute method of my Action class 'RegisterAction.java' the countries options are populated with a list retrieved from the ServletContext (a StartupManager.java plug-in had placed the list in the ServletContext when the application began)
It appears however that when the validator plug-in sees that the password field is empty it displays register.jsp with the reminder text but completely bypasses my execute method thus register.jsp is displayed but the select lists haven't been populated. Does this sound right? I believe this to be the case because when I set a breakpoint within my execute method the programs just runs to completion.
My question is how do I make my application validate the form then run execute method of my Action Class and then finally display the jsp page. And not bypass the execute method of Action class as it appears to be doing now.
Thanks for your help
Joined: Nov 28, 2006
Found out how to do this from another site...
I had a preprocess action which populated the collection and that was all it did. In the struts-config, I set the preprocessAction.do as the input page. That way if the validation failed, struts will execute the preprocessAction which will repopulate the list and redisplay the form in tact.