Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javax.el.PropertyNotFoundException when trying to resolve Boolean properties in EL

I have the following tree node class:

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;
    }

}

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:

Caused by: javax.el.PropertyNotFoundException: /main.xhtml @541,64 value="#{node.isToC}": The class 'ChapterTreeNode' does not have the property '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?

like image 341
Kawu Avatar asked Sep 15 '11 21:09

Kawu


1 Answers

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 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,

Caused by: javax.el.PropertyNotFoundException: /main.xhtml @541,64 value="#{node.isToC}": The class 'ChapterTreeNode' does not have the property 'isToC'.

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

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}.

See also:

  • How does Java expression language resolve boolean attributes? (in JSF 1.2)
  • javax.el.PropertyNotFoundException: Property 'foo' not found on type com.example.Bean
like image 106
BalusC Avatar answered Oct 20 '22 17:10

BalusC