2011-08-10 82 views
3

我目前正在使用PrimeFaces數據表,並且在用戶添加新數據表後立即嘗試追加新的數據表。服務器端,一切正常 - 數據被保存到數據庫和硬盤。我希望在成功的請求之後看到部分頁面更新,而我似乎無法使其工作。這是我的XHTML代碼:PrimeFaces dataTable在Ajax請求後不會更新

<div class="content"> 
     <div id="mainContent"> 

      <div class="topNav"> 
       <h:form id="navForm"> 
        <p:commandButton value="Upload"/> 
        <p:commandButton value="New Folder" onclick="createDlg.show();" /> 
        <p:commandButton value="Delete Folder" action="#" /> 
       </h:form> 
      </div> 

      <div id="filePanel"> 
       <h:form id="dataTable" prependId="false">  
        <p:dialog header="Create" widgetVar="createDlg" modal="true" height="200"> 

         <p:panel header="New Folder"> 
          <h:panelGrid columns="2"> 
           <h:outputLabel value="Name:" for="txt_name"></h:outputLabel> 
           <p:inputText id="txt_name" value="#{directoryController.newDir.name}" required="true" /> 
           <p:commandButton value="Create" actionListener="#{directoryController.createNew}" update="dGrid" oncomplete="createDlg.hide();"/> 
           <p:ajaxStatus style="width:16px; height:16px;"> 
            <f:facet name="start"> 
             <h:outputText value="Saving..." /> 
            </f:facet> 
            <f:facet name=""> 
             <h:outputText value="Complete." /> 
            </f:facet> 
           </p:ajaxStatus> 
          </h:panelGrid> 
         </p:panel> 

        </p:dialog> 
        <p:dataTable id="dGrid" value="#{directoryController.itemsByOwner}" var="dir"> 
         <p:column selectionMode="multiple"/> 
         <p:column sortBy="#{dir.name}">         
          <f:facet name="header"> 
           File Name 
          </f:facet> 
          <h:outputText value="#{dir.name}" /> 
         </p:column> 
         <p:column> 
          <f:facet name="header"> 
           File Size 
          </f:facet> 
         </p:column> 
        </p:dataTable>         
       </h:form>      
      </div> 
     </div> 
    </div> 

最後,這裏是我的支持bean。

public String createNew(){ 
    newDir.setDateCreated(new Date()); 
    newDir.setDateModified(new Date()); 
    newDir.setId(BigDecimal.ZERO); 
    newDir.setLocation(ROOT_DIRECTORY + currentUser.getUsername() + "/"); 
    newDir.setFilesCollection(f); 
    newDir.setDescription(""); 
    newDir.setOwner(currentUser); 
    current = newDir; 
    create(); 
    persistDirectoryFromObject(newDir); 
    newDir = new Directory(); 
    RequestContext.getCurrentInstance().addPartialUpdateTarget("dGrid"); 


    return null; 
} 

回答

1

如果您正在使用3.0.M4你可以這樣做:

... ...

<p:outputPanel autoUpdate="true"> 

       <p:dataTable id="dGrid" value="#{directoryController.itemsByOwner}" var="dir"> 
        <p:column selectionMode="multiple"/> 
        <p:column sortBy="#{dir.name}">         
         <f:facet name="header"> 
          File Name 
         </f:facet> 
         <h:outputText value="#{dir.name}" /> 
        </p:column> 
        <p:column> 
         <f:facet name="header"> 
          File Size 
         </f:facet> 
        </p:column> 
       </p:dataTable>  
</p:outputPanel> 

,或者你可以簡單地說:

<p:commandButton value="Create" action="#{directoryController.createNew}" oncomplete="createDlg.hide();" ajax="false" />