簡體   English   中英

具有嵌套復合組件的JSF / Primefaces復合組件

[英]JSF / Primefaces composite component with nested composite component

我目前使用

  • Primefaces 3.5
  • JSF 2.1.6
  • 玻璃魚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是否不支持此功能,或者我做錯了什么?

我只是記得我以前在素面panelGrid上遇到過類似的問題。 panelGrid不知何故不接受嵌套的組件,只是吞下了它而沒有錯誤或警告。

用JSF替換素面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 face 5.0。 在那個版本中,問題仍然存在。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM