struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <ch...@christopherschultz.net>
Subject Accessing action properties from JSPs
Date Sat, 03 Oct 2015 15:50:31 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

All,

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.

(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?).

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

iQIcBAEBCAAGBQJWD/lHAAoJEBzwKT+lPKRYAjkQAMfH92JS4kudGX8KJg1FH2zx
FC0Uvz4GZWtDDZhBy5EPZOuoLZhZevheejQq5dT9uRlWJaSBB39OrT2Lcdv+jNdL
vSQoP8bSQiHMD76SWe5GfeFcqTH0zNDutmrEiu+YjKcKcWIysDMDVveDrnKvWTQh
ZB13yys4HaDvE6r/gTxevVExSKcEe5s8GD/HRS9xtF5yjbKbA15i/LXa4XsnQvi+
guacbXPOewvs9CuRzV1JCR1y4YxJfjb+FJXnO3WtN3V5+kPHj/gE9ne/QcJHsQ2h
BOLjNve62kt2KRuiDA86c2cESD9Zv763udDfZ1LKI4q8xq4YaFl3uDFnwgB4zgxx
aIs2ftNnfMdhNXYlWSOFQL1HVA0iY78zsLdw5Xzu7Z9Jhioo20pxnt2PsiFdwa4z
jkMQAblJcmNCxHkVk1soayzv936GUVqvCIZbjqSQs/oPwZCpJF/fFmsmTTN/G4+R
iWXo0G9M/Zq9HpcmdXVlpjiGxW7EjTt6bYiqoKi0psvV3Rmy7UPVQUHh8Z9hKGz3
j5Wvl0m0Zhaf7dWMFpl5FnUICtOi1WUYUT6EQa3+usjEVdvoG/aB+6qreCl4G3Lo
1EU8lmT0IRORw6MaxZft152wCLPuGqiS3J+EFDzEexoPMd7M2Z37VF1KwogPA1N/
AJeYTvrTp5EillHT4ulu
=QyOq
-----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