facesContext.validationFailed
needs to be in a EL expression, i.e. #{facesContext.validationFailed}
; otherwise it is a javascript variable.
However, I think that still won't give you the desired effect as the onclick script would be executed before submitting the form.