JSF / Primefaces复合组件与嵌套复合组件

时间:2015-11-30 16:57:44

标签: jsf primefaces composite-component

我目前正在使用

  • Primefaces 3.5
  • JSF 2.1.6
  • Glassfish 3.1.2

并尝试将复合组件放在复合组件中。

复合组件:

     <?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>

嵌套复合组件:

 <?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>

但是,我没有收到错误消息或渲染元素,这非常令人困惑。

仅当我将嵌套组件移动到与其父级相同的级别时,才会呈现嵌套组件。

这在2.1.6中是否不受支持,或者我做错了什么?

1 个答案:

答案 0 :(得分:1)

我只记得早些时候我遇到过类似面部格格的问题。不知何故,panelGrid不接受嵌套组件,只是吞下它而没有错误或警告。

使用JSF替换primeface panelGrid解决了这个问题:

<?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>

由于JSF 2.3依赖性,我测试了Prime faces 5.0。在那个版本中,问题仍然存在。