You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Carl Schwarcz <ca...@schwarczclark.com> on 2003/01/01 22:53:44 UTC

interaction between jstl and struts

I'm trying to conver some existing jsp's to Struts but confused about
the interaction between JTSL looping constructs and Struts tags. I''ve
got a session attribute containing a list of subjects which get output
as the options in a select.  The Struts version complains that that the
attribute subj has no value, while everything works fine in the
original.  Anybody have any advice?

Here's my original jsp-based form:

<form method="post" action="/grumpy/Controller"  >
  <select name="topic">
    <c:forEach items="${subjects}" var="subj">
        <p><option value= "<c:out value="${subj}"/>"> <c:out
value="${subj}"/> </option></p>
  </select>
<input type="submit" value="Choice" name="action" />
</form>

Here's my attempt at a struts version"

<html:form action="/choice" name="choiceForm"
type="carl.struts.ChoiceForm" > 
  <html:select property="topic">
    <c:forEach items="${subjects}" var="subj">
      <p><html:option value= "<c:out value="${subj}"/>"> <c:out
value="${subj}"/></html:option></p>
    </c:forEach>
  </html:select>
  <html:submit>Choose Subject</html:submit>
</html:form>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: interaction between jstl and struts

Posted by "David M. Karr" <dm...@earthlink.net>.
>>>>> "Carl" == Carl Schwarcz <ca...@schwarczclark.com> writes:

    Carl> I'm trying to conver some existing jsp's to Struts but confused about
    Carl> the interaction between JTSL looping constructs and Struts tags. I''ve
    Carl> got a session attribute containing a list of subjects which get output
    Carl> as the options in a select.  The Struts version complains that that the
    Carl> attribute subj has no value, while everything works fine in the
    Carl> original.  Anybody have any advice?

    Carl> Here's my original jsp-based form:

    Carl> <form method="post" action="/grumpy/Controller"  >
    Carl>   <select name="topic">
    Carl>     <c:forEach items="${subjects}" var="subj">
    Carl>         <p><option value= "<c:out value="${subj}"/>"> <c:out
    Carl> value="${subj}"/> </option></p>
    Carl>   </select>
    Carl> <input type="submit" value="Choice" name="action" />
    Carl> </form>

    Carl> Here's my attempt at a struts version"

    Carl> <html:form action="/choice" name="choiceForm"
    Carl> type="carl.struts.ChoiceForm" > 
    Carl>   <html:select property="topic">
    Carl>     <c:forEach items="${subjects}" var="subj">
    Carl>       <p><html:option value= "<c:out value="${subj}"/>"> <c:out
    Carl> value="${subj}"/></html:option></p>
    Carl>     </c:forEach>
    Carl>   </html:select>
    Carl>   <html:submit>Choose Subject</html:submit>
    Carl> </html:form>

You can't nest custom tags in the attribute values of custom tags.

If you instead used the Struts-EL library (check "contrib/struts-el" in Struts
distribution), your excerpt would look like this:

 <html-el:form action="/choice" name="choiceForm"
               type="carl.struts.ChoiceForm" > 
   <html-el:select property="topic">
     <c:forEach items="${subjects}" var="subj">
       <html-el:option value="${subj}"/>
     </c:forEach>
   </html-el:select>
   <html-el:submit>Choose Subject</html-el:submit>
 </html-el:form>

This might be better if you could use the "options" or "optionsCollection"
tags, instead of iterating through a collection and explicitly creating
"option" tags.  However, this may have a wrinkle, as I believe those two assume
the collection is a collection of beans, not strings, as I think you have here.

-- 
===================================================================
David M. Karr          ; Java/J2EE/XML/Unix/C++
dmkarr@earthlink.net   ; SCJP



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>