How do I convert a JSP variable to a Struts2 variable?
I've tried the following:
<%=scoredDocument%>
<s:push value="scoredDocument"/>
<s:push value="#scoredDocument"/>
<s:push value="%{scoredDocument}"/>
<s:push value="${scoredDocument}"/>
<s:push value="#page.scoredDocument"/>
<s:push value="%{#page.scoredDocument}"/>
<display:column title="Study Code" sortable="true">
<s:property value="id"/>
The most frequent error is
Caused by: tag 'push', field 'value': You must specify a value to push on the stack. Example: person - [unknown location]
<s:push>
must enclose the<s:property>
tag. Also#attr
? WTF Struts? It's not even documented! https://struts.apache.org/release/2.0.x/docs/jsp.htmlThe
push
tag requires thevalue
attribute and it has to be initialized, otherwise it shows the JSP error. Unlike other tags where the value could be preinitialized with empty string, the JSP doesn't complain.The OGNL expression is evaluated in this attribute, like in many other attributes of Struts tags, and if can't resolve the value it returns
null
. This value is unacceptable for thepush
tag and it throws exception. The error mislead to make a different tries to access the scriptlet variable value via the OGNL expression, unfortunately none of that methods worked.Scriptlet expressions has a one pitfall when used with the Struts tags that you can use only in the body of the tag and it's converted to string. Like in this example
you can't do the same with the
push
tag. After that you can use the stringified version of#scoredDocument
in OGNL expressions.