Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moved to the Struts forum.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: <html:options> and <html:optionsCollection>. Of the two, <html:optionsCollection> 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 <html:options or <html:optionsCollection> 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 ]
 
This tiny ad will self destruct in five seconds.
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic