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>
/apex/mypage?q=someid
and thenpQID
gets a value which should be left alone for the duration of the wizard as long as you don'tpageRef.setRedirect(true);