struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <ch...@christopherschultz.net>
Subject Re: Accessing action properties from JSPs
Date Sun, 04 Oct 2015 18:20:08 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Lukasz,

On 10/4/15 3:49 AM, Lukasz Lenart wrote:
> 2015-10-03 17:50 GMT+02:00 Christopher Schultz
> <chris@christopherschultz.net>:
>> Is this the latest wisdom for accessing action properties from
>> JSPs using EL?
>> 
>> https://struts.apache.org/docs/access-to-valuestack-from-jsps.html
>>
>>
>> 
So if my action has a "public String getItems)" method, I'd like to do
>> something as close as possible to this:
>> 
>> <c:forEach var="item" items="$action.items"> </c:forEach>
>> 
>> It looks like I can do this very quickly:
>> 
>> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 
>> <%@ taglib prefix="s" uri="/struts-tags" %> <s:set var="action"
>> value="items" /> <c:forEach var="item" value="${items}"> ... 
>> </c:forEach>
>> 
>> Is there something I can do to bind "action" to the actual
>> action instance?
>> 
>> Or I can use the Struts 2 "iterate" tag:
>> 
>> <%@ taglib prefix="s" uri="/struts-tags" %> <s:iterator
>> var="item" value="items"> </s:iterator>
>> 
>> I realize that this is a simple example, but is there a
>> recommended technique, here? EL gives me the ability to do things
>> like print values with somewhat less code: "${fn:escapeXml(foo)}"
>> versus <s:property escapeHtml="true" value="foo" />
>> 
>> In general, EL seems to be more universally understood, while the
>> s2 tags are a bit more specialized.
>> 
>> Any suggestions are appreciated.
> 
> JSTL/EL are supported out-of-the-box
> 
> https://struts.apache.org/docs/can-we-use-jstl-with-the-framework.html
>
> 
>> (After writing all of the above and experimenting, I've found
>> that I can reference ${items} in my JSP without doing anything
>> with the Struts2 tags: no <s:set> required. How is that working?
>> Does S2 export all my beans from the action (and other places?)
>> to the request attributes?).
> 
> The magic happens in StrutsRequestWrapper (Struts wraps each
> request with dedicated class). The wrapper first tries to fetch the
> attribute from the original request, if not found, it will use
> ValueStack to find the value.
> 
> https://github.com/apache/struts/blob/master/core/src/main/java/org/ap
ache/struts2/dispatcher/StrutsRequestWrapper.java#L72-L104

Thanks
> 
for the explanation. I'm very happy that this works... the
reference I provided at the top of my post suggests that working with
non-Struts2-provided tags could be difficult, but it hasn't been
difficult at all.

Thanks,
- -chris
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org

iQIcBAEBCAAGBQJWEW3YAAoJEBzwKT+lPKRYFSAQALqOJtcI6DxVdICqn4QVZB28
gtq51KVfs9EjaEBiuX4VqHiXOwDllegE2ruf18fvwZaD35lAeW22SRDcy0EquhAJ
qcWwdl3qxT9ge/sTgN3LaLpCJsJRgL+/IoSJ3MPH7/VhEPsM2roK/G2fcs5d9SQS
zGtGB09HEWuSL8Vm8KfIg2MdnejCDuWG0nrQcf6765C5sMTUTPYuNo+GgpBbjuad
zoyV6Lx7GhkQsrIUK4RDcMbKy7vd3In+2BmwDWR6hbMD2c5Nlbp7jJbpGaz760wS
itVi6TLslzASL3nBcmfOKv4NoEbOl6eT4/rOYbc8+9d6umMDTMa0OnDRnBl+FHVT
LHT/dwTlKThEGTKry74giR9xVV7kwnmk0Q5e3LmUns3gwYTMYOKHsOclVO6Bui6S
YyLjh7yfKi5vK/XNiaMNABkJOV/bLr46GYt9aA1X/tStV1EFbj3GQrZOHNPO+CPz
fqDctZkasuTUERhcp5lHRkekJhzLAjZtKPxacLWG4TQsdaYLTpHOSrvEGa5FEN2j
bBMGuDz7EVqOvGrXz2FdkP9e1oSCerQ1SBEWH9sr4yCwfIxkdyRr+zsz1pOlhD8o
lpSnUaViD7XJlZ8jKmaxMrk5xXRWzvvEujQlzIwAv2yNQm4XoRTrMa5kLl1qGaHH
fgcO2slGew8p5aSDibPd
=Bi6o
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message