The rich:jQuery component integrates the jQuery JavaScript library into your applications. This allows one to dynamically apply style and behavior to DOM elements as the result of JSF component rendering.
The selector attribute defines an object (or list of objects) against which the query attribute will be applied. The query attribute should be defined with valid JavaScript statements or jQuery api calls.
The jQuery javascript is also accessible via EL using the rich:jQuery EL function.
rich:jQuery can be used in these modes:
This example shows how to attach events to the mouseover/mouseout event on the DOM objects. The source below will show how to make them enlarged.
<!DOCTYPE html> <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich"> <style type="text/css"> .pic-normal { width: 120px; border: 2px solid #ACBECE; } .wrap1 { width: 190px; height: 130px; float: left; } </style> <br /> <a4j:outputPanel id="gallery"> <h:graphicImage value="/images/nature/pic1.jpg" alt="pic" /> <h:graphicImage value="/images/nature/pic2.jpg" alt="pic" /> <h:graphicImage value="/images/nature/pic3.jpg" alt="pic" /> <h:graphicImage value="/images/nature/pic4.jpg" alt="pic" /> <h:graphicImage value="/images/nature/pic5.jpg" alt="pic" /> <h:graphicImage value="/images/nature/pic6.jpg" alt="pic" /> <h:graphicImage value="/images/nature/pic7.jpg" alt="pic" /> <h:graphicImage value="/images/nature/pic8.jpg" alt="pic" /> <h:graphicImage value="/images/nature/pic9.jpg" alt="pic" /> </a4j:outputPanel> <br style="clear: both" /> <rich:jQuery selector="#gallery img" query="addClass('pic-normal')" /> <rich:jQuery selector="#gallery img" query="wrap('<div class=\'wrap1\'></div>')" /> <rich:jQuery selector="#gallery img" event="mouseover" query="jQuery(this).stop().animate({width:'180px'})" /> <rich:jQuery selector="#gallery img" event="mouseout" query="jQuery(this).stop().animate({width:'120px'})" /> </ui:composition>