Q:

Disable javascript onclick when JSF validation fails

I have simple JSF form and onclick event inside submit button (google analytics event tracking). Is it posible to somehow disable onclick event when jsf validation fails?

A:

That's not possible. The onclick is fired before the request is sent to server. You basically want to fire it after the response has returned with a successful outcome.
There are several ways to achieve this:

Perform validation in JavaScript instead (not recommended).
Send tracking request from inside JSF bean's action method instead.
Send tracking request inside a (conditionally rendered) <script> element on result page instead.

