13

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?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Kawu
  • 13,647
  • 34
  • 123
  • 195

1 Answers1

23

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:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Hmm it's not as easy as it appears. I *want* to call my boolean `isToC` in the class, but the getter's name is supposed to be `isToC()`, too. In JSF XHTML this would be `#{file.toC}`. This now throws another exception: `The class 'de.poyry.pqgenerator.pqtree.ChapterTreeNode' does not have a readable property 'toC'.` I guess I have to give up on naming my booleans the same as the fields? – Kawu Sep 16 '11 at 19:04
  • 3
    Sorry, I overlooked that you used `Boolean` instead of `boolean`. You have to replace it by `boolean` or to rename the getter to `getToC()`. – BalusC Sep 16 '11 at 19:07
  • Strange stuff! Hmm. So Boolean is just treated as a non-boolean... I decided to rename the getter to `getIdToc` so I can use `#{file.isToC}` from JSF and keep `isToC` as the field name. – Kawu Sep 16 '11 at 19:15
  • 10
    EL does not do autoboxing, no. `Boolean` is an `Object`. – BalusC Sep 16 '11 at 19:17