Meaningless Drivel is fun!*
The moose likes Struts and the fly likes scriplet in html:select tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "scriplet in html:select tag" Watch "scriplet in html:select tag" New topic
Author

scriplet in html:select tag

Pavan Kumar
Greenhorn

Joined: Jun 08, 2005
Posts: 23
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.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Use the <htmlptionsCollection> tag. See the taglib documentation for more details.


Merrill
Consultant, Sima Solutions
Pavan Kumar
Greenhorn

Joined: Jun 08, 2005
Posts: 23
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.
Vijay RamaRaju
Greenhorn

Joined: Feb 27, 2006
Posts: 7
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

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

    Joined: Jun 08, 2005
    Posts: 23
    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 agree. Here's the link: http://aspose.com/file-tools
     
    subject: scriplet in html:select tag
     
    Similar Threads
    Help me regarding select value in html:select...
    update html:options
    storing values chosen from dropdown
    HTML:SELECT
    whats problem with following code ** urgent