> To: user@struts.apache.org > From: ch...@christopherschultz.net > Subject: Accessing action properties from JSPs > Date: Sat, 3 Oct 2015 11:50:31 -0400 > > -----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? MG>the <result...>jsp</result> is 'bound' inside struts-config.xml to parent <action tag https://struts.apache.org/docs/action-configuration.html MG>if on the other hand you want to use a different method to execute then you can use DMI https://cwiki.apache.org/confluence/display/WW/Action+Configuration#ActionConfiguration-DynamicMethodInvocation > > 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. MG>s2 tag resolution provides access to struts value stack via OGNL expression(s) > > 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? MG>in that case struts resolves this as a property placed on ValueStack https://struts.apache.org/docs/tag-syntax.html
Does S2 export > all my beans from the action (and other places?) to the request > attributes?). MG>if specified by scope attrib e.g. <s:set ...scope="request"/> https://struts.apache.org/docs/set.html > > Thanks, > - -chris MG>does that answer your understanding of struts-tags? > -----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-unsubscr...@struts.apache.org > For additional commands, e-mail: user-h...@struts.apache.org >