I have an object x
, which can have one Parameter
. A Parameter
is either a ParaA
or a ParaB
.
public abstract class Parameter {
private final String displayPage;
public Parameter(String displayPage) {
this.displayPage= displayPage;
}
}
public class ParaA extends Parameter {
private List<String> strings;
private String currentString;
}
public class ParaB extends Parameter {
private int min;
private int max;
}
I want to display each type of Parameter
in a different way, so I use <ui:include src="#{bean.parameter.displayPage}" />
to determine the .xhtml
of each type of Parameter
.
For example the paraA_displayPage.xhtml
looks like this:
<h:outputText value="ParaA" />
<p:dataTable var="s" value="#{bean.parameter.strings}">
<p:column>
<h:outputText value="#{s}" />
</p:column>
</p:dataTable>
This obviously doesn't work, because I have to cast Parameter
to ParaA
. So how can I manage this casting stuff in jsf
?
I could use something ugly like this, as recommended here: https://community.oracle.com/thread/1731149?start=0&tstart=0 but there is probably a better way.
public abstract class Parameter {
public ParaA getParaA() {
return (ParaA) this;
}
public ParaB getParaB() {
return (ParaB) this;
}
}