我有一个我不知道如何解决的问题。我有一个表单,用于显示数据和编辑数据。
<!-- New Network button -->
<h:button style="position:absolute; bottom:25px; right:265px;" styleClass="buttonImage" value="New Network" outcome="/Network/NewNetwork.xhtml" rendered="#{not bean.editable}"/>
<!-- Edit button -->
<h:commandButton style="position:absolute; bottom:25px; right:150px;" styleClass="buttonImage" onclick="this.disabled = true;" value=" Edit Network " rendered="#{not bean.editable}" action="#{bean.editNetwork(true)}" >
<f:ajax render="@form" execute="@form"></f:ajax>
</h:commandButton>
<!-- Save Changes button -->
<h:commandButton style="position:absolute; bottom:25px; right:150px;" rendered="#{bean.editable}" styleClass="buttonImage" value=" Save Changes " onclick="editdialog(this, 'Do you want to save the changes?');
return false;" />
<!-- Hidden Edit button -->
<h:commandButton id="editdata" value="HiddenDelete" action="#{bean.saveData}" style="display:none">
<f:ajax render="@form" execute="@form"></f:ajax>
</h:commandButton>
<!-- Cancel button -->
<h:commandButton style="position:absolute; bottom:25px; right:65px;" styleClass="buttonImage" value=" Cancel " rendered="#{bean.editable}" action="#{bean.initDBData}" >
<f:ajax render="@form"></f:ajax>
</h:commandButton>
我使用此JavaScript来确认数据编辑:
// Question Dialog for edit panel
function editdialog(button, a) {
jQuery("<div />", {
text: a
}).dialog({
width: 600,
buttons: {
"Ok": function() {
jQuery(button).closest("form").find("[id$=editdata]").click();
//$("form\\:deleterow").click();
jQuery(this).dialog("close");
button.value = "Processing...";
button.disabled = true;
},
"Cancel": function(event) {
jQuery(this).dialog("close");
event.preventDefault();
button.value = "Save Changes";
button.disabled = false;
}
}
});
}
但在检查服务器longs数据后,JavaScript方法saveData
永远不会被JavaScript调用。我错过了一些我找不到的东西。你能帮我找到我的错误。
EDIT:
问题在于:
<!-- Hidden Edit button -->
<h:commandButton id="editdata" value="HiddenDelete" style="position:absolute; bottom:25px; right:650px;" action="#{bean.saveData}" rendered="#{bean.editable}">
<f:ajax render="@form" execute="@form"></f:ajax>
</h:commandButton>
单击按钮时,表单未提交,并且未调用Java方法savedata
。
答案 0 :(得分:1)
我认为jQuery选择器中缺少引号:
jQuery(button).closest("form").find("[id$='editdata']").click();