Search code examples
jsfrichfacesmouseevent

richfaces how to detect mouse events


sorry if the answer to this is obvious but I couldn't find it.

How do I detect if the user has clicked, dragged etc. on an image (or other element)?

Thanks in advance!


Solution

  • There are several way of doing this:

    In HTML it would be something like:

    <img src="images/myImage.jpg" onclick="someJSFunc()"/>
    

    In the case of Richfaces you'd probably want to invoke some sort of server side logic through an Ajax request after your image has been clicked, so, the most appropriate thing would be:

    <img src="images/myImage.jpg">
     <a4j:support event="onclick" action="#{myBean.someActionMethod}" reRender="someComponent"/>
    </img>
    

    For more information of how to add Ajax behavior to standard HTML components tags with Richfaces see the a4j:support component description.