在jquery内调用一个支持bean方法 [英] Calling a backing bean method from within jquery

查看:168
本文介绍了在jquery内调用一个支持bean方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个JSF文件中工作,我有一个javascript函数,一些jquery涉及

我设计了一个带有两个按钮的对话框:1)确定和2)取消。
我已经设计了这样一个方式,取消按钮将中止这个过程,
,没有问题。

但是,我想要完成的是,当用户按OK,然后程序
应该调用支持bean(java bean)方法,
有没有人能够管理这个?



解决方案

为此,您需要让jQuery触发JSF的HTML表示上的点击事件< H:的commandButton> 。你可以根据需要隐藏窗体/按钮CSS display:none



例如

 < h:form id =formIdstyle =display:none> 
...
< h:commandButton id =buttonId... />
< / h:form>

  $( [ID = 'formId:buttonId'])点击(); 

但这有点笨拙。为什么不直接使用< h:commandButton> 作为确定按钮?此外,为JSF重新开发基于jQuery的组件可能会长期成为一种痛苦。您是否查看过 PrimeFaces ,以节省头痛和样板代码?它已经在封面下使用jQuery和jQuery UI。参见例如 < p:confirmDialog> showcase



另见:




Im working on a JSF file where I have a javascript function, and some jquery involved in this. I have designed a dialog with two button: 1) Ok and 2) Cancel. I have designed it in such a way that the Cancel button will abort the process, and there is no problem with that.
But, what I want to accomplish is that when the user presses Ok then the program should call a backing bean(java bean) method, Have anyone of you been able to manage this?

Thankful for all your help & tip

解决方案

To the point, you need to let jQuery trigger the click event on the HTML representation of a JSF <h:commandButton>. You could if necessary hide the form/button with CSS display:none.

E.g.

<h:form id="formId" style="display:none">
    ...
    <h:commandButton id="buttonId" ... />
</h:form>

with

$("[id='formId:buttonId']").click();

This is however somewhat clumsy. Why not just using the <h:commandButton> directly as "OK" button? Further, reinventing jQuery based components for JSF may in long term be a pain. Have you looked at for example PrimeFaces to save yourself the headache and boilerplate code? It is using jQuery and jQuery UI under the covers already. See also e.g. <p:confirmDialog> showcase.

See also:

这篇关于在jquery内调用一个支持bean方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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