Thanx you Dave for your advice!
I switched off the JSTL-EL (as it was recomended in Struts2 wiki), so I
wrote another working code:
<% request.setAttribute("jspContext", jspContext); %>
<s:property value="%{#attr.jspContext.getAttribute('fieldName')}"/>
And another more complex variant:
--------------------------------------
<%
class JspContextUtils {
private static final String ATTR_MAP_NAME =
"jspContext";
private PageContext pageContext;
private ServletRequest request;
public JspContextUtils(JspContext jspContext) {
pageContext = (PageContext) jspContext;
request = pageContext.getRequest();
}
public void exposeTagAttributeToOgnl(String attrName) {
Map<String, Object> attrMap = null;
Object attrMapObj =
request.getAttribute(ATTR_MAP_NAME);
if (attrMapObj == null || !(attrMapObj
instanceof Map)) {
attrMap = new HashMap<String, Object>();
request.setAttribute(ATTR_MAP_NAME,
attrMap);
} else {
attrMap = (Map<String, Object>)
attrMapObj;
}
attrMap.put(attrName,
pageContext.getAttribute(attrName));
}
}
JspContextUtils jspContextUtils = new
JspContextUtils(jspContext);
%>
<% jspContextUtils.exposeTagAttributeToOgnl("fieldName"); %>
<s:property value="%{#attr.jspContext.fieldName}"/>
--------------------------------------
P.S. What did you mean by this?:
"The answer is easier if this .tag file contains no recursive calls."
DNewfield wrote:
>
> The answer is easier if this .tag file contains no recursive calls.
> The issue is that the .tag file receives attributes through jstl-el, not
> ognl. You can use the jstl-el c:set tag to promote that value into a
> namespace that's also accessible from ognl.
>
> Alex Siman wrote:
>> /WEB-INF/tags/formField.tag
>> --------------------------------------------------------------
>> <%@ attribute name="fieldName" %>
> <c:set var="fieldNameInTag" scope="request" value="${fieldName}"/>
> <s:property value="%{#request.fieldNameInTag}"/>
>
> -Dale
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
>
--
View this message in context:
http://www.nabble.com/How-to-get-value-of-tag-attribute-from-OGNL--tp25862967p25876315.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]