I have a superclass Person
:
public class Person {
public abstract Type getType();
}
I have 2 subclasses of it:
public class JuridicalPerson extends Person {
public Type getType() {
return Type.JP;
}
public List<JuridicalBelong> getJuridicalBelongs() {
return juridicalBelongs;
}
}
public class NaturalPerson extends Person {
public Type getType() {
return Type.NP;
}
public List<NaturalBelong> getNaturalBelongs() {
return naturalBelongs;
}
}
JuridicalBelong
and NaturalBelong
have different properties and can't be subclassed.
I have them in a List<Person>
which I'd like to present in JSF/Facelets as follows:
<ui:repeat value="#{bean.persons}" var="person">
<h:panelGroup rendered="#{person.type eq 'JP'}">
<ui:repeat value="#{person.juridicalBelongs}" var="juridicalBelong">
...
</ui:repeat>
</h:panelGroup>
<h:panelGroup rendered="#{person.type eq 'NP'}">
<ui:repeat value="#{person.naturalBelongs}" var="naturalBelong">
...
</ui:repeat>
</h:panelGroup>
</ui:repeat>
However, this causes the following exception:
javax.el.PropertyNotFoundException: The class 'com.example.NaturalPerson' does not have the property 'juridicalBelongs'.
How is this possible? As per my rendered
condition
<h:panelGroup rendered="#{person.type eq 'JP'}">
it should ignore NaturalPerson
, right?