我有这样的代码
<h:commandLink>
<f:ajax execute="@this"
render=":organizerTable :organizerData :delete @form"
onevent="deleteOrganizer"
listener="#{organizercontroller.deletePossible}"/>
<span id="minus" class="add-on glyphicon glyphicon-minus" aria-hidden="true"></span>
</h:commandLink>
当我单击减号时,ajax标记的侦听器应该在onevent
之前执行。通常情况下是相反的。
我试过了:
function deleteOrganizer(data) {
var status = data.status;
if (status === 'complete') {
if (#{organizercontroller.canDelete}) {
alert("Value: " + #{organizercontroller.canDelete});
window.location.href = "#id_delete_popup";
}
else {
alert("false");
}
}
}
现在,侦听器方法将在我的JavaScript函数之前执行,但在#{organizercontroller.deletePossible}
中,我改变了canDelete
的值,当我读取它时,这个值不正确。
我该如何解决这个问题?
更新:用status === 'success'
也不行
我似乎找不到在ajax调用中添加回调参数的链接/帖子,而不使用PrimeFaces或OmniFaces ajax
不过你也可以更新页面中包含javascript函数的部分在ajax调用中更新并包含/返回EL
<h:commandLink>
<f:ajax execute="@this"
render=":organizerTable :organizerData :delete @form myCallback"
onevent="deleteOrganizer"
listener="#{organizercontroller.deletePossible}"/>
<span id="minus" class="add-on glyphicon glyphicon-minus" aria-hidden="true"></span>
</h:commandLink>
<ui:fragment id="myCallback">
function myFunction() {
return #{organizercontroller.deletePossible}
}
</ui:fragment>
并在ajax响应处理程序
中调用该函数function deleteOrganizer(data) {
var status = data.status;
if (status === 'complete') {
if (myFunction()) {
alert("Value: " + myFunction());
window.location.href = "#id_delete_popup";
}
else {
alert("false");
}
}
}