我有一个 DataTable,我想做实例行选择。单击一行后,将出现一个对话框,在 PanelGrid 中显示记录详细信息。我面临的问题是 Dialog 和 PanelGrid 没有呈现。当我从浏览器查看源代码时,它找不到元素。在 Apache 日志文件中,它有这个错误“javax.faces.FacesException:在视图中找不到标识符为“frmMain:strMaint”的组件。” frmMain 是 HTML 表单的 ID,strMaint 是 PanelGrid 的 ID。
下面是 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:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>PROFIT V10</title>
<h:outputStylesheet name="styles.css" library="css" />
</h:head>
<h:body>
<h:form id="frmMain">
<p:panel styleClass="layout-panel"
style="width: 98%; margin-left: auto; margin-right: auto; margin-top: 15px;">
<h2>Store Search</h2>
<p:focus context="pnlStoreSearchCriteria" />
<h:panelGrid id="pnlStoreSearchCriteria" columns="2" styleClass="panel-search">
<h:outputText value="Company" />
<p:selectOneMenu id="coySub" value="#{storeSearchBean.coySub}" effect="">
<f:selectItems value="#{storeSearchBean.coysubmsts}" var="coysub"
itemValue="#{coysub.coy_sub}"
itemLabel="#{coysub.coy_sub} - #{coysub.coy_sub_name}" />
</p:selectOneMenu>
<h:outputText value="Business Unit" />
<p:selectOneMenu id="storeCat" value="#{storeSearchBean.storeCat}">
<f:selectItem itemLabel="" itemValue="" />
<f:selectItems value="#{storeSearchBean.strcatmsts}" var="strcatmst"
itemValue="#{strcatmst.category}"
itemLabel="#{strcatmst.category} - #{strcatmst.category_name}" />
</p:selectOneMenu>
<h:outputLabel for="store" value="Store" />
<p:autoComplete id="store" value="#{storeSearchBean.store}" maxResults="10" maxlength="4"
completeMethod="#{storeSearchBean.populateStoreAutoComplete}" size="4" />
<h:outputLabel for="storeName" value="Store Name" />
<p:autoComplete id="storeName" maxlength="30" size="50"
value="#{storeSearchBean.storeName}" maxResults="10"
completeMethod="#{storeSearchBean.populateaStoreNameAutoComplete}" />
<f:facet name="footer">
<h:panelGroup id="pnlgrpButtonSearch">
<p:commandButton id="btnReset" type="reset" value="Reset"
action="#{storeSearchBean.doReset}" />
<p:commandButton id="btnSearch" type="submit" value="Search"
action="#{storeSearchBean.doSearch}"
update="pnlStoreSearchResult" />
</h:panelGroup>
</f:facet>
</h:panelGrid>
<p:separator />
<p:outputPanel id="pnlStoreSearchResult">
<p:dataTable id="tblStoreSearchResult" value="#{storeSearchBean.stores}" var="store"
emptyMessage="No data to display" paginator="true" rows="10"
paginatorPosition="bottom" draggableColumns="true" editable="true"
selection="#{storeSearchBean.selectedStore}" selectionMode="single">
<!--
<p:ajax event="rowSelect" listener="#{storeSearchBean.onRowSelect}" update="frmMain:strMaint"
oncomplete="strmstDialog.show()" />
<p:ajax event="rowUnselect" listener="#{storeSearchBean.onRowUnselect}" />
-->
<p:column sortBy="#{store.store_coy_sub}" headerText="Company">
<h:outputText value="#{store.store_coy_sub}" />
</p:column>
<p:column sortBy="#{store.store_category}" headerText="Business Unit">
<h:outputText value="#{store.store_category}" />
</p:column>
<p:column sortBy="#{store.store}" headerText="Store">
<h:outputText value="#{store.store}" />
</p:column>
<p:column sortBy="#{store.store_name}" headerText="Store Name">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{store.store_name}" />
</f:facet>
<f:facet name="input">
<h:inputText value="#{store.store_name}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column sortBy="#{store.store_type}" headerText="Type">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{store.store_type}" />
</f:facet>
<f:facet name="input">
<h:selectOneMenu value="#{store.store_type}">
<f:selectItem itemValue="W" itemLabel="W" />
<f:selectItem itemValue="S" itemLabel="S" />
</h:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column sortBy="#{store.store_del_cd}" headerText="Deleted">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{store.store_del_cd}" />
</f:facet>
<f:facet name="input">
<h:selectOneMenu value="#{store.store_del_cd}">
<f:selectItem itemValue="Y" itemLabel="Y" />
<f:selectItem itemValue="N" itemLabel="N" />
</h:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<p:rowEditor />
</p:column>
</p:dataTable>
<p:dialog id="dlgMaint" header="Strmst Maintenance" widgetVar="strmstDialog" resizable="false"
modal="true" showEffect="fade" hideEffect="fade">
<h:panelGrid id="strMaint" columns="2">
<h:outputText value="#{storeSearchBean.selectedStore.store}" />
<h:outputText value="#{storeSearchBean.selectedStore.store_name}" />
</h:panelGrid>
</p:dialog>
</p:outputPanel>
</p:panel>
<div id="copyright">Copyright © 2012 QR Retail Automation (ASIA) Sdn. Bhd. All rights reservered.</div>
</h:form>
</h:body>
</html>
当我评论这两个<p:ajax /> component
时, Dialog 和 PanelGrid 在浏览器中呈现正常。
我的环境如下:
- NetBeans 7.1.2
- PrimeFaces 3.3.1(我也试过 3.2 但还是一样)
- JDK 1.6.0.33
- Apache Tomcat 7(也尝试过 Glassfish3,但还是一样)
谢谢。