All (visual) components have attributes such as onclick
, onmouseover
, onmouseout
, onfocus
, etc. that allow you to run Javascript code when a specific event is fired. For example:
<h:inputText ... onclick="alert('Click');"/>
will display a "Click" message when the user clicks in the input field.
Regarding your requirements, you can try something like that:
<h:commandButton ... styleClass="aCssClass" onmouseover="this.className='anotherCssClass'" onmouseout="this.className='aCssClass'"/>
In others words, the button will be displayed regarding the CSS class aCssClass
, and when the cursor is entering the button, it will use the anotherCssClass
class. Of course, you can also define a CSS class for the onclick
event...
Just for information: If you want to execute an Ajax call to your server regarding a specific event, which may not be what you are looking for exactly, you can use the <a4j:support/>
tag:
<h:inputText ...>
<a4j:support event="onclick" actionListener="#{myBean.doSomething}"/>
</h:inputText>