2015-10-06 88 views
1

我在這裏看到了這個問題很多次,但它對我沒有幫助。javax.faces.FacesException:當啓用選擇或者定義rowKey屬性時,DataModel必須實現org.primefaces.model.SelectableDataModel

我有第一個ID爲的數據表:servers,我可以做一個右鍵點擊並出現一個contextMenu。我可以點擊Show Process,然後我得到第二個dataTable,ID爲:processes。 但現在的問題是,而不是顯示新的DataTable我得到的,

javax.faces.FacesException:當選擇啓用或 您需要定義rowKey DataModel中必須實現 org.primefaces.model.SelectableDataModel屬性

但我不得不在這兩個dataTable

定義rowKey我有這樣的代碼:

<h:form id="form" onkeypress="return event.keyCode != 13"> 
    <!-- <p:messages id="msgs" /> --> 
    <p:growl id="msgs" showDetail="true" sticky="true" autoUpdate="true" /> 
    <!-- Context menu for servers table. --> 
    <p:contextMenu for="servers"> 
     <p:menuitem value="Show processes" update="form" icon="ui-icon-search" actionListener="#{homeBean.findLSRunningProcesses}" styleClass="homeIE"/> 
    </p:contextMenu> 
    <!-- Context menu for processes table. --> 
    <p:contextMenu for="processes"> 
     <p:menuitem styleClass="homeIE" update="@form" value="Stop Process" icon="ui-icon-stop"  oncomplete="stopDialog.show()"/> 
    </p:contextMenu> 

    <!-- Servers table. --> 
    <p:dataTable id="servers" var="server" value="#{homeBean.serverList}" paginator="true" rows="10" 
        paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}" 
        rowsPerPageTemplate="5,10,15" widgetVar="serversTable" rowKey="#{server.adminFQDN}" 
        selection="#{homeBean.selectedLogicalServer}" selectionMode="single" emptyMessage="No servers found with given criteria"> 

     <f:facet name="header"> 
      <h:outputText value="Servers" /> 
     </f:facet> 
     <p:column filterBy="#{server.ASSETID}" filterMatchMode="contains" sortBy="#{server.ASSETID}" headerText="ASSETID"> 
      <h:outputText value="#{server.ASSETID}" /> 
     </p:column> 
     <p:column filterBy="#{server.adminFQDN}" filterStyle="width:240px;" filterMatchMode="contains" sortBy="#{server.adminFQDN}" headerText="FQDN"> 
      <h:outputText value="#{server.adminFQDN}" /> 
     </p:column> 
     <p:column filterBy="#{server.adminIP}" filterMatchMode="contains" sortBy="#{server.adminIP}" headerText="Admin IP"> 
      <h:outputText value="#{server.adminIP}" /> 
     </p:column> 
     <p:column filterBy="#{server.delivery}" filterMatchMode="exact" sortBy="#{server.delivery}" headerText="Delivery"> 
      <f:facet name="filter"> 
       <p:selectOneMenu onchange="PF('serversTable').filter()"> 
        <f:selectItem itemLabel="Select One" itemValue="#{null}" noSelectionOption="false" /> 
        <f:selectItems label="#{homeBean.deliveries}" value="#{homeBean.deliveries}" /> 
       </p:selectOneMenu> 
      </f:facet> 
      <h:outputText value="#{server.delivery}" /> 
     </p:column> 
     <p:column filterBy="#{server.environment}" filterMatchMode="exact" sortBy="#{server.environment}" headerText="Environment"> 
      <f:facet name="filter"> 
       <p:selectOneMenu onchange="PF('serversTable').filter()"> 
        <f:selectItem itemLabel="Select One" noSelectionOption="true" itemValue="#{null}"/> 
        <f:selectItems value="#{homeBean.environments}" /> 
       </p:selectOneMenu> 
      </f:facet> 
      <h:outputText value="#{server.environment}" /> 
     </p:column> 
     <p:column filterBy="#{server.function}" filterMatchMode="exact" sortBy="#{server.function}" headerText="Function"> 
      <f:facet name="filter"> 
       <p:selectOneMenu onchange="PF('serversTable').filter()"> 
        <f:selectItem itemLabel="Select One" itemValue="#{null}" noSelectionOption="true" /> 
        <f:selectItems value="#{homeBean.functions}" /> 
       </p:selectOneMenu> 
      </f:facet> 
      <h:outputText value="#{server.function}" /> 
     </p:column> 
     <p:column filterBy="#{server.osVersion}" filterMatchMode="contains" sortBy="#{server.osVersion}" headerText="OS VERSION"> 
      <h:outputText value="#{server.osVersion}" /> 
     </p:column> 
     <p:column filterBy="#{server.os}" filterMatchMode="contains" sortBy="#{server.os}" headerText="OS"> 
      <h:outputText value="#{server.os}" /> 
     </p:column> 


    </p:dataTable> 

    <!-- Panel containing processes tables. --> 
    <p:panelGrid id="serverProcesses" styleClass="group-user-selection-table" rendered="#{homeBean.showSelectionPanel}"> 
     <f:facet name="header"> 
      <p:row> 
       <p:column> 
        <h:outputText value="#{homeBean.selectedLogicalServer.adminFQDN}" /> 
       </p:column> 
      </p:row> 
     </f:facet> 

     <p:row> 

      <!--Processes table. --> 
      <p:column> 
       <p:dataTable id="processes" var="process" value="#{homeBean.processesList}" filteredValue="#{homeBean.filteredProcesses}" 
          selection="#{homeBean.selectedProcesses}" paginator="true" rows="15" rowKey="#{process.owner}" 
          paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}" 
          rowsPerPageTemplate="15,20,25,30" selectionMode="single" emptyMessage="No processses found with given criteria"> 
        <f:facet name="header"> 
         <h:outputText value="Processes" /> 
        </f:facet> 
        <p:column name="owner" filterBy="#{process.owner}" filterMatchMode="contains" sortBy="#{process.owner}" headerText="#{homeBean.selectedLogicalServer.os eq 'Windows' ? 'DESCRIPTION' : 'OWNER'}"> 
         <h:outputText value="#{process.owner}" /> 
        </p:column> 
        <p:column name="pid" filterBy="#{process.pid}" filterMatchMode="exact" sortBy="#{process.owner}" headerText="PID"> 
         <h:outputText value="#{process.pid}" /> 
        </p:column> 
        <p:column name="ppid" filterBy="#{process.ppid}" filterMatchMode="exact" sortBy="#{process.ppid}" headerText="#{homeBean.selectedLogicalServer.os eq 'Windows' ? 'TYPE' : 'PPID'}"> 
         <h:outputText value="#{process.ppid}" /> 
        </p:column> 
        <p:column name="c" filterBy="#{process.c}" filterMatchMode="exact" sortBy="#{process.c}" headerText="#{homeBean.selectedLogicalServer.os eq 'Windows' ? 'STATE' : 'C'}"> 
         <h:outputText value="#{process.c}" /> 
        </p:column> 
        <p:column name="stime" filterBy="#{process.stime}" filterMatchMode="contains" sortBy="#{process.stime}" headerText="STIME" rendered="#{!(homeBean.selectedLogicalServer.os eq 'Windows')}"> 
         <h:outputText value="#{process.stime}" /> 
        </p:column> 
        <p:column name="tty" filterBy="#{process.tty}" filterMatchMode="contains" sortBy="#{process.tty}" headerText="TTY" rendered="#{!(homeBean.selectedLogicalServer.os eq 'Windows')}"> 
         <h:outputText value="#{process.tty}" /> 
        </p:column> 
        <p:column name="time" filterBy="#{process.time}" filterMatchMode="contains" sortBy="#{process.time}" headerText="TIME" rendered="#{!(homeBean.selectedLogicalServer.os eq 'Windows')}"> 
         <h:outputText value="#{process.time}" /> 
        </p:column> 
        <p:column name="cmd" filterBy="#{process.cmd}" filterMatchMode="contains" sortBy="#{process.cmd}" headerText="#{homeBean.selectedLogicalServer.os eq 'Windows' ? 'NAME' : 'CMD'}"> 
         <h:outputText value="#{process.cmd}" /> 
        </p:column> 
       </p:dataTable> 
      </p:column> 
     </p:row> 
    </p:panelGrid> 
    <p:dialog header="Stop Process" widgetVar="stopDialog" minHeight="40" styleClass="dialogPosition"> 
     <h:outputText value="You are going to stop the process "/> 
     <h:outputText value="#{homeBean.selectedProcesses.cmd}"/> 
     <h:outputText value="with PID"/> 
     <h:outputText value="#{homeBean.selectedProcesses.pid}"/> 
     <br /><br /><br /><br /> 
     <p:commandButton value="Yes" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" style="float:left" onclick="stopDialog2.show();stopDialog.hide();" actionListener="#{homeBean.attrListener}"> 
      <f:attribute name="processPID" value="#{process.pid}" /> 
     </p:commandButton> 
     <p:commandButton value="NO" onclick="stopDialog.hide()" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" style="float:right"/> 
    </p:dialog> 
    <p:dialog header="Stop Process" widgetVar="stopDialog2" minHeight="40" styleClass="dialogPosition"> 
     <h:outputText value="You are going to send an email to:"/> 
     <br /> 
     <h:outputText value="#{homeBean.email}"/> 
     <br /><br /><br /> 
     <p:commandLink value="Yes" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" style="float:left" update="form" action="#{homeBean.stopProcess}" oncomplete="stopDialog2.hide();"/> 
     <p:commandButton value="NO" onclick="stopDialog2.hide()" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" style="float:right"/> 
    </p:dialog> 
</h:form> 
+0

這是爲欺騙可以接受嗎? http://stackoverflow.com/questions/13342524/datamodel-must-implement-org-primefaces-model-selectabledatamodel-when-selection/ – BalusC

+0

rowKey不會爲空。所以我需要在Process類中實現SelectableDataModel? @BalusC 我不能這樣做'import org.primefaces.model.SelectableDataModel' –

+0

當我使用Primefaces 4.0版本並且當我切換到版本5.0時停止工作。 @BalusC –

回答

相關問題