gpt4 book ai didi

if-statement - Struts 2 如果标签 : test with a constant

转载 作者:行者123 更新时间:2023-12-01 12:55:00 24 4
gpt4 key购买 nike

我正在制作以下代码:

<s:if test="%{#beanVar == com.mycompany.project.NOT_REGISTERED} ">
<td>NOT REGISTRED</td>
</s:if>

哪里 com.mycompany.project.NOT_REGISTERED 是一个类静态字段:
public static final long NOT_REGISTERED == 0;

我在 Struts2 文档中找不到在运行时评估中公开常量的方法。

在此先感谢您的帮助。

P.S :我不想使用老式构造 <% %>

最佳答案

来自OGNL基础知识:

Accessing static properties OGNL supports accessing static properties as well as static methods.

By default, Struts 2 is configured to disallow this--to enable OGNL's static member support you must set the struts.ognl.allowStaticMethodAccess constant to true via any of the Constant Configuration methods.

OGNL's static access looks like this:

@some.package.ClassName@FOO_PROPERTY
@some.package.ClassName@someMethod()

However, XWork allows you to avoid having to specify the full package name and call static properties and methods of your action classes using the "vs" prefix:

@vs@FOO_PROPERTY @vs@someMethod()
@vs1@FOO_PROPERTY @vs1@someMethod()
@vs2@BAR_PROPERTY @vs2@someOtherMethod()

"vs" stands for "value stack". The important thing to note here is that if the class name you specify is just "vs", the class for the object on the top of the stack is used. If you specify a number after the "vs" string, an object's class deeper in the stack is used instead.



问候,

关于if-statement - Struts 2 如果标签 : test with a constant,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10298071/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com