aspose file tools*
The moose likes Struts and the fly likes html:select and pulling out value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "html:select and pulling out value" Watch "html:select and pulling out value" New topic
Author

html:select and pulling out value

A knibbs
Ranch Hand

Joined: Aug 23, 2006
Posts: 158
Unfortunately I still don't have a complete grasp on how struts interacts, and am having problems pulling out values from a select box. I have the following in the JSP:
<pre>
<select id="Order">
<logic:iterate name="User" property="orders" id="orders">
<option><bean:write name="orders" property="orderId" />
</option>
</logic:iterate>
</select>
<pre>

The problem is I am not sure how to determine which property was selected in the formbean. Any thoughts or suggestions anyone could offer would be fantastic.
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
My suggestion would be to use the html tags...they are a good friend to Struts developers. Without knowing what your form and objects looks like I can only guess at the property names, but the code might look like this:


"order" is a property on the form that stores the selected Order ID
"orders" refers to a "getOrders()" method on the form that returns a collection of Order objects
"orderId" refers to the getOrderId() property on the Order object...the same property is used for the value and the label

- Brent
[ November 07, 2006: Message edited by: Brent Sterling ]
A knibbs
Ranch Hand

Joined: Aug 23, 2006
Posts: 158
Thanks for the help Brent. I found out in the end from what I read using optionsCollection is only valid when you have a collection of beans, not a collection of Strings in which case just using options will work - thought I might put that in incase someone searches on this in the future.

Thanks again.
A knibbs
Ranch Hand

Joined: Aug 23, 2006
Posts: 158
Thanks for the help Brent. I found out in the end from what I read using optionsCollection is only valid when you have a collection of beans, not a collection of Strings in which case just using options will work - thought I might put that in incase someone searches on this in the future.

Thanks again.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: html:select and pulling out value