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