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

How to create an arraylist in action class and then capture in struts option?

 
Rocko Smith
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to create an arraylist in the action class containing 4 entries (<option> Entry 1 - 4 </option> that will later be viewed in the jsp using the option tag. I want to create it in the action class and hold the 4 entries in the form class. Then I want to extract the 4 entries from the form bean in the html.

Heres the existing html:
td class="label">Action Taken:</td>
<td class="data" colspan="5">
<select name="action" onchange="updateAction(); if(test_selectio(this, 'No Action')){ alert('Please provide any explaination in the Notes box.'); }">
<option> how do I get the arraylist from the bean? </option>
</select>
</td>
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64688
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to the Struts forum.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are two struts custom tags made specifically for building a list of options from a property in the ActionForm: <htmlptions> and <htmlptionsCollection>. Of the two, <htmlptionsCollection> is the most intuitive and easy to use. Note that you must also use <html:select> instead of <select> if you use one of the above tags.

here is the link that explains how to use them:

http://struts.apache.org/struts-doc-1.2.x/userGuide/struts-html.html#options

If after reading this you still have questions, let us know.
[ February 12, 2006: Message edited by: Merrill Higginson ]
 
Rocko Smith
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for reply. I have another question concerning the conversion of the existing html <select> tag to the struts <html:select> tag.

The current select tag uses the name="action" attribute, which is referenced in multiple places in page to determine the current value in the <option> current value </option>. Now that I am changing the <select> to struts the name attribute is used to identify the form name(name=FormName).
Do you know if there's an attribute in the <html:select> tag that maps from the html <select name="FormName">?

Thanks!
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you use your browser's "view source" function to view the generated HTML from a JSP that uses Struts tags, you will see that in any <html:xxx> tag, the property attribute maps to the name attribute of the actual raw html tag that is generated. So, the tag <html:select name="myForm" property="action"> will generate the html tag <select name="action">

One more thing: When you use a combination of <html:select> and <htmlptions or <htmlptionsCollection> Struts automatically selects the option that matches the value of the property you specify in your form bean. If you carefully read the link I gave you, it will become clear to you.
[ February 12, 2006: Message edited by: Merrill Higginson ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic