• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Prepopulating a form

 
Ranch Hand
Posts: 489
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Struts-config.xml
-----------------



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.

Thanks,
Ram.
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ramprasad

All Action tags should come inside a single action-mappings tag
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).

- Brent
 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 .

Thanks for your help.

ram.
 
Life just hasn't been the same since the volcano erupted and now the air is full of tiny ads.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic