0

I have image and would like to call a method that is store in bean. I was thinking of

<h:graphicImage value="DisplayImage?id=1&amp;stuff=photo&amp;mainID=main" 
 onclick="
          alert('clicked me 1');
          #{PersonalInformationDataBean.doSaveImage()};
          alert('clicked me 2');
         " styleClass="modal"/>

I was expecting #{PersonalInformationDataBean.doSaveImage()}; to work, however this is not working. I am only getting alert as clicked me 1

Any idea how to get this done?

Update 1

Forget to update that I am doing this in JSP Page.

Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276

2 Answers2

1

how bout something like this

<h:graphicImage value="DisplayImage?id=1&amp;stuff=photo&amp;mainID=main" 
 onclick="$('#myFormID\\:myButtonID').click();" styleClass="modal"/>
<h:commandButton id="myButtonID" action="#{PersonalInformationDataBean.doSaveImage()}" style="display:none">
    <f:ajax/>
</h:commandButton>

you might have to play a bit with the jquery selector $('#myFormID\\:myButtonID') or $('#myButtonID')

OR

<h:commandLink>
    <f:ajax event="action" listener="#{PersonalInformationDataBean.doSaveImage()}"/>
    <h:graphicImage value="DisplayImage?id=1&amp;stuff=photo&amp;mainID=main" 
    styleClass="modal"/>
</h:commandLink>
Daniel
  • 36,833
  • 10
  • 119
  • 200
0

I'm assuming that `#{PersonalInformationDataBean.doSaveImage()}; is a function which you've defined in your server and is not a javascript object method. Correct me if I'm wrong.

The problem here is you're trying to access server side methods from client side javascript. Since HTTP is a stateless protocol, you need some intermediate technology to access those methods.

DWR is a powerful tool that will allow you to achieve exactly this. Check out http://directwebremoting.org/dwr/documentation/index.html .I've used this countless times and it never fails.

afrin216
  • 2,295
  • 1
  • 14
  • 17
  • While you're right about the concrete cause of OP's fail, I disagree using DWR for this. JSF has its own tags and facilities to achieve the desired functional requirement. – BalusC Jul 28 '12 at 14:27
  • thanks... any link from where I can get the code (for idea how it is working) – Fahim Parkar Jul 28 '12 at 14:28
  • @BalusC : Could you please tell me the same... – Fahim Parkar Jul 28 '12 at 14:28
  • @BalusC : Can you elaborate on that? Even I'm curious to know the solution which you have in mind. Are you talking about calling JSF Handler functions? – afrin216 Jul 28 '12 at 15:07