You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by Craig Longman <cr...@begeek.com> on 2002/09/24 08:34:29 UTC
double EL evaluating
i've searched the archives, but have been unable to find an answer to
this, other than a question shawn made about wanting a real-world case
for it. i think i might have one, and i'm not sure how to proceed, so
i'll see what y'all think.
the situation is that i have an 'imported' page that displays a menu,
but the options in the menu change depending on what page imports it. i
achieve this by sending different parameters to the imported page, and
then the imported page goes from there. one of the parameters passed in
are parent_objectName, which, for example, can contain 'Product' or
'Service'. what i want to do is this:
<c:if test"${not empty param.typeID}">
<c:set var="${param.parent_objectName}_typeID" value="${param.typeID}"/>
</c:if>
then later:
<c:out value="${${parent_objectName}_typeID}"/>
this would store an attribute named either Product_typeID or
Service_typeID that could then be used elsewhere in the page.
unfortunately, the problems are plenty. it seems c:set.var isn't EL
enabled (there is nothing set by the name of Service_typeID for example)
and one can't 'double evaluate' in the c:out.value attribute.
the only way i can see of doing this now, is to create a custom tag that
performs the magic, which might make sense for me in this case anyway,
but i'd thought i'd throw this into the pit to be picked apart.
cheers,
--
CraigL->Thx();
Be Developer ID: 5852
Re: double EL evaluating
Posted by Shawn Bayern <ba...@essentially.net>.
On 24 Sep 2002, Craig Longman wrote:
> what i want to do is this:
>
> <c:if test"${not empty param.typeID}">
> <c:set var="${param.parent_objectName}_typeID" value="${param.typeID}"/>
> </c:if>
>
> then later:
>
> <c:out value="${${parent_objectName}_typeID}"/>
>
> this would store an attribute named either Product_typeID or
> Service_typeID that could then be used elsewhere in the page.
>
> unfortunately, the problems are plenty. it seems c:set.var isn't EL
> enabled (there is nothing set by the name of Service_typeID for
> example) and one can't 'double evaluate' in the c:out.value attribute.
>
> the only way i can see of doing this now, is to create a custom tag
> that performs the magic, which might make sense for me in this case
> anyway, but i'd thought i'd throw this into the pit to be picked
> apart.
You don't have to go that far. Indeed, you can't use dynamic values with
'var', and you can't begin a subordinate expression within a top-level
expression. However, using collections, it should be straightforward to
do what you want:
<%-- Set up a Map. Of course, a back-end servlet could do this too. --%>
<jsp:useBean id="types" class="java.util.Map" />
<c:if test="${not empty param.typeID}">
<c:set target="${types}"
property="${param.parent_objectName}_typeID"
value="${param.typeID}" />
</c:if>
This saves information, which you can later retrieve with
<c:set var="propertyName" value="${param.parent_objectName}_typeID" />
<c:out value="${types[propertyName}" />
Note the <c:set>, which lets us build up a complex temporary key into
'types'; you can't concatenate strings in the JSTL EL, so the
concatenation must occur outside an expression -- in this case, in the
attribute value of <c:set>.
Hope that helps,
--
Shawn Bayern
"JSTL in Action" http://www.jstlbook.com
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>