title: Primefaces DefaultTreeNode to TreeNode conversion issue
body: <p>I am trying to implement my side navigation menu using Primefaces TreeNode. I was trying to use this example in my project, but with javax annotations instead of JSF. </p>
  
  <p>Using Mojarra 2.2.12-jbossorg-2 with PrimeFaces 6.0</p>
  
  <p>But when I run my application, I get the below exception</p>
  
  <blockquote>
    <p>SEVERE [javax.enterprise.resource.webcontainer.jsf.application] (default task-8) Error Rendering View[/views/home.xhtml]: javax.el.ELException: /views/common/navigation/navigation-menu.xhtml @12,41 value="#{navTree.root}": java.lang.IllegalArgumentException: Cannot convert Menu of type class org.primefaces.model.DefaultTreeNode to interface org.primefaces.model.TreeNode</p>
  </blockquote>
  
  <pre><code>import java.io.Serializable;
  
  import javax.enterprise.context.SessionScoped;
  import javax.inject.Named;
  
  import org.primefaces.model.DefaultTreeNode;
  import org.primefaces.model.TreeNode;
  
  @Named("bcService")
  @SessionScoped
  public class BreadCrumbService implements Serializable {
  
      private static final long serialVersionUID = 1L;
  
      @SuppressWarnings("unused")
      public TreeNode createDocuments() {
          TreeNode root = new DefaultTreeNode(new Document("Menu", "root"), null);
          // Home
          TreeNode home = new DefaultTreeNode(new Document("Home", "home"), root);
  
          // Admin
          TreeNode admin = new DefaultTreeNode(new Document("Admin", "home"), home);
          TreeNode staff = new DefaultTreeNode("document", new Document("Staff", "home"), admin);
          TreeNode news = new DefaultTreeNode("document", new Document("News", "home"), admin);
          TreeNode availability = new DefaultTreeNode("document", new Document("Availability", "home"), admin);
          TreeNode printService = new DefaultTreeNode("document", new Document("PrintService", "home"), admin);
          TreeNode referenceDataCommon = new DefaultTreeNode("document", new Document("Reference Data Common", "home"), admin);
  
          // Billing
          TreeNode billing = new DefaultTreeNode(new Document("Billing", "home"), home);
          TreeNode initiateBilling = new DefaultTreeNode("document",new Document("Initiate Billing", "home"), billing);
          TreeNode billingMaintenance = new DefaultTreeNode("document",new Document("Billing Maintenance", "home"), billing);
          TreeNode viewBilling = new DefaultTreeNode("document", new Document("View Billing", "home"), billing);
  
          collapsingOrExpanding(home, true);
          return root;
      }
  
      public void collapsingOrExpanding(TreeNode n, boolean option) {
          if(n.getChildren().size() == 0) {
              n.setSelected(false);
          }
          else {
              for(TreeNode s: n.getChildren()) {
                  collapsingOrExpanding(s, option);
              }
              n.setExpanded(option);
              n.setSelected(false);
          }
      }
  }
  </code></pre>
  
  <p>Here is the NavigationTree</p>
  
  <pre><code>import javax.annotation.PostConstruct;
  import javax.enterprise.context.SessionScoped;
  import javax.inject.Inject;
  import javax.inject.Named;
  
  import org.primefaces.model.TreeNode;
  
  @Named("navTree")
  @SessionScoped
  public class NavigationTree implements Serializable {
  
      private static final long serialVersionUID = 1L;
      private TreeNode root;
      private TreeNode selectedNode;
  
      @Inject @Named("bcService")
      private BreadCrumbService service;
  
      @PostConstruct
      public void init() {
          root = service.createDocuments();
      }
  
      public void setService(BreadCrumbService service) {
          this.service = service;
      }
  
      public TreeNode getRoot() {
          return root;
      }
  
      public TreeNode getSelectedNode() {
          return selectedNode;
      }
  
      public void setSelectedNode(TreeNode selectedNode) {
          this.selectedNode = selectedNode;
      }
  }
  </code></pre>
  
  <p>And the JSF view</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;ui:composition xmlns="http://www.w3.org/1999/xhtml"
   xmlns:h="http://java.sun.com/jsf/html"
   xmlns:f="http://java.sun.com/jsf/core"
   xmlns:ui="http://java.sun.com/jsf/facelets"
   xmlns:c="http://java.sun.com/jstl/core"
   xmlns:p="http://primefaces.org/ui"
   xmlns:pe="http://primefaces.org/ui/extensions" xml:lang="en" lang="en"&gt;
  
   &lt;h:form&gt;
    &lt;p:tree value="#{navTree.root}" var="doc" selectionMode="single" 
     selection="#{navTree.selectedNode}" &gt;
     &lt;p:treeNode expandedIcon="fa fa-folder-open"
      collapsedIcon="fa fa-folder"&gt;
      &lt;h:outputText value="#{doc.name}" /&gt;
     &lt;/p:treeNode&gt;
     &lt;p:treeNode type="document" icon="fa fa-file-text-o fileColor"&gt;
      &lt;h:outputText value="#{doc.name}" /&gt;
     &lt;/p:treeNode&gt;
    &lt;/p:tree&gt;
   &lt;/h:form&gt;
  &lt;/ui:composition&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Complete stack trace</p>
  
  <pre><code>14:36:15,311 SEVERE [javax.enterprise.resource.webcontainer.jsf.application] (default task-8) Error Rendering View[/views/home.xhtml]: javax.el.ELException: /views/common/navigation/navigation-menu.xhtml @12,41 value="#{navTree.root}": java.lang.IllegalArgumentException: Cannot convert Menu of type class org.primefaces.model.DefaultTreeNode to interface org.primefaces.model.TreeNode
      at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:114)
      at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
      at org.primefaces.component.api.UITree.getValue(UITree.java:157)
      at org.primefaces.component.tree.TreeRenderer.encodeMarkup(TreeRenderer.java:234)
      at org.primefaces.component.tree.TreeRenderer.encodeEnd(TreeRenderer.java:191)
      at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:920)
      at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863)
      at javax.faces.render.Renderer.encodeChildren(Renderer.java:176)
      at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:890)
      at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
      at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
      at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
      at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:458)
      at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:134)
      at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
      at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
      at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
      at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
      at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
      at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
      at org.apache.deltaspike.jsf.impl.listener.request.DeltaSpikeLifecycleWrapper.render(DeltaSpikeLifecycleWrapper.java:111)
      at javax.faces.lifecycle.LifecycleWrapper.render(LifecycleWrapper.java:92)
      at org.apache.deltaspike.jsf.impl.listener.request.JsfClientWindowAwareLifecycleWrapper.render(JsfClientWindowAwareLifecycleWrapper.java:160)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:659)
      at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
      at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
      at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
      at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
      at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
      at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
      at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
      at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
      at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
      at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
      at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
      at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
      at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
      at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
      at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
      at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
      at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
      at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
      at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:285)
      at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:264)
      at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
      at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:175)
      at io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)
      at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:792)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: javax.el.ELException: java.lang.IllegalArgumentException: Cannot convert Menu of type class org.primefaces.model.DefaultTreeNode to interface org.primefaces.model.TreeNode
      at com.sun.el.ExpressionFactoryImpl.coerceToType(ExpressionFactoryImpl.java:87)
      at javax.el.ELContext.convertToType(ELContext.java:473)
      at com.sun.el.lang.EvaluationContext.convertToType(EvaluationContext.java:166)
      at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:229)
      at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
      at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
      at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
      ... 50 more
  Caused by: java.lang.IllegalArgumentException: Cannot convert Menu of type class org.primefaces.model.DefaultTreeNode to interface org.primefaces.model.TreeNode
      at com.sun.el.lang.ELSupport.coerceToType(ELSupport.java:428)
      at com.sun.el.ExpressionFactoryImpl.coerceToType(ExpressionFactoryImpl.java:85)
      ... 56 more
  </code></pre>
  
  <p>I looked up the PrimeFaces 6.0 API and didn't see any reason why it would have an issue from DefaultTreeNode to TreeNode</p>
  
  <p>I suspect the annotations, but not sure how to fix or what I am missing. Any help is appreciated.</p>
  
  <p>Thanks,
  Avinash</p>