function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SushupsiSushupsi 

Using same controller to send data to child window and pass back list of data to parent window

Hi,

 

Long Time no see :smileyhappy:

 

I am here with an issue. We tried forming a work around but seem to not figure it the right way. :smileysad:

 

Please find the scenario below:

 

We require to have a parent window. From the parent window we pass a value of acount to another child window.

Depending on the account id passed to child window we query all the contacts associated to the parent account and show then on the child window.

 

Now i select a multiple contacts from the child window and and i need to pass the contacts to parent window. This is where we am failing.

 

My queries are as follows:

 

1.)    How do we use the same session between the parent and child with out losing the data.

2.)    How can we restrict that the controller does not run the constructor when the child window is opened. I have observed that the constructor runs again when the child window opens with the same controller.

 

I have used the following code for the parent page:

 

<apex:page standardController="IB_CCP_Call_Report__c" tabStyle="IB_CCP_Call_Report__c" extensions="IB_CCP_CallReport_NewController">
<apex:stylesheet value="{!$Resource.IB_CCP_CallReportNewStyles}"/>

------ My code here

     <apex:outputpanel id="refreshOnModalClose" layout="block">
   
        <table width="100%"><tr>
          <td style="width:100%">
          <apex:commandButton value="refresh table" reRender="ExtSection"/>
          <apex:pageBlockSection id="ExtSection" title="Client Attendees" columns="1" collapsible="true">
          <apex:outputPanel id="searchExt" layout="block">
          <center>
             <apex:commandLink target="_blank" action="{!openAddAttendeeWindow}">
                 <apex:commandButton id="addClient" immediate="true" rerender="ExtSection" value="Add Client Attendees" disabled="{!renderAddAttendee}"/>&nbsp;&nbsp;&nbsp;
             </apex:commandLink>
             <!-- action="{!refreshContactList}"-->
             <apex:commandButton id="openClientAttendeesModal" action="{!removeAllContactsFromMap}" value="Clear All" disabled="{!NOT(addedcontactListcheck)}" rerender="searchExt,out2,errors" status="openClientAttendeesModal"/>&nbsp;&nbsp;&nbsp;
             <apex:CommandButton reRender="false" onclick="window.open('/003/e?+{!newContactParam}');" value="New contact"></apex:CommandButton>
          </center><br/>
          <apex:outputpanel id="addedcontactListPanel" rendered="{!addedcontactListcheck}" layout="block">
          <table style="width:100%" border="1"><tr><td style="width:100%">
              <apex:pageBlockTable id="addedcontactListId" value="{!addedcontactListDisplay}" var="addedCon">
              <apex:column HeaderValue="Contact">{!addedCon.ContactName}&nbsp;</apex:column>
              <apex:column HeaderValue="Title">{!addedCon.Title}&nbsp;</apex:column>
              <apex:column HeaderValue="Position">{!addedCon.Position}&nbsp;</apex:column>
              <apex:column HeaderValue="Action"><apex:commandbutton action="{!removeContactFromMap}" value="Delete" reRender="ExtSection">
              <apex:param name="testparam" assignTo="{!deleteContactId}" value="{!addedCon.ContactId}"/>
              </apex:commandbutton>
              </apex:column>
              </apex:pageBlockTable>
          <apex:commandLink action="{!prevConDetail}" value="Previous" rerender="addedcontactListPanel" rendered="{!prevConDetailListCheck}"/>&nbsp;&nbsp;
          <apex:commandLink action="{!nextConDetail}" value="Next" rerender="addedcontactListPanel" rendered="{!nextConDetailListCheck}"/>          
          </td></tr></table>
          </apex:outputpanel>
          </apex:outputPanel>


</apex:page>

 

The Code highlighted in Red is used to open the child window and use the same controller for the same.

 

Here i am able to pass the data from the parent window but i am unable to hold the values and pass them back to the parent window. On refresh the page is just reloading and showing the entire list as empty.

 

    /* This is the Logic for the Call Report Addition of Clients Revamped */
    Public Boolean renderAddAttendee {get; set;}

    Public PageReference openAddAttendeeWindow(){
        return(new pageReference('/apex/IB_CCP_openAddAttendee'));
    }

 

Any help would be appreciated.

 

TIA

sfdcfoxsfdcfox

1) "forward view state" mode only kicks in when you actively redirect to a new page and the new page has the same controller and extensions or proper subset. Redirecting is done by returning a PageReference in a CommandButton or CommandLink action. I suspect your view state isn't surviving your "button in a link" combination.

 

2) I believe that your statement and observation are both simultaneously correct. Constructors are only called if there is no valid view state being processed by the server.

 

You can observe a constuctor being invoked only once with the following example code:

 

/apex/testpage

 

 

<apex:page controller="testPage">
<apex:form >
    {!constructorCount} - {!pageCount}
    <apex:commandLink action="{!page2}" value="Page 2"/>
</apex:form>
</apex:page>

/apex/testpage2

 

 

 

<apex:page controller="testPage">
    <apex:form >
    {!constructorCount} - {!pageCount}    
    <apex:commandLink action="{!page1}" value="Page 1"/>
    </apex:form>
</apex:page>

 

public class testPage {

    public PageReference page2() {
        pageCount++;
        return Page.testpage2;
    }


    public PageReference page1() {
        pageCount++;
        return Page.testPage;
    }

    public integer constructorCount = 0;
    public integer getconstructorcount() { return constructorcount; }
    
    public integer pageCount = 0;
    public integer getpagecount() { return pagecount; }
    public testPage() {
        constructorCount++;
    }
}

When you use this example, you'll see that each click goes to the other page, and the first value, constructorCount, will remain at "1", while using the link will increment the pageCount value by 1. Also note what happens if you refresh, go back a page, etc. The view state will act oddly at some point if you think about it too much.

 

 

At any rate, your code does not appear to be passing the view state correctly, probably related to the "button inside a link" mess you've got going on there. I realize what you're trying to do (buttons can't have targets the way you're looking for). Instead, I would venture that the "correct" method to handle this would be far more convoluted than you're thinking of: JavaScript.

 

 

I would suggest the following viable alternatives:

 

1) Render the entire popup window in JavaScript. To ease the pain of doing this, I'd like to say that it doesn't have to rely on AJAX Toolkit or anything terribly complex. It would be sufficient to have hidden fields that can be populated by calling an actionFunction, etc, with the popup window relying solely on data being fed from the parent window.

 

2) Manually pass the view state along. Complex? Probably. But I'd image you'd take the following steps: a) create a new window using javascript, b) inject just enough HTML code into the window to create a functional form that contains the hidden view state attribute and required inputs, c) javascript submit the form so that the view state is accepted and the page is refreshed, d) before closing the window, pass the view state through javascript back to the parent window, e) fake a form submit, completing the loop and refreshing the page's state.

 

3) Just open the new window, passing in the parameters you want to use; create a separate page that uses the same controller, but keep in mind that the constructor will be called a second time, so you may need to code around that (... if(ApexPages.currentpage().getParameters().get('skipinit')<>null) ... ). To pass data BACK to the main window, remember you'll still need some JavaScript cooperation.

 

I'm not even going to attempt to model this tonight, but I don't see why either of the above methods couldn't work if written correctly. JavaScript would be the easiest way to accomplish your goals. The Force.com platform itself uses method 3 mentioned above for its lookup dialog boxes, so you might gain some insight by looking there.