我有一个问题,我不知道如何解决。我有一个表格,我用它来显示数据并编辑数据。无法正确调用保存对象
<!-- 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;
}
}
});
}
但检查服务器多头数据后的Java方法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
不叫。
你跟踪JavaScript执行在Firebug? – skuntsel 2013-05-12 16:59:34
是的,有任何输出。 – 2013-05-12 17:00:57
好吧,据我了解,如果你手动点击editdata按钮,save方法不会被调用,对吧?那么'bean.saveData'看起来怎么样? – dratewka 2013-05-12 18:19:49