在图像onClick事件上调用bean方法 [英] calling bean method on image onClick event
本文介绍了在图像onClick事件上调用bean方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有图像,并且想调用一个存储在bean中的方法。我在考虑
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&stuff=photo&mainID=main"
onclick="
alert('clicked me 1');
#{PersonalInformationDataBean.doSaveImage()};
alert('clicked me 2');
" styleClass="modal"/>
我期待#{PersonalInformationDataBean.doSaveImage()};
工作,但这不起作用。我只是因为点击了我1
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?
忘记更新我在 JSP Page 中执行此操作。
Forget to update that I am doing this in JSP Page.
推荐答案
这是怎么回事
how bout something like this
<h:graphicImage value="DisplayImage?id=1&stuff=photo&mainID=main"
onclick="$('#myFormID\\:myButtonID').click();" styleClass="modal"/>
<h:commandButton id="myButtonID" action="#{PersonalInformationDataBean.doSaveImage()}" style="display:none">
<f:ajax/>
</h:commandButton>
您可能需要使用jquery选择器 $('# myFormID \\:myButtonID')
或 $('#myButtonID')
you might have to play a bit with the jquery selector $('#myFormID\\:myButtonID')
or $('#myButtonID')
OR
OR
<h:commandLink>
<f:ajax event="action" listener="#{PersonalInformationDataBean.doSaveImage()}"/>
<h:graphicImage value="DisplayImage?id=1&stuff=photo&mainID=main"
styleClass="modal"/>
</h:commandLink>
这篇关于在图像onClick事件上调用bean方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文