You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jim Newsham <ne...@hotu.com> on 2000/12/01 02:21:50 UTC

using tags within tag parameter field ?

I apologize as this is a generic jsp question and not specific to struts, but
hopefully this is a simple one (at least, I give a struts example below).  Is
it possible to use a tag as an rtexprvalue within another tag's parameter
field?  For example (assuming 'mytag' can take a rtexprvalue for parameter
'param'):

<tag:mytag param="<tag:anothertag param=\"hello\"/>"/>


As a struts example, here are two versions to show a dynamic list of simple
menu items (there's a java.util.Collection attribute named "menu" attached to
the request; it's a collection of beans with properties 'href' and 'text'),
which differ only on the second line.  The first version is quite ugly but
works.  The second version is what I'd like to use, but this doesn't work --
causes a compile exception.  I'm assuming the answer to my question is "no",
but does this mean I'm stuck with version 1, or is there a better way?


ver 1:
<logic:iterate id="menuitem" collection="<%=request.getAttribute(\"menu\")%>">
  <form:link href="<%=((com.hotu.intra.MenuItem)
pageContext.getAttribute(\"menuitem\")).getHref()%>">
    <bean:write name="menuitem" property="text"/>
  </form:link>
  <br>
</logic:iterate>


ver 2:
<logic:iterate id="menuitem" collection="<%=request.getAttribute(\"menu\")%>">
  <form:link href="<bean:write name=\"menuitem\" property=\"href\"/>">
    <bean:write name="menuitem" property="text"/>
  </form:link>
  <br>
</logic:iterate>


compile exception:
/home/newsham/work/intranet/main.jsp:30: ')' expected.
          _jspTag3.setHref("<bean:write name="menuitem" property="href"/>");
                                              ^
1 error

com.caucho.java.JavaCompileException: /home/newsham/work/intranet/main.jsp:30:
')' expected.
          _jspTag3.setHref("<bean:write name="menuitem" property="href"/>");
                                              ^
1 error


Thanks,

Jim Newsham


Re: using tags within tag parameter field ?

Posted by Pierre Métras <ge...@sympatico.ca>.
Hi Jim,


>
> I apologize as this is a generic jsp question and not specific to struts,
but
> hopefully this is a simple one (at least, I give a struts example below).
Is
> it possible to use a tag as an rtexprvalue within another tag's parameter
> field?  For example (assuming 'mytag' can take a rtexprvalue for parameter
> 'param'):
>
> <tag:mytag param="<tag:anothertag param=\"hello\"/>"/>

No. You can't use tags into tag attributes.

But with a little effort, you can rewrite your tag to support a syntax like:
<tag:mytag>
    <tag:param>
        <tag:anothertag param="hello"/>
    </tag:param>
</tag:mytag>

Else, you're stuck with ver.1 for now.

Pierre Métras