I have javascript/jquery on a page that uses a variable from the controller that is transient. When the visualforce input field validation fails, it refreshes the page without going to the controller and the transient variable is then cleared causing a syntax error. Is there anyway to catch the validation after it fails to call the controller and repopulate the transient variable?


Not sure if this is what you are looking for, there is a way to identify if the page has errors You can use ApexPages.hasMessages() to check if there are errors

From this post You can also validate if there are errors using CSS : How to check that any error message is diplaying in visualforce page

function checkIt(){
    if (jQuery('.errorMsg').length > 0){
        // Error exists
        alert('There is an error on the page!');
        alert('No errors!');

<apex:commandButton reRender="none" oncomplete="checkIt();" value="Click me"/>

  • This isn't quite what I am looking for. I'm looking for a way to call a method in the controller after a validation has failed to repopulate the transient variable. Thanks though. – Kiet May 15 '14 at 21:45

I have found the answer, you can catch syntax errors in Javascript because it is an interpreted language. So using the "window.OnError" in Javascript, we are able to call a methods in the controller.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.