This week's book giveaway is in the Server-Side JavaScript and NodeJS forum.
We're giving away four copies of Modern JavaScript for the Impatient and have Cay Horstmann on-line!
See this thread for details.
Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

html:select problem

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have done many searches but I don't understand.

I have an ArrayList "probationOfficers" defined in "MyActionForm".

Currently, my code displays and retrieves the name of the probation officer.

Here is the code:



If I load data from an action I have to send (to the jsp) the name - like "Johnson" in order to display the right selection. Likewise, I receive "Johnson" in the action upon a submit etc.

I need to be able to send (for instance) id = 4 to the jsp and have that code display the appropriate name (Johnson)- and I need a 4 also on submit.

I have read many posts and i'm not getting it - I'm sure which is which - collection - property -labelProperty - name. Can someone please provide some assistance.

Regards.
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is an usual stuff that every one does in struts,

See this post in Javaranch,

https://coderanch.com/t/45981/Struts/struts-html-options-tag-not
 
Marshal
Posts: 15873
265
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I personally prefer html:optionsCollection over html:options. The latter tag's attributes are, as you have seen, a bit confusing to use. The html:optionsCollection attributes, on the other hand, are more straightforward and intuitive.



You can read the JSP like so:

create a drop down; the value selected for this dropdown should go into the "probationOfficer" property of the form.

The options for the dropdown are in the Collection returned by the "officers" property of the form. The label to show for the options should be the "name" of each officer in the collection. The value to use to set the enclosing "select" tag when a selection is made is the "id" of the officer selected.
[ January 04, 2005: Message edited by: Junilu Lacar ]
 
chris gar
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks! That did it!
 
Why am I so drawn to cherry pie? I can't seem to stop. Save me tiny ad!
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic