Its very recently that I have begun playing around with struts and I have been trying to get my head around this for sometime now and I am almost begining to think that its not possible.
What I want to do is pre-populate a Struts form and then call a jsp which uses the struts-el tags to display the form.
I have a form with 2 fields - a select field and a radio button field. The select field has a list of 'network' options the user can select from and the radio button field has 2 views that the user can again choose from.
I have 2 urls (/selectNetwork and /submitNetwork) - one which displays the form and the other which the form is submitted to. This is what I have come up with.
In the form view url's (/networkSelect) Action class, I manually create a NetworkForm object, populate the attributes and set it in request scope with the same name (networkForm) as defined in the form bean definitions in the xml above. The jsp picks up the form and displays the values correctly.
However in the submit url (/submitNetwork) Action class, the ActionForm passed into the execute method is null. I would expect that the framework would reuse the NetworkForm object (or create a new one) and populate the fields from the request. Is this because I manually created the form object in the previous request and botched up the framework processing (though I cant fugure out why it should be so)?
Alternatively could I have included the form in the 'view' url too and set the scope to session? I dislike having to do so since this really is not a session object and is necessary only for 2 requests. Also if I do that, I am at a loss how to include validation in here. The problem is I dont want the validate method to kick in for the view (which is another reason why I dint map the form object to the view url).
I appreciate your patience in reading this post and would be grateful for any suggestions/comments.
I am not sure if the duplicate action-mappings tags are causing the problem. It seem like if you are able to call your action and NetworkSubmitHandler is being called then that might not be the issue. I am not sure what else would cause this. You have a name set for the action submitNetwork action, so Struts should create a new instance of your form and try to populate it with values from the request.
About validation: By default validation is turned on for all actions, but if you set validate to false for the action networkSelect, then your form values will only be validated on the submitNetwork action. Your input property may need to point back to another action if you need to do some setup before the jsp is shown (like populating lists).
Thanks VidyaSagar and Brent. Yes, the problem wasnt with the multiple action-mappings. In my earlier post, I had written that I manually created a Form object for prepopulation. I had made the default no args constructor required by the framework unavailable by defining my custom one - yes stupid me - I know .