2013-05-12 94 views
0

我有一個問題,我不知道如何解決。我有一個表格,我用它來顯示數據並編輯數據。無法正確調用保存對象

<!-- 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>&nbsp; 

<!-- 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不叫。

+0

你跟蹤JavaScript執行在Firebug? – skuntsel 2013-05-12 16:59:34

+0

是的,有任何輸出。 – 2013-05-12 17:00:57

+0

好吧,據我瞭解,如果你手動點擊editdata按鈕,save方法不會被調用,對吧?那麼'bean.saveData'看起來怎麼樣? – dratewka 2013-05-12 18:19:49

回答

1

我覺得有缺失報價在jQuery選擇:

jQuery(button).closest("form").find("[id$='editdata']").click(); 
+0

好看! +1。 – skuntsel 2013-05-12 17:11:34

+0

我更新了JavaScript,但沒有任何更改。 – 2013-05-12 17:25:15

+0

好的,但你有沒有檢查選擇器實際上找到了按鈕? – dratewka 2013-05-12 17:27:05