简体   繁体   English

使用jQuery重新加载JSF数据表

[英]Reload a jsf datatable using jquery

my data table 我的数据表

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

i'm using a modal to hold my form, the modal contains this commandbutton 我正在使用模式来保存表单,该模式包含此命令按钮

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

handleComplete function: 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

    }
}  

im using jsf 2 and i also imported primefaces 我正在使用jsf 2,我也导入了primefaces

You can use <p:remoteCommand> to generate a JavaScript function which invokes a JSF command action. 您可以使用<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>

This can be invoked as follows: 可以如下调用:

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