0

I am working on a controller and and a bunch of VF pages for a multi-step wizard and am having some issues with being able to click a button before the page is fully loaded. If I click the command button before the page is fully loaded, the browser redirects to new page but the value of the page parameter q is null and the page hits the error. If the page is fully loaded, everything works just as expected.

I am not interested in disabling the buttons until the page is fully loaded due to the odd behavior the page would exhibit to users. I have tried doing lazy initialization of the variable but it does not seem to have any effect.

Finally, I have looked at the view state of pages and they are not too big. The page sometimes loads very quickly (< 1sec) but sometimes takes more time (2-3 secs). It is during the longer load times that the command button issue is more of a problem.

Is there some other way to make sure the parameter gets loaded sooner?

Here is my controller:

public class Questionnaire {

    //Page parameters
    public String pQID {get; set;}

    public Questionnaire() {

         pQID = ApexPages.currentPage().getParameters().get('q');

        if (pQID == null) {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, 'There was a problem.'));
            isError = true;
        }

        Other stuff......
       ...................
    }

    public pageReference nextPage() {
        pageRef = NextPageJump(Q.EntryStatus__c);
        pageRef.getParameters().put('q',pQID);
        pageRef.setRedirect(false);
        return pageRef;   
    }
}

And the visualforce pages (all have same look and controller):

<apex:page controller="Questionnaire">

  Lots of stuff.........
  ......................
  ......................
  ......................

  <apex:commandButton value="Next page" action="{!nextPage}"/>

</apex:page>
3
  • note: since nextpage() uses setRedirect(false), then the controller won't reinitialize and there's no reason to set q to pQID again and again. Are you saying that the constructor hasn't finished initializing before the user impatiently clicks Next?
    – cropredy
    Commented Sep 4, 2014 at 23:10
  • Yeah, the user clicks the button before the page is fully loaded. The issue is that to a standard user the page appears to be loaded (everything is displayed) but Chrome/FF etc. is still loading something behind the scenes (swirling icon). I would hope that users wouldn't be too antsy, but unfortunately that is not always the case and am hoping to avoid any page load errors if possible. Commented Sep 4, 2014 at 23:29
  • 1
    Per the doc: salesforce.com/us/developer/docs/pages/… , the constructor will complete before any html is sent to the page. Presumably the first wizard page is invoked with /apex/mypage?q=someid and then pQID gets a value which should be left alone for the duration of the wizard as long as you don't pageRef.setRedirect(true);
    – cropredy
    Commented Sep 4, 2014 at 23:47

1 Answer 1

1

A few suggestions:

  1. The simplest thing I can think of would be to set the button location to "bottom" on the <apex:pageblockbuttons> element. This doesn't technically stop the user from clicking the button, but are they really going to load the page and scroll way to the bottom and hurry to click it before your 2-3 second page load?
  2. Null check pQID in your nextpage() method. Don't let them advance, and just display a message to them if they click before it's loaded.
  3. Put less work in your constructor. I would simplify by getting the pQID in the constructor, setting it and then moving everything else you're doing now to an init() method or similar. Call the init() method on the action in the <apex:page> element. This would likely make your ID get set earlier.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .