0

I'm trying to include different file according to the type of my java object.

I'm doing something like that :

<p:panelGrid rendered="#{adapter.habitation}" >
    <ui:include src="./habitation.xhtml" />
</p:panelGrid>

<p:panelGrid rendered="#{adapter.animas}">
    <ui:include src="./animals.xhtml" />
</p:panelGrid>

But all my cases throw an exception because it's trying to resolve all xhtml files.

Any idea what's wrong?

Thanks

  • What is the exception? It is perfectly normal that all the fragment files are "resolved" by the way. You may not be allowing content to be rendered to the view, but it still becomes part of the JSF component tree. – Gimby Jun 19 '15 at 10:54
  • Here is my exception : javax.servlet.ServletException: /animals.xhtml @15,57 value="#{adapter.newType}": The class 'com.adapter.AdapterHabitation' does not have the property 'newType'. at javax.faces.webapp.FacesServlet.service(FacesServlet.java:606) newType is only in the class animal but my object is an instance of habitation – Romain Hoog Jun 19 '15 at 11:58

1 Answers1

0

You need a boolean expression in rendered attribute.

Try this:

<p:panelGrid rendered="#{adapter.habitation != null}" >
    <ui:include src="./habitation.xhtml" />
</p:panelGrid>

<p:panelGrid rendered="#{adapter.animas != null}">
    <ui:include src="./animals.xhtml" />
</p:panelGrid>
Miguel
  • 536
  • 6
  • 20
  • adapter.habitation and adapter.animas are boolean values I tried this way adapter.habitation == true Or directly rendered == false but it doesn't work – Romain Hoog Jun 19 '15 at 13:20
  • Ok, I thought your objects in rendered attribute were the main objects in your pages. I have been reading about your problem and I found a BalusC's answer: http://stackoverflow.com/questions/11989631/skip-executing-uiinclude-when-parent-ui-component-is-not-rendered/11991895#11991895 – Miguel Jun 22 '15 at 06:49