• 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

scriplet in html:select tag

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am trying to generate the <html ption> tags in my action class and store it in action form to display on the screen. I am using html:select tag and my code looks like this.

<bean efine id="form" name="SampleForm" type="struts.forms.SampleForm" />
<html:select property="Test" name="form" style="size: 150px;">
<%= form.getFieldValue()%>
</html:select>

My Struts form contains a variable named fieldValue and the getter and setter methods for it.

When I set the value to the form variable fieldValue in the struts Action class to something like <html ption value="Tester">TEST Data</html ption> , I am not able to see the value in the select dropdown in the screen. Can anyone please tell me how I can create a html options code in struts action, store it in the action form and then use it in the screen. I appreciate your help.

Thanks,
Pavan.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use the <html:optionsCollection> tag. See the taglib documentation for more details.
 
Pavan Kumar
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Merill,

I also tried to generated the <html ptionsCollection > tag in the struts action class and pass it to the screen using the request attribute or Form bean variable. The problem is that even though I get the result from the request attribute or form bean variable and try to print inbetween the <html:select> tags using <%= %>, it is not recognizing it. Any suggestions please...

Thanks,
Pavan.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pavan,


Create a Key,Value paired collection object, add it to the ActionForm.
Use the same collection object with <html ptionsCollection>
 
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
The html:optionsCollection tag, or for that matter, any Struts tag will work only if you place it directly in the JSP, not if you generate it through a scriptlet. To understand why it won't work to generate it in a scriptlet, let's review the JSP life cycle:
  • The JSP interpreter reads the JSP file, including any custom tags such as Struts tags and converts everything to Java source code
  • It then compiles it into a class file
  • It executes the code, rendering a response in plain HTML and sending it back to the browser.
  • It is only at this point that the scriptlet code you inserted gets executed. It is now too late in the cycle to insert any custom tags, since they've already been interpreted by this point.
  • Conclusion: if you want to generate HTML code in a scriptlet, it must be plain vanilla HTML, and not a custom tag such as a Struts tag.
    [ October 19, 2007: Message edited by: Merrill Higginson ]
     
    Pavan Kumar
    Greenhorn
    Posts: 23
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thank you Merill. It all makes sense now. I previously had a plain HTML tag for the Drop down and I was able to put the variables for the name and property and other attributes on the fly. Thank you for your post.
     
    I am not young enough to know everything. - Oscar Wilde This tiny ad thinks it knows more than Oscar:
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic