2

I have a custom VF page to create new or edit records of Type CustomObject__c. Via a Linker__c object such records can be related to other OtherCustomObject__c.

To create such links I have a button on my custom new/edit page ...

<apex:page standardController="CustomObject__c" extensions="CtrlExt">
        <apex:form >
            ...      
            <apex:pageBlockSection title="Linker" columns="1">
                <apex:commandButton value="Link other objects" action="{!createLinks}" />
                <apex:pageBlockTable value="{!linkers}" var="links">
                    ....

...that should load another page where the user can select 0..n records of OtherCustomObject__c.

<apex:page controller="CtrlExt">
        <apex:form >
            <apex:pageBlockButtons >
                <apex:commandButton value="Link Selected Objects" action="{!doLink}" />
                <apex:commandButton value="Cancel" action="{!doCancel}" />
            </apex:pageBlockButtons> 
            ...

If he clicks Ok or Cancel he will come back to the previous page (all of his edit should be still there) and linker objects have been created from his selection.

The problem here seems to be the shared state between the custom edit page with a controller extension and the select page which is not bound to a standard controller. How can harmonize the two different page types and share viewstate between them?

public with sharing class CtrlExt {

    public  CtrlExt() {

    }

    public CtrlExt(ApexPages.StandardController stdCtrl) {

    }

    public PageReference doSelect() {
        return Page.selectOtherObjects;
    }

    public PageReference doLink() {
        // create Linker records
        return Page.customEditNew;
    }

    public PageReference doCancel() {
        return Page.customEditNew;
    }
}
2
  • Hi, is it an option to use one visualforce and have different sections displayed or not using Rendered? Commented Jul 23, 2014 at 10:00
  • Not really an option as each single page already is complex enough. Commented Jul 23, 2014 at 10:30

1 Answer 1

2

Have you tried using the same page signature for the second page too:

<apex:page standardController="CustomObject__c" extensions="CtrlExt">

that I assume would ensure that the state is transferred? The second page logic can just ignore anything related to the ApexPages.StandardController. One way to tell which page the controller is operating on would be:

Boolean onFirstPage = ApexPages.currentPage().getUrl() == Page.First.getUrl();
Boolean onSecondPage = ApexPages.currentPage().getUrl() == Page.Second.getUrl();

Navigation between the pages would need to use view state preserving components like apex:commandButton and apex:commandLink.

You must log in to answer this question.

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