JavaRanch Home
 
Front Page FAQs Ranchers Categories Recent Changes To Do Upload

Struts Tags In Scriptlets   



Question:

I am trying to generate the <html:option> 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:define id="form" name="SampleForm" type="struts.forms.SampleForm" />
<html:select property="Test" name="form" style="size: 150px;">
  <%= form.getFieldValue()%> 
</html:select>

When I set the value to the form variable fieldValue in the struts Action class to something like
<html:option value="Tester">TEST Data</html:option>
I am not able to see the value in the select dropdown in the screen.



Answer:

The html:option 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.



Return to StrutsFaq
Front Page FAQs Ranchers Categories Recent Changes To Do Upload
Last Edited: 19 February 2008 What's Changed?
 
Copyright © 1998-2008 Paul Wheaton | Home | Contact Us | Privacy | Register