*
The moose likes Struts and the fly likes How to create an arraylist in action class and then capture in struts option? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to create an arraylist in action class and then capture in struts option?" Watch "How to create an arraylist in action class and then capture in struts option?" New topic
Author

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

Rocko Smith
Greenhorn

Joined: Jul 12, 2005
Posts: 10
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

Joined: Jan 10, 2002
Posts: 60782
    
  65

Moved to the Struts forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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 ]

Merrill
Consultant, Sima Solutions
Rocko Smith
Greenhorn

Joined: Jul 12, 2005
Posts: 10
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

Joined: Feb 15, 2005
Posts: 4864
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 ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to create an arraylist in action class and then capture in struts option?
 
Similar Threads
dynamic value to be submitted to form beans
Forms in servlet
raw HTML in Mozilla
Map dynamically generated HTML select(s) control in form bean
Form Params not passed properly