On Fri, 8 Jun 2001, Erich Meier wrote:
> Hi!
>
> I am evaluating struts for a new project. One problem I wasn't able to solve
> was the integration of JSP expressions inside the attributes of
> custom tags.
>
> My code looks like this:
>
> <logic:iterate id="pelement" name="MyBean" property="pelements">
> <% String name = ((PElement)pelement).getName(); %>
> <html:link href="/<%= name %>/index.jsp">
> ^^^^^^^^^^^ Here is my problem!
> <bean:write name="pelement" property="longname"/>
> </html:link><br />
> </logic:iterate>
>
> The links always contain the <%= name %> string instead of the evaluated
> expression. I tried it with different quoting techniques but without luck.
>
> What is the correct solution here?
>
> TIA,
> Erich
>
You are up against the fact that runtime expressions and string constants
cannot be mixed in an attribute of a custom tag -- it's got to be one or
the other. One way to deal with it is this:
<html:link href="<%= "/" + name + "/index.jsp" %>">
which uses a Java string expression to calculate the entire value.
Craig