2

I have the following scenario :-

  • I do some query on a page using user input.
  • User makes changes to the query and click 'Update' button
  • User is redirected to a new page for confirmation where they are shown with old values and also the new ones
  • Then user is asked to click 'Confirm'

The problem is that in the first page I did the query and the query results were stored in list, on 'Update' the list was copied into a new list, list data gets updated & user is directed to the confirmation page BUT now when the user is directed , I can't think of any way to pass both list to this new page.

I tried using the same apex controller for both pages BUT whenever I will get to the confirmation page the controller will be reloaded &its constructor will be called again & I will lose the data in the lists.

Can Someone Help me With THIS?

7

The page's view state is preserved when the following conditions hold:

  • The new page uses the same controller as the old page.
  • The new page uses a subset of the extensions as the old page.
  • The Redirect flag is set to false on the PageReference.
  • Both pages use an apex:form.

Here's an incredibly basic proof of concept that shows this behavior in action:

CommonController.cls

public class CommonController {
    public String message { get; set; }
    public PageReference nextPage() {
        return Page.CommonPage2;
    }
}

CommonPage1.page

<apex:page controller="CommonController">
    <apex:form>
        <h1>
            This is page 1.
        </h1>
        Enter a message:
        <apex:inputText value="{!message}" />
        <apex:commandButton action="{!nextPage}" value="Show on next page" />
    </apex:form>
</apex:page>

CommonPage2.page

<apex:page controller="CommonController">
    <apex:form>
        <h1>
            This is page 2.
        </h1>
        The message from page 1 was:
        <span style="font-weight: bold">
            <apex:outputText value="{!message}" />
        </span>
    </apex:form>
</apex:page>

As this code hopefully demonstrates, you can indeed pass whatever data you want between the two controllers. Depending on the complexity of the page, it might take you several tries, but I suggest that you simply start off simple (e.g. build a basic working version), and then build up to the desired feature set over several iterations.

0

I am assuming you are using pagereference method to navigate to the next page from controller.

PageReference nextpage = PageReference.orderpage;
nextpage.getParameters().put('items', String.join(items, ','));

and in the next page you can do a get of the parameter.

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.