You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Dan Eklund <DE...@intralinks.com> on 2003/06/04 22:28:00 UTC

struts (and JSTL) expression language questions

Hello all,

I'm a bit concerned (after spending a few days spinning my wheels) on 
a few aspects of the EL implementation both with the struts-el libraries
and the JSTL core EL implementation.
The following are a few of my observations.  I was wondering if people
here could confirm these as problematic, or tell me I'm smoking crack.

1) It's not easy to access a 'normal' variable using the expression 
language.
Instead you have to coerce it into the page scope.
Something like:

<%
        // a transfer object
        EmployeeData   empData    = someEJBFacade.returnEmployeeData( ... 
);
%>
<c:out value="${empData.name}" />
<html-el:text name="employeeName" value="${empData.name}" />

will not work (I'm running weblogic 7.0 -- haven't tried it yet on tomcat)

Instead I have to do something like:
<%
        // a transfer object
        EmployeeData empData = someEJBFacade.returnEmployeeData( ... );
        pageContext.setAttribute("empData",empData);
%>
<c:out value="${pageScope.empData.name}" />
<html-el:text name="employeeName" value="${pageScope.empData.name}" />

2 ) There seems to be no way to combine arbitrary method invocations, or 
static variables
 with an  EL evaluated attribute.

        <html-el:hidden 
property="${DBConstants.SOME_STATIC_CONSTANT}:${pageScope.empData.name}" 
/>
will not work (can't combine static variables)
        <html-el:link 
href="java.net.URLEncoder.encode(${pageScope.empData.name})"
will not work 'cause you can only combine EL variables and literals.

3 ) You cannot go back and forth between EL and RT in loops. (yeah i know 
this has nothing to do with
struts, but it seems all part of the same bag)
        <c:forEach items="${pageScope.empData.accolades}" var="accolade">
             <%  Log.print(accolade.ID) %>
        </c:forEach>
will not work.... I had assumed that if the <forEach> had declared an 
identifier called 'accolade' ,
then I would be able to access it as a java variable named 'accolade'...
Instead 'accolade' as an identifier is ONLY available to EL evaluations 
and not the servlet code itself.


If anyone thinks these observations have more pertinence on another 
mailing-list/news-group, 
please drop me a line.  I have observed that there are hacks available for 
all the above
problems except 3).... But I am tired of hacks.

As for now, I've decide that the JSTL-EL and the Struts-EL are too odd for 
me to continue researching
their shortcomings.  Although I love the concept of a more compact 
language that EL offers, I think
I'll have to stick with the existing <jsp:usbean>, normal struts with RT, 
and the normal logic struts for loops
and conditionals.

thanks for any comments,
Daniel Eklund