本文介绍了javax.el.PropertyNotFoundException当试图解决在EL布尔属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的树节点类:

public abstract class DocumentTreeNode extends TreeNodeImpl implements javax.swing.tree.TreeNode
{
    private Boolean isToC;

    ...

    public Boolean isToC()
    {
        return isToC;
    }

    public void setToC(Boolean isToC)
    {
        this.isToC = isToC;
    }

}

这是指示文件是否被包括在任何或不是一个简单的复选框。然而,试图JSF内引用这个时候2 EL

This is a simple check box indicating whether the document is to be included in whatever or not. However, when trying to reference this from within JSF 2 EL

...
<h:selectBooleanCheckbox value="#{node.isToC}" />
...

我得到一个异常:

I get an exception:

产生的原因:javax.el.PropertyNotFoundException:/main.xhtml @ 541,64值=#{} node.isToC:类ChapterTreeNode'没有属性'isToC

(我想我几乎尝试了每一种组合,至少我觉得这种方式... ;-))

(I think I tried almost every combination, at least I felt this way... ;-) )

我如何解决布尔属性?需要改变什么?

How do I resolve that boolean property? What needs to be changed?

推荐答案

您不应该指定方法的名称,而只是属性名称。您需要省略(和 GET 设置 )preFIX指定bean的属性时。

You should not specify the method name, but just the property name. You need to omit the is (and get and set) prefix when specifying bean properties.

<h:selectBooleanCheckbox value="#{node.toC}" />

EL只是自动使用该属性的适当的getter / setter(注意,这确实意味着该实例变量的物理presence是没有必要的)。你得到的例外,

EL will just automatically use the proper getter/setter for the property (note that this indeed means that the physical presence of the instance variable is not necessary). The exception which you got,

产生的原因:javax.el.PropertyNotFoundException:/main.xhtml @ 541,64值=#{} node.isToC:类ChapterTreeNode'没有属性'isToC

基本上意味着,有没有这样的方法 isIsToc() getIsToc()(它有它的权利)。

basically means that there's no such method as isIsToc() or getIsToc() (and it has it right).

你的第二个问题是,你使用布尔而不是布尔。那么你真的应该调用方法 getToC() getIsToC()而不是 isToC( )。在后一种情况下,你可以继续使用#{node.isToC}

Your second problem is that you used Boolean instead of boolean. You should then really call the method getToC() or getIsToC() instead of isToC(). In the latter case, you can just continue using #{node.isToC}.




  • How does Java expression language resolve boolean attributes? (in JSF 1.2)
  • javax.el.PropertyNotFoundException: Property 'foo' not found on type com.example.Bean

这篇关于javax.el.PropertyNotFoundException当试图解决在EL布尔属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 03:37
查看更多