从 JavaScript 调用托管 Bean 方法 [英] Calling Managed Bean Method From JavaScript
问题描述
我有一个应用程序,其中包含定义了多个部分的客户端图像映射.我需要从 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 访问该元素并调用其 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屋!