2

我将 primefaces 3.5 与 JSF mojarra 2.2 一起使用。
我有一个包含两个 ui:include 的页面,它们包含在 ap:dialog 中,并且 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>

支持豆:

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 ”,然后一切正常。但我不知何故觉得这个问题还有其他更好的可能解决方案。

请求专家帮助

4

1 回答 1

0

它实际上通过在 taglib 中重写和自定义 JSF 标记解决了同样的问题。ui:includeui:param

然后你有一个很好且易于重用的标签,例如:

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

并编写一个标签库:

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>
于 2017-08-20T21:04:47.053 回答