从JavaScript调用托管Bean方法 [英] Calling Managed Bean Method From JavaScript

查看:95
本文介绍了从JavaScript调用托管Bean方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有定义了多个部分的客户端图像映射的应用程序.我需要从<area> onclick属性调用托管Bean中的方法.

I have an application with a client-side image map with multiple sections defined. I need to call a method in the Managed Bean from the <area> onclick attribute.

这不起作用:

<area id="ReviewPerson" shape="rect" coords="3, 21, 164, 37" href="#" 
    onclick="#{personBean.method}" alt="Review Person" id="reviewPersonArea"
    title="Review Person" />

由于我的手被绑在了图像地图上(不幸的是),如何在<area>标记内调用托管bean方法?

Since my hands are tied on the image map (unfortunately), how can I call a managed bean method from within the <area> tag?

推荐答案

您有一些选择.如果您使用的是JSF 2.0,则可以围绕这些区域标签构建复合组件.

You have a few options. If you are using JSF 2.0 you can build a composite component around these area tags.

最简单的方法是调用一个隐藏的JSF输入按钮.

The easiest way however would be to invoke a hidden JSF input button.

<h:commandButton id="hdnBtn" actionListener="#{personBean.method}" style="display: none;" />

这将呈现为页面上的input HTML元素,您可以从Javascript访问该HTML元素并调用其click事件.

This will render as an input HTML element on the page that you can access from Javascript and invoke its click event.

onclick="jQuery('#form:hdnBtn').click();"

这篇关于从JavaScript调用托管Bean方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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