• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

html:select problem

 
chris gar
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.
 
unni krishna
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,

http://www.coderanch.com/t/45981/Struts/struts-html-options-tag-not
 
Junilu Lacar
Bartender
Pie
Posts: 8773
81
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I personally prefer htmlptionsCollection over htmlptions. The latter tag's attributes are, as you have seen, a bit confusing to use. The htmlptionsCollection 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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic