[英]struts ognl dynamic expression
I've spent the last few hours to get a Struts expression to work as I want but didn' t succeeded. 我花了最后几个小时让Struts表达式可以按我的意愿工作,但没有成功。
I want to execute a OGNL expression from a String. 我想从字符串执行OGNL表达式。
By example, I have the following code : 例如,我有以下代码:
<s:push value="#row">
alert('<s:property value="id + ' ' + id" />');
</s:push>
This works perfectly giving me the id of the object twice. 这可以完美地给我两次对象的ID。
This example 这个例子
<s:push value="#row">
<s:set name="expr" value="id + ' ' + id"/>
alert('<s:property value="%{#expr}" />');
</s:push>
works fine too. 也可以。
But now, if I create a method in my action : 但是现在,如果我在操作中创建一个方法:
public String getTest() {
return "id + ' ' + id";
}
and in the JSP : 并在JSP中:
<s:set name="expr" value="getTest()"/>
<s:push value="#row">
alert('<s:property value="%{#expr}" />');
</s:push>
The result is : 结果是:
alert('id + ' ' + id');
which doesn't work because of quotes. 由于引号而无法使用。
But why in my last example I have the String value and not the expression evaluated ? 但是,为什么在我的上一个示例中,我具有String值而不是表达式求值?
I've tried a lot of possibilities, read articles, tutorials but didn't find a suitable answer to my problem. 我尝试了很多可能性,阅读了文章,教程,但没有找到解决我问题的合适方法。
Struts 2 escapes the ActionMessages by default. Struts 2默认情况下会转义ActionMessages。
Try <s:property value="%{#expr}" escape="false"/>
尝试
<s:property value="%{#expr}" escape="false"/>
UDPATE UDPATE
Try 尝试
alert(<s:property value="%{#expr}" />);
Not 不
alert('<s:property value="%{#expr}" />');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.