I found the following advice in the struts archive regarding a "tag within
a tag" problem:
----------------------------------------------------------------------------------------------------
From: John Raley
Subject: Re: nesting bean:write inside of html:link
Date: Mon, 27 Aug 2001 13:22:41 -0700

As a workaround, I wrote an 'eval' tag that captures its content to a
bean.  You can bind the content to a scripting variable and use the
variable.  It's ugly but it works.

So, you'd do this:

<x:eval id='idValue'><bean:write name="somebean" property="id" /></x:eval>
<html:link href="somepage.jsp?action=someaction&id=<%= idValue %>" >link
text</html:link>

The actual implementation of eval is very simple - just a body tag that
captures its content to a String and puts the String into the page context.
----------------------------------------------------------------------------------------------------

John's example implies that the tag somehow puts the <x:eval> id attribute,
"idValue", into the pageContext such that it can be accessed from the
scriptlet <%=idValue%>.  In my implementation, the best I can do is set
"idValue" as the name in the pageContext.setAttribute() method.  Then the
jsp page has to get it like so:

<x:eval id="idValue"><bean:write name="somebean" property="id" /></x:eval>
<%String idValue= (String) pageContext.getAttribute( "idValue" );  %>
<html:link href="somepage.jsp?action=someaction&id=<%= idValue %>" >link
text</html:link>

Is John's example just pseudo code that leaves out the
pageContext.getAttribute step, or is there some way to set a variable in a
custom tag such that it can be directly accessed from a scriptlet?

Thanks,
Craig R.

Reply via email to