struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <>
Subject RE: [struts-el] What's the benefits ?
Date Thu, 06 Mar 2003 01:51:45 GMT

> From: alexj []
> I didn't find the benefits of the use of jstl extention.
> Who can explain me the benefits ?

> From: p2 - apache <>
> Some body don't want to see <% .... %>? Just a guess.

There's lots of advantages to the expression language that Struts-EL uses
(copied from JSTL 1.0, and to be embedded everywhere in a JSP page in JSP
2.0).  My favorite feature is independence from the underlying
implementation of the properties.  Consider the following expression:


This works for all of the following scenarios (as well as some others):

* "customer" is a bean with a getMailAddress() getter, which in term
  returns a bean with a getCity() getter.

* "customer" is a bean where getMailAddress() returns a Map that has
  (among others) an entry with a key of "city".

* "customer" is a Map that has a key "mailAddress" whose value is a
  bean with a getCity() method.

* "customer" is a Map with a key of "mailAddress" that returns a Map
  that has a key of "city" ...

You get the idea?  The business tier developer has a fair amount of
freedom in how they implement the beans representing the data required by
the view tier -- or even skips implementing them if Maps do the trick.
And changing your mind among these choices does not invalidate the syntax
of the expression that is embedded in your page.

The other thing I like about EL expressions is that the syntax is very
close to what page authors familiar with JavaScript already understand, so
it's natural for them to be able to script with it, without having to know
any java at all.  Consider a personnel management app that wants to
restrict the display of salary information to managers.  In a JSP 1.2
environment (with JSTL), you could write:

  <c:if test="${user.role = 'Manager'}">
    <c:out value="${employee.salary}"/>

and have a fair chance that the page author can understand it -- while the
corresponding scriptlet version is pretty opaque to a non-programmer:

     if (user.getRole().equals("Manager")) {

to say nothing of the fact that the Java code requires you to expose
"user" and "employee" as instance variables in the page class, while the
tagged version doesn't.  (And, by the way, you'd better be prepared for
NullPointerException errors in the scriptlet, while the expression
language deals with them for you.)

By the way, in a JSP 2.0 environment, this example will get even simpler:

  <c:if test="${user.role = 'Manager'}">

because you will be able to use EL expressions anywhere (including
template text), not just in tags that understand it.

Craig McClanahan

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message