1

标题真的很烂,但我找不到更简洁的标题。

我的应用程序实际上包含一个使用 Primefaces 和 JSF 2.x 的 JSF 页面。我正在使用 Primefaces 布局标签来构造页眉、页脚、导航和内容。很简单的东西。导航使用 PF Tree 组件,当我单击一个节点时,会显示该节点的内容。我对所有可能的内容使用 render=。目前,每个内容都包含在内,因此我可以使主页更易于阅读。内容是显示从数据库返回的记录的数据表,选择每个记录会显示该选择的值。将其视为布局内的布局。内部布局包含一个数据表,然后是用于查看所选数据的面板网格。我可以毫无问题地添加、更新和删除。

我的问题是我尝试使用 Facelets 来动态包含内容,而不是设置 render=。这样做的代码是:

<?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">
<ui:composition template="inc-templates/main-template.xhtml"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html">
    <ui:define name="centerContent">
        <ui:include src="/#{UtilBean.contentPage}.xhtml"/>
    </ui:define>
</ui:composition>

当单击树中的节点时,UtilBean 设置 contentPage。我现在有 2 个节点 - 图形消息和电子邮件模板。

图形消息.xhtml

<?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:p="http://primefaces.org/ui"
      xmlns:pe="http://primefaces.org/ui/extensions"
      xmlns:ui="http://java.sun.com/jsf/facelets">
    <h:head>
        <title>Facelet Title</title>
    </h:head>
    <h:body>
        <ui:composition>
                <p:layout id="graphicMessageLayout"
                          style="height: 100%;width: 100%;">
                    <p:layoutUnit id="gmDataTableLU" position="west" size="270"
                                  header="Graphic Messages" closable="false" collapsible="true"
                                  resizable="true">
                        <h:form id="dataTableForm">
                            <p:dataTable id="gmDataTable" var="graphicMessage"
                                         value="#{GraphicMessageBean.graphicMessages}"
                                         paginatorPosition="bottom" widgetVar="gmDataTableVar"
                                         rowKey="#{graphicMessage.graphicMessageUID}"
                                         selection="#{GraphicMessageBean.selectedGraphicMessage}"
                                         selectionMode="single"
                                         style="background: #5d8bba !important; color: white !important;">
                                <pe:paginator
                                        paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
                                        pageLinks="3"
                                        rows="20"/>
                                <p:ajax event="rowSelect" update=":centerForm:ogrid"/>
                                <p:column id="messageId" sortBy="#{graphicMessage.messageId}"
                                          style="width: 25%; text-align: left; white-space: nowrap; padding-left: 5px; padding-right: 5px;"
                                          headerText="Message Id">
                                    <h:outputText value="#{graphicMessage.messageId}" style="white-space: nowrap;"/>
                                </p:column>
                            </p:dataTable>
                        </h:form>
                    </p:layoutUnit>
                    <p:layoutUnit position="center">
                        <h:form id="centerForm" prependId="false">
                            <div id="outerpanel"
                                 style="margin-left: auto; margin-right: auto; margin-top: 50px; width: 470px">
                                <p:panelGrid id="ogrid" styleClass="gmGrid">
                                    <f:facet name="header">
                                        <p:row>
                                            <p:column colspan="2">Graphic Message Properties</p:column>
                                        </p:row>
                                    </f:facet>
                                    <p:row>
                                        <p:column>
                                            <h:outputText value="Message Id:"/>
                                        </p:column>
                                        <p:column>
                                            <p:inputText
                                                    disabled="#{GraphicMessageBean.disabled or GraphicMessageBean.update}"
                                                    value="#{GraphicMessageBean.messageId}"/>
                                        </p:column>
                                    </p:row>
                                    <p:row>
                                        <p:column>
                                            <h:outputText value="Description:"/>
                                        </p:column>
                                        <p:column>
                                            <p:inputText disabled="#{GraphicMessageBean.disabled}"
                                                         value="#{GraphicMessageBean.description}"/>
                                        </p:column>
                                    </p:row>
                                    <p:row>
                                        <p:column>
                                            <h:outputText value="URL:"/>
                                        </p:column>
                                        <p:column>
                                            <p:inputText disabled="#{GraphicMessageBean.disabled}"
                                                         value="#{GraphicMessageBean.graphicURL}"/>
                                        </p:column>
                                    </p:row>
                                    <p:row>
                                        <p:column>
                                            <h:outputText value="Image Source:"/>
                                        </p:column>
                                        <p:column>
                                            <p:selectOneMenu id="selectMenu" value="#{GraphicMessageBean.imageSrc}"
                                                             effect="fade"
                                                             valueChangeListener="#{GraphicMessageBean.viewImageSrc}"
                                                             disabled="#{GraphicMessageBean.disabled}">
                                                <f:selectItem itemLabel="Select One" itemValue=""/>
                                                <f:selectItems value="#{GraphicMessageBean.imageSrcItems}"/>
                                                <p:ajax update="imagesrc"/>
                                            </p:selectOneMenu>
                                        </p:column>
                                    </p:row>
                                    <p:row>
                                        <p:column id="imageSrcColumn" colspan="2">
                                            <div class="imgWrap">
                                                <h:panelGroup id="imagesrc">
                                                    <h:graphicImage

                                                            value="http://localhost/media/ep2demo/banners/#{GraphicMessageBean.imageSrc}"
                                                            height="150px"/>
                                                </h:panelGroup>
                                            </div>
                                        </p:column>
                                    </p:row>
                                    <f:facet name="footer">
                                        <p:row id="buttonRow">
                                            <p:column colspan="2" style="text-align: center;">
                                                <p:commandButton value="Add" rendered="#{GraphicMessageBean.add}"
                                                                 actionListener="#{GraphicMessageBean.addGraphicMessage}"
                                                                 update="ogrid"/>
                                                <p:commandButton value="Edit" rendered="#{GraphicMessageBean.edit}"
                                                                 actionListener="#{GraphicMessageBean.editGraphicMessage}"
                                                                 update="ogrid"/>
                                                <p:commandButton value="Delete" rendered="#{GraphicMessageBean.delete}" onstart="alert('Are you sure?');"
                                                                 actionListener="#{GraphicMessageBean.deleteGraphicMessage}"
                                                                 update="ogrid :dataTableForm:gmDataTable"/>
                                                <p:commandButton value="Update" rendered="#{GraphicMessageBean.update}"
                                                                 actionListener="#{GraphicMessageBean.updateGraphicMessage}"
                                                                 update="ogrid gmMessages"/>
                                                <p:commandButton value="Save" rendered="#{GraphicMessageBean.save}" 
                                                                 actionListener="#{GraphicMessageBean.saveGraphicMessage}"
                                                                 update="ogrid :dataTableForm:gmDataTable"/>
                                                <p:commandButton value="Cancel" rendered="#{GraphicMessageBean.cancel}"
                                                                 actionListener="#{GraphicMessageBean.cancelGraphicMessage}"
                                                                 update="ogrid"/>
                                            </p:column>
                                        </p:row>
                                    </f:facet>
                                </p:panelGrid>
                                <p:messages id="gmMessages"/>
                            </div>
                        </h:form>
                    </p:layoutUnit>
                </p:layout>
        </ui:composition>
    </h:body>
</html>

现在客户端代码可以工作了,因为如果我只用一个 Hello 标头替换 graphicsMessage.xhtml 的代码,我就可以毫无问题地交换内容。emailTemplate 与graphicMessage.xhtml 几乎相同。为简单起见,我将每个页面都替换为一个通用的 Hello!文本(一次一个,所以一页有完整的内容,另一页有一个简单的 Hello 文本),它不起作用。如果我只用纯文本交换两者,它就可以工作。所以问题在于所有 JSF 组件的主要内容。我调试了生命周期,它永远不会超过第一阶段。

注意:我做的最后一件事是逐个撕下内容,直到它起作用,然后我将问题缩小到 p:ajax 标签。在布局中使用它们会导致生命周期中断。我需要该标签,以便可以根据数据表中选择的行填充属性。我还需要它来显示在选择一个菜单中选择的图像。有任何想法吗?我没有看到太多关于 PF ajax 标签的使用,我也看不到我做错了什么。如果我包含它并设置渲染属性,则此代码有效。

4

0 回答 0