Meaningless Drivel is fun!
The moose likes Struts and the fly likes html:select problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "html:select problem" Watch "html:select problem" New topic

html:select problem

chris gar
Ranch Hand

Joined: Jul 20, 2002
Posts: 45
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.

unni krishna
Ranch Hand

Joined: Jul 14, 2004
Posts: 39
This is an usual stuff that every one does in struts,

See this post in Javaranch,

Software Engineer (SCJP)<br />USTechnology, CA
Junilu Lacar

Joined: Feb 26, 2001
Posts: 6529

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 ]

Junilu - [How to Ask Questions] [How to Answer Questions]
chris gar
Ranch Hand

Joined: Jul 20, 2002
Posts: 45
Thanks! That did it!
I agree. Here's the link:
subject: html:select problem
It's not a secret anymore!