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.
hi,
I have a jsf page with one button of graphic image.how can i call managed bean when that is clicked.
Use the action attribute.
<h:commandButton image="image.gif" action="#{myBean.action}" />
I am having graphic image as a button.if I write onclick option then how can I call the bean from the script code
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.
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.
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.