+ Start a Discussion

Javascript and Visualforce Page problem


I am facing a very strange VF behaviour. I have a visualforce page button which has a save method.


It is a simple command button and all is well so far/


Now I have a requirement that I have to trigger a validation (server side validation) and if the validation is not true, a warning message should popup to the user.


This method validates the code and sets isRenderedConfirm=true.


on Visualforce page I have a small snipet of javascipt


  <apex:commandButton value="Save" action="{!ValidateBeforeSave1}" />

<apex:actionFunction action="{!save}" rerender="error" name="saveFuncion"/>



                if('{!isRenderedConfirm}' == 'true')
                       var cnf=confirm(' Proceed?');





public PageReference ValidateBeforeSave1(){
        System.debug('in getValidateBeforeSave method: '+obj);
        if(isDateCorrect > 0){
            //Pagereference pg=Save();
            //return pg;

        return null;        



But now the problem is, till confirm box all works fine, but after confirm message it does not enter Save method. The save method is not touched at all.


Please help.


Hi, I understand the problem you're describing, but I'm not trying to provide an answer here.


Instead, I'm climbing on a soapbox for just a moment, I hope you don't mind.



To my way of thinking this is one of those examples where you're really going out of your way to make your Salesforce instance behave in a way that just isn't the way "normal" salesforce works.   For example, if I edit an Opportunity and hit Save, it checks any validation rules I've defined, and then saves it.  If there are errors, they are reported back, otherwise it's just done.  There's no "Proceed" intermediate step, if the user didn't want to proceed, they shouldn't have hit Save! :-)



But seriously, I'd skip the popup, and just have the Save method check your validation.  If it's valid, just go and do the save.  If not, display the problem in the ApexMessages block.  That's consistent with the rest of Salesforce's behaviors.


If you *really* need a proceed button, instead of doing a Javascript style Confirm box, why not conditionally render a "Validate" button to display if isDateCorrect is False or Null, and render a "Proceed" command button (which calls Save) if isDateCorrect is true.   So, you're just showing two different Command buttons.


Best, Steve.