<h:commandButton image="foo.png"> generates HTML <input type="image" src="foo.png"> . The onmouseover attribute (like all on* attributes) should point to JavaScript functions. However, you put the image path equal. This will only result in a JavaScript error (which you would notice if using Firebug or WDT).
You need to write some JS that changes the src attribute of the image button accordingly:
onmouseover="this.src='/resources/images/mainbtn2.png'"
Remember to add onmouseout , which will change the image back.
Unrelated to a specific problem, it is common practice to use CSS background images for this. HTML <input type="image"> has a technically completely different purpose. It is an image map that allows you to send the coordinates of the mouse where you clicked on the image map. You are apparently not interested in this information because you are not using a static image.
eg.
<h:commandButton value="" styleClass="mybutton" />
which generates
<input type="submit" value="" class="mybutton" />
and add this CSS (run example)
.mybutton { margin: 2px; padding: 0; border: 0; width: 100px; height: 20px; background-image: url('foo.png'); cursor: pointer; overflow: visible; } .mybutton:hover { background-image: url('bar.png'); }
It is not only better to use / maintain, but also does not require JS support.
source share