具有嵌套复合组件的 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 替换 prime faces 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。在那个版本中问题仍然存在。
我目前使用
- 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 替换 prime faces 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。在那个版本中问题仍然存在。