This question already has an answer here:
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.
This doesn't work:
<area id="ReviewPerson" shape="rect" coords="3, 21, 164, 37" href="#"
onclick="#{personBean.method}" alt="Review Person" id="reviewPersonArea"
title="Review Person" />
Since my hands are tied on the image map (unfortunately), how can I call a managed bean method from within the <area>
tag?
You have a few options. If you are using JSF 2.0 you can build a composite component around these area tags.
The easiest way however would be to invoke a hidden JSF input button.
<h:commandButton id="hdnBtn" actionListener="#{personBean.method}" style="display: none;" />
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();"
来源:https://stackoverflow.com/questions/9619906/calling-managed-bean-method-from-javascript