how to call a managed bean when a button in clicked

hi,

I have a jsf page with one button of graphic image.how can i call managed bean when that is clicked.

[117 byte] By [javamnr948a] at [2007-11-27 10:49:16]
# 1

Use the action attribute.

<h:commandButton image="image.gif" action="#{myBean.action}" />

BalusCa at 2007-7-29 11:18:06 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

I am having graphic image as a button.if I write onclick option then how can I call the bean from the script code

javamnr948a at 2007-7-29 11:18:06 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Create a h:commandButton and hide it using CSS display: none; and then in the onclick of the image you can invoke the hidden commandButton using Javascript: document.getElementById('formId:buttonId').click().

But I recommend you to gently use the h:commandButton with the image.

BalusCa at 2007-7-29 11:18:06 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

BalusC,

It seems to me that the following is more straightforward, but perhaps there is some gotcha I am not aware of. Use a commandButton along with the image and an onclick handler. Then the JavaScript runs and the form is submitted afterwards. It only gets tricky if he needs to conditionally submit the form, it which case he needs to swallow the mouse click event.

RaymondDeCampoa at 2007-7-29 11:18:06 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

True =)

But as far I understood, he want to use the following construction:<h:graphicImage value="image.gif" onclick="submitFormSomehow();" />

, so I was suggesting him to use h:commandButton with an image instead. He also didn't mention about some Javascript requirements, so an onclick is also not needed.

BalusCa at 2007-7-29 11:18:06 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...