簡體   English   中英

使用jQuery重新加載JSF數據表

[英]Reload a jsf datatable using jquery

我的數據表

<h:form>
   <h:dataTable value="#{testController.items}" var="item" border="0">
       <h:column>
           <h:outputText value="#{item.name}"/>
       </h:column>           
   </h:dataTable>
</h:form>

我正在使用模式來保存表單,該模式包含此命令按鈕

<p:commandButton styleclass="btn btn-primary" action="#{testController.create}" oncomplete="handleComplete(xhr, status, args)" />

handleComplete函數:

function handleComplete(xhr, status, args) {  
    if(args.validationFailed) {  
        alert("failed");
    }else{
        $('#test-modal').modal('hide');

          // Do something here to reload the datatable to add the newly created item

    }
}  

我正在使用jsf 2,我也導入了primefaces

您可以使用<p:remoteCommand>生成一個JavaScript函數,該函數調用JSF命令動作。

<h:form>
   <h:dataTable id="table" value="#{testController.items}" var="item" border="0">
       <h:column>
           <h:outputText value="#{item.name}"/>
       </h:column>           
   </h:dataTable>
   <p:remoteCommand name="updateTable" action="#{testController.update}" update="table" />
</h:form>

可以如下調用:

function handleComplete(xhr, status, args) {  
    if (args.validationFailed) {  
        alert("failed");
    } else {
        $('#test-modal').modal('hide');
        updateTable();
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM