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
goabhigogoabhigo 

Communicating between visualforce pages

Hi everyone. Is there any method to communicate with 2 visualforce pages?? I have tried with the ids(the inputText id,or page id), but it does not work at all. I have tried with apex controllers too.Here,I can use getter setter methods. But since I cannot pass value to controller through JavaScript I am not able to achieve this task. Is there any solution?? I have tried with 'static' variable too. As we know its meaning is different in Apex, we cannot use it for different pages. Any suggestions will be helpful Thanks in advance.
Best Answer chosen by Admin (Salesforce Developers) 
goabhigogoabhigo

Oh yeah,its solved..

 

I used ids of the apex tags..

 

Child:

 

<script>

function YourFunction()

 var myValue=document.getElementById('{!$Component.id3:id4:t1}').innerHTML;  (You have to write relative path here.)

 var winMain=window.opener;

      if (null==winMain)

      {

         winMain=window.parent.opener;

      }

 winMain.aFunction(myValue);       // Pass the value to the parent window.

}

</script>

<apex:pageBlock id="id3">

 <apex:pageBlockSection columns="2" collapsible="false" id="id4"

<apex:pageBlockSectionItem > <b> name</b></apex:pageBlockSectionItem>

 <apex:pageBlockSectionItem > <b> Sample </b></apex:pageBlockSectionItem>

 <apex:commandLink value="Test1" onclick="YourFunction()" />

 <apex:outputText id="t1" value="Testing1" />

</apex:pageBlockSection>

 </apex:pageBlock> 

</apex:form>

</apex:page>

 

 

 

Parent:

 

function aFunction(childVal)

{

 document.getElementById('{!$Component.pb1:pbs1:pbsi1:msgArea}').value=childVal;

}

 

Thats it, the text area(id='msgArea') gets filled with the value from the child window. Here too while specifying id of text area take care of its path. In my case text area is inside pageBlock(id='pb1')-- pageBlockSection(id='pbs1')---pageBlockSectionItem(id='pbsi1')....     

 

NEVER THOUGHT IT WAS SO SIMPLE.

Enjoy.. :-)

 

--abhi

All Answers

md1md1

see the documentation for visualforce wizard... the idea is to use the samw controller/extension for the pages.

goabhigogoabhigo

Thanks Manu, but still the value is different in both the pages. I have used a string variable(say, str='';). In the second window(child window or popup window) I can set the value of str and can display the value. But when I close the window and if I check in he parent window, the value of str is still blank(or null). So it is obvious that both pages are using different instances of the same controller class (???? is it? I am not sure). The same problem persists even if I use static.. Any reasons?? Or if you have any other better solutions,please let me know....

 

Thanks.

goabhigogoabhigo

Oh yeah,its solved..

 

I used ids of the apex tags..

 

Child:

 

<script>

function YourFunction()

 var myValue=document.getElementById('{!$Component.id3:id4:t1}').innerHTML;  (You have to write relative path here.)

 var winMain=window.opener;

      if (null==winMain)

      {

         winMain=window.parent.opener;

      }

 winMain.aFunction(myValue);       // Pass the value to the parent window.

}

</script>

<apex:pageBlock id="id3">

 <apex:pageBlockSection columns="2" collapsible="false" id="id4"

<apex:pageBlockSectionItem > <b> name</b></apex:pageBlockSectionItem>

 <apex:pageBlockSectionItem > <b> Sample </b></apex:pageBlockSectionItem>

 <apex:commandLink value="Test1" onclick="YourFunction()" />

 <apex:outputText id="t1" value="Testing1" />

</apex:pageBlockSection>

 </apex:pageBlock> 

</apex:form>

</apex:page>

 

 

 

Parent:

 

function aFunction(childVal)

{

 document.getElementById('{!$Component.pb1:pbs1:pbsi1:msgArea}').value=childVal;

}

 

Thats it, the text area(id='msgArea') gets filled with the value from the child window. Here too while specifying id of text area take care of its path. In my case text area is inside pageBlock(id='pb1')-- pageBlockSection(id='pbs1')---pageBlockSectionItem(id='pbsi1')....     

 

NEVER THOUGHT IT WAS SO SIMPLE.

Enjoy.. :-)

 

--abhi

This was selected as the best answer