JSF按钮onclick事件调用bean方法

JSF按钮onclick事件调用bean方法,jsf,Jsf,在JSF2中,我需要在显示对话框之前准备好数据。在下面的代码中,方法“newAuto”是在ViewScope托管bean中定义的。单击按钮后,我想首先调用此方法,然后显示对话框 我尝试了很多方法,都失败了 谢谢 <h:commandButton type="button" value="Add Dialog" onclick="jsf.ajax.request(this, event, {execute: 'newAuto'}); autoDialog2.show(); retur

在JSF2中,我需要在显示对话框之前准备好数据。在下面的代码中,方法“newAuto”是在ViewScope托管bean中定义的。单击按钮后,我想首先调用此方法,然后显示对话框

我尝试了很多方法,都失败了

谢谢

<h:commandButton  type="button" value="Add Dialog"   onclick="jsf.ajax.request(this, event, {execute: 'newAuto'});  autoDialog2.show(); return false;" />

您应该使用
标记,然后使用其
onevent
属性

<h:commandButton value="Add Dialog" action="#{bean.newAuto}">
    <f:ajax onevent="function(data) { if (data.status == 'success') autoDialog2.show(); }" />
</h:commandButton>

也许您还想将
render=“someDialogId”
添加到
中,这样可以提前更新对话框的内容