Javascript 无法正确调用保存对象
我有一个我不知道如何解决的问题。我有一个用于显示数据和编辑数据的表单Javascript 无法正确调用保存对象,javascript,jsf,jsf-2,Javascript,Jsf,Jsf 2,我有一个我不知道如何解决的问题。我有一个用于显示数据和编辑数据的表单 <!-- 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}"/&g
<!-- 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>
问题在于:
<!-- 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
也不会被调用。我认为jQuery选择器中缺少引号:
jQuery(button).closest("form").find("[id$='editdata']").click();
您在Firebug中跟踪JavaScript执行了吗?是的,有任何输出。好的,据我所知,如果您手动单击editdata按钮,则不会调用save方法,对吗?那么
bean.saveData
看起来是什么样子呢?是的,由于某种原因,这种情况没有发生-Java方法工作不正常。您能从bean中提供一些代码吗?提交表单时,您的可编辑
属性必须为true
。也许您使用的是@RequestScoped
,而可编辑的
在每个请求中都变为false。好的,但是您是否检查过选择器是否确实找到了按钮?
<!-- 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>
jQuery(button).closest("form").find("[id$='editdata']").click();