2
votes

I currently use

  • Primefaces 3.5
  • JSF 2.1.6
  • Glassfish 3.1.2

and tried to put a composite component within a composite component.

Composite component:

     <?xml version="1.0" encoding="UTF-8" ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html 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:composite="http://java.sun.com/jsf/composite" xmlns:p="http://primefaces.org/ui"
   xmlns:components="http://java.sun.com/jsf/composite/components">

 <composite:interface>
   <composite:attribute name="myobject" required="true" />
 </composite:interface>

 <composite:implementation>

   <p:panelGrid id="container">      
     <components:newEntry outputLabelId="labelId" outputLabelValue="#{msgs.label}"
       selectOneMenuId="labelMenuId" selectOneMenuValue="#{myobject.value}"
       selectOneMenuItems="#{myobject.values}" update=":targets">
     </components:newEntry>
   </p:panelGrid>

 </composite:implementation>
 </html>

Nested composite component:

 <?xml version="1.0" encoding="UTF-8" ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html 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:composite="http://java.sun.com/jsf/composite" xmlns:p="http://primefaces.org/ui"
   xmlns:components="http://java.sun.com/jsf/composite/components">

 <composite:interface>
   <composite:attribute name="outputLabelId" required="true" />
   <composite:attribute name="outputLabelValue" required="true" />
   <composite:attribute name="selectOneMenuId" required="true" />
   <composite:attribute name="selectOneMenuValue" required="true" />
   <composite:attribute name="selectOneMenuItems" required="true" />
   <composite:attribute name="update" required="true" />

   <composite:attribute name="rendered" default="true" />
 </composite:interface>

 <composite:implementation>
   <p:row>
     <p:column>
       <p:outputLabel id="#{cc.attrs.outputLabelId}" value="#{cc.attrs.outputLabelValue}"
         rendered="#{cc.attrs.rendered}" />
     </p:column>
     <p:column>
       <p:selectOneMenu id="#{cc.attrs.selectOneMenuId}" value="#{cc.attrs.selectOneMenuValue}"
         effect="none" filter="true" filterMatchMode="contains" rendered="#{cc.attrs.rendered}">
         <f:selectItems value="#{cc.attrs.selectOneMenuItems}" />
         <p:ajax event="change" update="#{cc.attrs.update}" />
       </p:selectOneMenu>
     </p:column>
   </p:row>
 </composite:implementation>

 </html>

However I don't get an error message or a rendered element which is quite confusing.

Only when I move the nested component on the same level as its parent, is the nested component rendered.

Is this not supported in 2.1.6 or am I doing something wrong?

1
"Is this not supported in 2.1.6 " tried it? - Kukeltje
I thought PrimeFaces is based on JSF. Do you mean plain JSF 2.1.6 instead of PrimeFaces within? - Dr4gon
Sorry, should have stated: Tried a newer jsf version. My bad… - Kukeltje
My my sometimes I'm wondering what's going on in my head. Thanks for the simple and good question. I just tried 2.2 and 2.2.5. Both of them don't show the nested component. Does that mean I'm doing something wrong? - Dr4gon

1 Answers

2
votes

I just remembered that I had similiar problem earlier with the prime faces panelGrid. Somehow the panelGrid doesn't accept a nested component and just swallows it without an error or warning.

Replacing the prime faces panelGrid with a JSF one solves this problem:

<?xml version="1.0" encoding="UTF-8" ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html 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:composite="http://java.sun.com/jsf/composite" xmlns:p="http://primefaces.org/ui"
   xmlns:components="http://java.sun.com/jsf/composite/components">

 <composite:interface>
   <composite:attribute name="myobject" required="true" />
 </composite:interface>

 <composite:implementation>

   <h:panelGrid id="container">      
     <components:newEntry outputLabelId="labelId" outputLabelValue="#{msgs.label}"
       selectOneMenuId="labelMenuId" selectOneMenuValue="#{myobject.value}"
       selectOneMenuItems="#{myobject.values}" update=":targets">
     </components:newEntry>
   </h:panelGrid>

 </composite:implementation>
 </html>

I tested Prime faces 5.0 due to the JSF 2.3 dependency. In that version the problem was still present.