如何在Struts 2中测试bean属性? [英] How to test bean property in Struts 2?

查看:72
本文介绍了如何在Struts 2中测试bean属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的班级:

public class Foo {
    public boolean isValid() {
        return false;
    }
}

在我的JSP文件中,我想在测试条件下使用isValid方法:

In my JSP file I want to use the isValid method in a test condition:

<s:bean name="com.Foo" var="bar"></s:bean>
<s:if test="%{bar.valid == false}">
    <p>hello</p>                    
</s:if>

但是它不起作用.我做错了什么?

but it doesn't work. What did I do wrong?

推荐答案

#引用了上下文变量,但是您使用了没有数字符号的名称bar.

Context variables are referenced by #, but you've used a name bar without number sign.

<s:if test="%{#bar.valid == false}">
    <p>hello</p>                    
</s:if>


查看OGNL的变量引用语言指南.


Look at the Variable References of the OGNL language guide.

OGNL有一个简单的变量方案,可让您存储中间变量 结果并再次使用它们,或者只是命名事物以表达 更容易理解. OGNL中的所有变量都是全局变量 表达.您使用数字前面的数字符号来引用变量 它的名字,像这样:

OGNL has a simple variable scheme, which lets you store intermediate results and use them again, or just name things to make an expression easier to understand. All variables in OGNL are global to the entire expression. You refer to a variable using a number sign in front of its name, like this:

#var

这篇关于如何在Struts 2中测试bean属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆