6

I know lot of folks would you say this topic was covered previously. Please do check out the question once, if its updated please provide me the link.

Scenario : I want to take an wizard flow. Two pages and one controller.

1st page : user will select month and year in picklist and click on button. Controller method will be called and there 3 queries will run ( long ones ), then user will be redirected to second page ( with setRedirect as false)

2nd page : This page will contain 4 data tables which will be rendered as pdf.

problem : In the first page after clicking on button its not redirecting ( no errors, i have added pageMessages and no exceptions, i have added catch block also).

PageReference pageRef = new PageReference ('/.....');
return pageRef;

or

return Page.PageName;

I have tried both but its not redirecting.

Am i missing anything?

Update : I have done on the similar lines ( below link ), but its not working.

http://www.salesforce.com/us/developer/docs/pages/Content/pages_quick_start_wizard.htm

Update :

Pasting the simplified code

Page :

  .tableStyling
     {
            padding:15px;
         }  
    </style>
<apex:form >
    <apex:outputPanel >         // This block will be hidden for page 2
        <apex:pageMessages ></apex:pageMessages>
        <apex:outputLabel value="Month" /> 
        <apex:selectlist multiselect="false" size="1" value="{!Month}">
            <apex:selectOption itemValue="01" itemLabel="Jan"/>
                        .
                        .
             <apex:selectOption itemValue="12" itemLabel="Dec"/> 
             </apex:selectList>

        <apex:outputLabel value="Year" /> 
         <apex:selectlist multiselect="false" size="1" value="{!Year}">
                <apex:selectOption itemValue="2012" itemLabel="2012"/>
                                .
                        .
                                <apex:selectOption itemValue="2017" itemLabel="2017"/> 
        </apex:selectList>

         <apex:commandButton value="GO" reRender="output,thePage" action="{!processCommission}" status="image"/>
        <apex:actionStatus id="image">
                                    <apex:facet name="start">
                                            <img class="waitingImage" src="/img/loading.gif" title="Getting Values for you..." />
                         </apex:facet>
        </apex:actionStatus>

    </apex:outputPanel>
    <apex:pageBlock id="output" rendered="false">    // Block Hidden for page 1
         <apex:outputText value="Producer" style="font-size : 18px;font-weight:bold;color : red"/>
         <br /><br /><br />
        <apex:dataTable value="" var="" width="100%" >
                <apex:column value="" headerValue="Name" styleClass="tableStyling"/>
                    More Columns
            </apex:dataTable>
        <br /><br /><br />
        <apex:outputText value="Commission by Producer" style="font-size : 18px;font-weight:bold;color : red"/>
        <br /><br /><br />
        <apex:dataTable value="" var="" width="100%" >
                  <apex:column value="" headerValue="CWP" styleClass="tableStyling"/>
                     More Columns
         </apex:dataTable>   
        <br /><br /><br />
        <apex:outputText value="Commission by Insurance Companies" style="font-size : 18px;font-weight:bold;color : red"/>
        <br /><br /><br />
        <apex:dataTable value=""  var="" width="100%">
                <apex:column value="" headerValue="Name" styleClass="tableStyling"/>
                More Columns
        </apex:dataTable>  
        <br /><br /><br />
        <apex:outputText value="Commission by Payment Detail" style="font-size : 18px;font-weight:bold;color : red"/>
        <br /><br /><br />      
        <apex:dataTable value="" var="" width="100%" >
                <apex:column value="" headerValue="Name" styleClass="tableStyling"/>
                More Columns
        </apex:dataTable>
    </apex:pageBlock>
</apex:form>
</apex:page>

Controller :

Controller contains only gettters and setters and this method

public with sharing class CommissionSlipController 
  {
         // Setters and getter for components in page
          public PageReference processCommission()
          {                         
                 String con = y+m ;
                 ContactIns =  [SOQL 1];
                 CommProdIns = [ SOQL 2 ]; 
                 CommCompIns = [ SOQL 3 ];
                 CommPaymIns = [ SOQL 4];
                 return Page.PageName;
           }
   }

Is anything missing?

Upate : Figure it out...Duhh!!! I forgot to take out reRender attribute on button, that little fellow was stopping the page from getting redirecting.

Thanks all

2 Answers 2

6

If you're doing pageRef.setRedirect(false); then it will not redirect the user to the second page. It needs to be set to true for the redirect to occur. That said, the latter form should work.

Are you 100% sure that your code is not returning some other value prior to the return statement that uses the Page.Pagename; format?

Alternative to multiple pages with one controller

From the sound of the question, the three queries run are those being used to get the data for the tables in the second page. In this scenario, what would likely work better would be to do those queries in a second controller that is specific to the PDF, the first controller would return the page reference with the various query parameters passed as page parameters.

Update - previous information was incorrect

Although you can have multiple pages use one controller, you need to make sure that any data that's used on more than one page is referenced in the very first page as per the caution note in the documentation:

Data that's used across several Visualforce pages must be defined within the first page, even if that page isn't using the data. For example, if a field is necessary on pages two and three of a three-step process, page one must also contain the field. You can hide this field from the user by setting the rendered attribute of the field to false.

9
  • If i do the latter one it'll be like a Client Side Redirect so i would be losing all the values ( in the list). I need to retain those values so that i can populate the data in the 2nd page and render it as pdf.
    – Geek
    Commented Feb 19, 2013 at 4:25
  • Thanks for the reply. That i have done and its working fine. But as of know i have very few parameters to send so it won't bother me much, but i'm trying to figure if i am ever to send list of objects itself as parameter. In that case it won't be feasible.
    – Geek
    Commented Feb 19, 2013 at 4:45
  • 1
    One possibility is to create a custom object for the parameters, creating a record on the button press from the first page, passing the record id as a query parameter, and loading (and ultimately deleting) the record in the second page.
    – metadaddy
    Commented Feb 19, 2013 at 5:20
  • @metadaddy Appreciate your time for the reply. Your solution will work but i don't want to create an custom object to keep track of that. or is there any other better way to achieve this? I'm looking for something like this salesforce.com/us/developer/docs/pages/Content/… In the example, page is getting changed ( may not be a URL ), user will be able to navigate to next page and retain the values of the varibles. I have done something like this but somehow its not happening.
    – Geek
    Commented Feb 19, 2013 at 5:41
  • 1
    setRedirect(false) is the solution to "holding" the viewstate, so to speak. However, since it was not getting any redirect and there is no other error being shown, I think the problem has to be somewhere else. Is there more pertinent code you can show?
    – joshbirk
    Commented Feb 20, 2013 at 15:40
0

Remove the rerender attribute from the command button and it will work as expected. No need to set redirect. Its working for me.

You must log in to answer this question.

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