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.
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...
Create a Key,Value paired collection object, add it to the ActionForm. Use the same collection object with <html ptionsCollection>
Joined: Feb 15, 2005
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 ]
Joined: Jun 08, 2005
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.