JSF按钮的onclick事件调用bean方法 [英] JSF button onclick event call bean method

查看:62
本文介绍了JSF按钮的onclick事件调用bean方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在JSF 2中,我需要在显示对话框之前准备好数据.在下面的代码中,在viewscoped托管Bean中定义了方法"newAuto".单击按钮后,我要先调用此方法,然后显示对话框.

In the JSF 2, I need to get ready the data before showing a dialog. In the code below, the method 'newAuto' defined in the viewscoped managed bean. once button is clicked, I want to call this method first, then show dialog.

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

I tried lots of ways, all failed.

谢谢

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

推荐答案

您应该先使用<f:ajax>标记,然后使用其onevent属性.

You should be using the <f:ajax> tag and then its onevent attribute.

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

也许您还想将render="someDialogId"添加到<f:ajax>,这应该事先更新对话框的内容.

Maybe you also want to add render="someDialogId" to <f:ajax> which should update the dialog's content beforehand.

这篇关于JSF按钮的onclick事件调用bean方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆