Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

html:select and pulling out value

 
A knibbs
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic