我正在使用带有JSF mojarra 2.2的primefaces 3.5 我有一个带有两个ui的页面:include包含在一个p:对话框中,而ui:param用于将值传入/传出包含。
<p:dialog header="Customer Selection Criteria" widgetVar="customerSelectionDialog" width="1200" position="center" appendToBody="true">
<h:form id="customerForm">
<p:outputPanel id="customerSelection">
<ui:include src="../INTERNAL/8500.xhtml">
<ui:param name="showCidSelect" value="1" />
<ui:param name="targetObject" value="#{customerDetailsInquiry.cf8444.cg1014.cg1014cidnumb}" />
</ui:include>
<p:commandButton rendered="false" value="#{COMMON.COMMON_SELECTBUTTON}" action="#{customerDetailsInquiry.tchelp.handleReturnFromCustomerSelectionCriteria}" oncomplete="customerSelectionDialog.hide();" update=":mainForm:cf8444icg1014c1002" >
<f:setPropertyActionListener value="#{customerSearchEngine}" target="#{flash.customerSearchEngine}"/>
</p:commandButton>
</p:outputPanel>
</h:form>
</p:dialog>
<p:dialog closeOnEscape="true" modal="true" appendToBody="false" header="Entity Stack" widgetVar="entityStackDialog" width="400" >
<h:form id="entityForm">
<ui:include src="../INTERNAL/StackedEntity.xhtml">
<ui:param name="displayCaption" value="CID Numbers" />
<ui:param name="department" value="8" />
<ui:param name="stackedObject" value="#{customerDetailsInquiry.cf8444.cg1014.cg1014cidnumb}" />
</ui:include>
</h:form>
</p:dialog>
支持Bean:
FaceletContext faceletContext = (FaceletContext) FacesContext.getCurrentInstance().getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY);
String paramValue = (String) faceletContext.getAttribute("showCidSelect");
现在问题出在“ showCidSelect ”参数上。
showCidSelect 决定是否在 8500.xhtml 中显示“选择”按钮。
由于上面示例中的“ showCidSelect ”设置为“1”,因此应该渲染选择按钮。
如果没有“ StackedEntity.xhtml ”的第二个对话框,则此功能完全正常。
但是当我把第二个对话框和它的ui:param这个停止工作时,FaceletContext getAttribute调用返回null。
截至目前,我被迫在两个对话框中都包含“ showCidSelect ”,然后一切正常。但我不知何故觉得这个问题还有其他更好的解决办法。
请求专家帮助
答案 0 :(得分:0)
通过将ui:include
和ui:param
重写为taglib中的自定义JSF标记,实际上解决了同样的问题。
然后你有一个很好的,易于重用的标签,如:
<widgets:showCustomerSelector targetObject="#{customerDetailsInquiry.cf8444.cg1014.cg1014cidnumb}" />
和
<widgets:stackedEntity displayCaption="CID Numbers" department="8" stackedObject="#{customerDetailsInquiry.cf8444.cg1014.cg1014cidnumb}" />
然后将新的命名空间添加到您使用它的每个JSF页面/模板中(当然):
xmlns:widgets="http://your-company/jsf/widgets/customer"
并写一个taglib:
WEB-INF/widgets.jsf.taglib.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<facelet-taglib version="2.2"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facelettaglibrary_2_2.xsd">
<namespace>http://your-company/jsf/widgets/customer</namespace>
<tag>
<tag-name>showCustomerSelector</tag-name>
<description>@TODO Document this. Here goes your 8500.xhtml You had it in INTERNAL, better put templates in e.g. WEB-INF/templates/group/sub-group/ to have it out of document-root.</description>
<source>resources/tags/show_customer_selector.xhtml</source>
<attribute>
<name>targetObject</name>
<description>@TODO Document this.</description>
<required>true</required>
<!-- @TODO Find a **WAY** better type-hint, like an interface? -->
<type>java.lang.Object</type>
</attribute>
<attribute>
<name>rendered</name>
<description>Whether this tag is being rendered by JSF engine. </description>
<required>false</required>
<type>java.lang.Boolean</type>
</attribute>
</tag>
<tag>
<tag-name>stackedEntity</tag-name>
<description>@TODO Document this. Here goes your StackedEntity.xhtml - keep file names lower_under_scored to avoid case-sensitive problems!</description>
<source>resources/tags/stacked_entity.xhtml</source>
<attribute>
<name>displayCaption</name>
<description>@TODO Document this.</description>
<required>true</required>
<type>java.lang.String</type>
</attribute>
<attribute>
<name>department</name>
<description>@TODO Document this.</description>
<required>true</required>
<type>java.lang.Number</type>
</attribute>
<attribute>
<name>rendered</name>
<description>Whether this tag is being rendered by JSF engine. </description>
<required>false</required>
<type>java.lang.Boolean</type>
</attribute>
<attribute>
<name>stackedObject</name>
<description>@TODO Document this.</description>
<required>true</required>
<!-- @TODO Find a **WAY** better type-hint, like an interface? -->
<type>java.lang.Object</type>
</attribute>
</tag>
</facelet-taglib>
最后,在web.xml
注册:
<context-param>
<description>JSF widget tags library</description>
<param-name>javax.faces.FACELETS_LIBRARIES</param-name>
<param-value>/WEB-INF/widgets.jsf.taglib.xml</param-value>
</context-param>