• 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

Can struts repopulate collection from html:select upon submit?

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Experts -

I'm new to the html:select control, and am not sure if it even supports what I want to do.

My html:select displays a drop down menu with all my choices in it on the browser. When I hit submit, I want it to repopulate the form bean with all those same choices, in addition to populating one field with the choice selected. Will struts repopulate all the choices too?

If so, can you give some pointers? Here's a snippet of code. I want it to repopulate the regions collection upon submission.

<html:select name='SearchForm' property="selectedId" size="1">
<html ption value="-1">-- Select Region --</html ption>
<html ptionsCollection property='regions' value="internalId" label="name"/>
</html:select>

thanks in advance.
Steve
 
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Steve,
Welcome to JavaRanch!

If the list of regions is still in the session, Struts will use it. This isn't part of the form, so it is somewhat independent of Struts. Populating the actual selected element is the job of the action form.
 
Steve Line
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Very interesting and Thanks for your help! Is this something struts does automatically or something i rig by saving the list in the session, then retrieving it from the session after the form has been submitted?

More details-
I have action class A generate the list, stick it in the form bean, and the jsp displays it. When the html:form in the jsp is submitted it goes to another action class, class B. Then action class B forwards back to the jsp. I want the jsp to show the same list the second time around as it did the first time.
 
Jeanne Boyarsky
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Steve Line:
something i rig by saving the list in the session, then retrieving it from the session after the form has been submitted?


More like this one. When you put something in the session, it stays there until you explicitly delete it (or the session times out.) This is something the web container does for you and independent of Struts. The Struts JSP option tag is told to look in the session for a list of options in a specified bean.

In your example, you want A to put the list in the session (form bean.) While you happen to be storing the list in the form bean, it really could be stored anywhere in the session. The form bean is a logical place, so this is good. Obviously, the JSP sees it on the first shot. When you submit again, form.reset() is called. As long as this doesn't blank out the list, it will still be there when the JSP next looks for it.

So the two keys here are:
1) Keep form in session scope
2) Don't blank out list of regions
 
Steve Line
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Excellent - I'll try this!
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just wondering I was trying to do the same thing, but my Collection is a list of strings. How would I handle it so that the list is repopulated and it has the previoudly select value displayed. oh, and ther is no form associated with the list there is an action called to prepopulate the jsp page. This action places the list returned on the request.
[ July 13, 2005: Message edited by: Lisa Carter ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic