1

I have a class and subclasses who extends that. Like this:

 @Table
    @Entity
    class Cat{



    class DomesticCat extends Cat{
       String litterBox;

    //getter and setters


    }

    class TigerCat extends Cat{
       String huntingStyle;

    //getter and setters
    }


}

i have a List<Cat> cats in my controller bean. i filled it like

cats.add(new DomesticCat());
cats.add(new TigerCat());

Here i want to write sth like this in my xhtml page

<ui:repeat var="cat" value="#{controller.cats}">
<outputText rendered="tried some control here, did not work" value="cat.litterBox"/>
</ui:repeat>

i am getting "Property not found exception".

is it possible?

EDIT

Wrong question sorry, what do you advise me to do to using extending subclasses and JSF together.

merveotesi
  • 2,145
  • 15
  • 53
  • 84
  • possible duplicate of [JSF and expression language: Bind property only when it exists](http://stackoverflow.com/questions/5619183/jsf-and-expression-language-bind-property-only-when-it-exists) – McDowell Feb 26 '12 at 10:46
  • Duplicate of http://stackoverflow.com/questions/22613193/javax-el-propertynotfoundexception-when-submitting-uirepeat-with-conditionally/ – BalusC Aug 12 '14 at 18:38

2 Answers2

1

When the Expression Language tries to resolve the litterBox property on an instance of TigerCat it will throw an exception.

See the documentation for BeanELResolver in the EL specification:

getValue(ELContext, Object, Object)

other documentation elided...

If the property is not found or is not readable, a PropertyNotFoundException is thrown.

This is the expected behaviour.

McDowell
  • 107,573
  • 31
  • 204
  • 267
0

Yes it's possible and it's the correct behavior.

How would the EL parser go about resolving litterBox on 'TigerCat'? If both a TigerCat and DomesticCat are added to the list cats, an exception will thrown when it hits your TigerCat.

If you put a dog in the list with the cats and put value="dog.bark" wouldn't you expect the same behavior?

Jonathan S. Fisher
  • 8,189
  • 6
  • 46
  • 84