The following problem has bothered me for days.
I have an action Registration.java which is used for users to create an account.
this action class has two methord: doList and execute.
doList gets data from the database and renders the initial jsp page with some s:select tags.
execute do the actual business logics.
I also have a validation config file: RegistrationAction-Registration-validation.xml
when i created some validation errors and the intial page was not displayed with the error: InitList.action is not available. It seems strut2s did not recognized the action InitList. When i change the result input like this:
In your case you just need to write <result name="input" >yourfile.jsp</result> .
Whiel rendering the input page (if validation fails) ,the Action Support class which your action class will extend checks for hasActionErrors() and displays the errors if any.
If you have any dropdown lists(s:select) in your page which needs to be prepopulated everytime the page is rendered ,write some prepare method in your action class to load the data from database.You don't need to call an action class in the result in this case.
Joined: Apr 01, 2010
Its not an error to call action again to load data from database,but you will lose your error messages
Joined: Jul 12, 2010
Sita Marivada wrote:
If you have any dropdown lists(s:select) in your page which needs to be prepopulated everytime the page is rendered ,write some prepare method in your action class to load the data from database.
<result name="input" >yourfile.jsp</result> is a better way to do it. Do you mean put the prepare methods in the execute of the action class?
in that case, will those methods be invoked again when i submit the form?
Joined: Apr 01, 2010
Instead of populating controls in an Action method, implement the Preparable interface, and use a prepare method instead. The prepare method is called before validation, so if validation fails, we still have a chance to populate controls (or whatever).
By default ActionSupport implements Preparable interface,so just need to override prepare method and add code to load data.
put the initialize methods in the Preparable interface.
but this still cannot prevent invoking those initialize methods when validation is passed and action executes successfully because prepare interceptor cannot be bypassed. but your approach is still good because it avoid action redirect which caused everything in request lost!!!
by the way, to pass error messages between actions, <interceptor-ref name="store"> can be used.