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:
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
You can use <p:remoteCommand>
to generate a JavaScript function which invokes a JSF command action.
<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();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.