3.2. Using the Struts-EL Tags
Problem
You want to be able to use JSTL expressions for attribute values on Struts tags.
Solution
Use the tag libraries supplied with the Struts distribution in the
contrib/struts-el/lib directory. You will need
to copy all the JAR and TLD files from this directory to your
application's WEB-INF/lib
directory. Use the appropriate taglib directives
on JSP pages where you want to use expressions:
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html-el"
prefix="html-el" %>
Table 3-2 lists the Struts-EL tag libraries and
the corresponding taglib URIs.
Table 3-2. Struts-EL Taglib URIs
|
Tag library |
Struts-EL Taglib URI (1.1) |
Struts-EL Taglib URI (1.2) |
|---|---|---|
|
html-el | ||
|
bean-el | ||
|
logic-el |
Discussion
JSTL-style expressions, such as ${foo.bar[4].baz},
are not supported by the base Struts tags. For example, it would be
nice if you could format a tag using an expression like the
following:
<html:text value="${sessionScope.foo.bar[3]}"/>Instead, these tags require runtime expressions, which is just Java code:
<html:text
value="<%=session.((Foo)getAttribute("foo")).getBar(3)%>"/>Getting the Java code out of your JSP pages makes your pages less brittle and more maintainable. This lack of EL support was identified ...