[英]Primefaces Ajax updated form does not trigger commandButton action
我有一個表單不觸發其commandButton操作方法的問題。 當我提交沒有事先更新的表單(不在樹中選擇任何節點)時,該方法將觸發正常。
表單被Ajax更新后,commandButton將不再調用其動作。
這是JSF代碼:
<p:layoutUnit position="center">
<p:tree orientation="horizontal" value="#{flightTypeController.tree}" var="node"
selectionMode="single" selection="#{flightTypeController.selectedNode}">
<p:ajax event="select" listener="#{flightTypeController.onNodeSelect}" update=":typesTree"/>
<p:treeNode>
<h:outputText value="#{node.name}"/>
</p:treeNode>
</p:tree>
<h:form id="typesTree">
<p:inputText disabled="true" id="outputParent" value="#{flightTypeController.selectedOne.name}"/>
<p:inputText id="outputName" value="#{flightTypeController.current.name}"/>
<p:commandButton ajax="false" icon="ui-icon-disk" value="#{bundle.general_create}" action="#{flightTypeController.create()}"/>
</h:form>
</p:layoutUnit>
和Java偵聽器:
public void onNodeSelect(final NodeSelectEvent event) {
final Object res = event.getTreeNode().getData();
if (res instanceof FlightType) {
selectedOne = (FlightType) res;
} else {
selectedOne = null;
}
}
我已經檢查過BalusC的聖經和JS Fix,但是沒有成功。
我經常看到類似的行為(必須找到解決方法),所以我可能誤解了一些基本知識。
哦,是的,我多次檢查:代碼中沒有嵌套的表單。
您發現的JS修補程序鈎在jsf.ajax.addOnEvent
,該方法僅由<f:ajax>
觸發,而不是由在jsf.ajax.addOnEvent
使用jQuery的PrimeFaces組件觸發。
為了也涵蓋PrimeFaces ajax請求,請獲取當前版本的JS修復程序 (我最近更新了該帖子),並添加以下內容以將該修復程序也應用於jQuery ajax請求:
$(document).ajaxComplete(function(event, xhr, options) {
if (typeof xhr.responseXML != 'undefined') { // It's undefined when plain $.ajax(), $.get(), etc is used instead of PrimeFaces ajax.
fixViewState(xhr.responseXML);
}
}
免責聲明:我沒有嘗試過您的特定用例。 但是,從理論上講,它應該可以解決您的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.