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
Shwetal DesaiShwetal Desai 

Returning Data from Pop up VF page to Parent VF Page

There are two VF Pages
X is parent vf page and Y is pop up vf page
there is a commandlink on Y page
and two <apex:param> component on pop vf page
There is one Command Link on X parent page on click of which Y pop up page will open.
 
Source Code:
 
X Page [parent page]:
 
<apex:page standardController="POS__c" extensions="PointOfSale" tabStyle="POS__c">
<script type="text/javascript">
function openclient()
{
     var clt = window.open("{!$Page.clientlookup}?ctxt=client&ctid=clientid","lookup","width=750,height=390");     
}
</script>
<apex:form id="frmpos">
<apex:pageBlock title="New Ticket" id="pos">
<apex:inputText value="{!clientId}" id="client"/>
<apex:commandLink onclick="openclient();return false();">
</apex:commandLink>
<apex:inputText id="clientid"/>
Y Page [pop up Page]:
 
<apex:page controller="ClientLookUp" showHeader="false" tabStyle="Client__c" sidebar="false" wizard="true">
               <script type="text/javascript">
                window.opener.document.getElementById('clientId').value = '{!$CurrentPageReference.parameters.cid}';
                alert('{!$CurrentPageReference.parameters.cid}');
                return false;               
               </script>
<apex:form id="list">
<apex:pageblock title="Select Client">   
<apex:pageBlockSection title="Client List" id="result">   
<apex:outputPanel id="rlist" title="Result">
            <apex:pageBlockTable value="{!searchresult}" var="clt" columns="5"  id="list" width="100%">        
                <apex:column value="{!clt.Name}"/>
                <apex:column >         
                    <apex:facet name="header"><b>Client</b></apex:facet>         
                    <apex:commandLink id="classtype" onclick="setvalue();">               
                    <apex:param name="cid" value="{!clt.Id}"/>
                    <apex:param name="ccode" value="{!clt.Client__c}"/>
                    {!clt.Client__c}        
                    </apex:commandLink>   
                </apex:column>   
            </apex:pageBlockTable>  
          </apex:outputPanel>
        </apex:pageBlockSection> 
    </apex:pageblock>
</apex:form>
</apex:page>
 
 
ERRORS:
1. Onclick of commandLink on Y Page it gives error "window.opener.document is null or not an object".
2. {!$CurrentPageReference.parameters.cid} is blank.
 
for first error i tried "window.opener.document.form.client.value", "window.opener.form.client.value" but error remains same.
 
any help/suggesions are greatly appreciated.......
 
Thanks
 
 
Ron HessRon Hess
2. {!$CurrentPageReference.parameters.cid} is blank.

should this be {!$CurrentPageReference.parameters.ctid} ? since that is what you are passing ?



1. Onclick of commandLink on Y Page it gives error "window.opener.document is null or not an object".

the id of an visualforce tag can be generated using something like {! $Component. frmpos .client }

see the documentation on $Component

http://www.salesforce.com/us/developer/docs/pages/Content/pages_access.htm#pages_access_dom
Shwetal DesaiShwetal Desai
Thanks Ron for replying
 
2. {!$CurrentPageReference.parameters.cid} is blank.
 
here is my code for this:
            <apex:column >          
                    <apex:facet name="header"><b>Client</b></apex:facet>         
                    <apex:commandLink id="classtype" onclick="setvalue();">               
                          <apex: param name="cid" value="{!clt.Id}"/>
                          <apex: param name="ccode" value="{!clt.Client__c}"/>
                    {!clt.Client__c}        
                    </apex:commandLink>    
             </apex:column>   
 
here for both <apex: param> tags I have name = "cid" and "ccode" respectively
And i m getting both "{!$CurrentPageReference.parameters.cid} " and "{!$CurrentPageReference.parameters.ccode}" blank.
 
Is it becoz i have used custom controller?
 
1. Onclick of commandLink on Y Page it gives error "window.opener.document is null or not an object".
 
Actually for this problem I tried to get window.opener first.. and when i write alert(window.opener); in javascript it gave me alert message undefined.
that means i think i m not getting window.opener on child page, and for this on X page i have replaced previous function with this function
 
function openclient()
{
     var newWindow = window.open("{!$Page.clientlookup}?txt=client&ctid=clientid","newWindow","width=670,height=390");      
     newWindow.creator=self;
}
 
but still window.opener.document is null or not an object error is remains same.
 
 
Please Guide me ...

Message Edited by Shwetal Desai on 09-09-2008 01:08 AM

Message Edited by Shwetal Desai on 09-09-2008 01:33 AM
Ron HessRon Hess
still a few things i don't understand

in this code
Code:
   <script type="text/javascript">
                window.opener.document.getElementById('clientId').value = '{!$CurrentPageReference.parameters.cid}';
                alert('{!$CurrentPageReference.parameters.cid}');
                return false;               
               </script>

 
you are executing this code when the page is rendered, but you return false ?

it looks to me that this is supposed to be inside a function?




also, in this code
Code:
<apex:commandLink id="classtype" onclick="setvalue();">               
                          <apex: param name="cid" value="{!clt.Id}"/>
                          <apex: param name="ccode" value="{!clt.Client__c}"/>
                    {!clt.Client__c}        
                    </apex:commandLink>  

 you have no action method, so the only thing that will run is a javascript method, which is not defined

the param tag works with Apex action methods, not onclick() javascript functions, so cid will never be set.


Shwetal DesaiShwetal Desai
yes right its my mistake in javascript and i made it proper like this:
Code:
<script type="text/javascript">
    function setvalue()
    {
        alert(top.opener);
        top.opener.document.getElementById('{!$Component.clientid}').value='Shwetal';
    }
</script>

 
now in this code m getting error "top.opener.document.getElementById(...) is null or not an object".
 
after that i tried with this line :
 top.opener.document.getElementById('{!$Component.frmpos.clientid}').value='Shwetal';
but it gives same error.

also, this code i wrote to pass values of {!clt.Id} and {!clt.Client__c} from this pop up page to parent page using javascript...
Code:
<apex:commandLink id="classtype" onclick="setvalue();">               
                          <apex: param name="cid" value="{!clt.Id}"/>
                          <apex: param name="ccode" value="{!clt.Client__c}"/>
                    {!clt.Client__c}        
                    </apex:commandLink>  

but as u say i havent wrote action for this commandlink and without action (apex code) param tag will not set its value..
so in this case what should i do?
 
How can i pass these two values from this pop up page to its parent page??
what i m trying to do is , i want to pass more than one value from different columns of PageBlockTable on selection of one column value at a time.
 

Shwetal DesaiShwetal Desai
can someone help me to perform this task?
 
m looking for help
 
 
trishtrish

Shwethal.

I don't know if you already found a solution for this. I was getting the same error and I was able to fix it by using window.top.opener.document.getElementById. Hope this helps.

 

Shwetal DesaiShwetal Desai
THanks for replying Trish

yeah i got the solution...
I used same line
window.parent.opener.document.getElementById
MukulMukul

H Shwetal,

 

I was facing the exact issue. This forum post helped me a lot!

 

Thanks much!

Regards

Mukul

atintoatinto

H Shwetal,

I have used the code:

window.top.opener.document.getElementById....;

or
window.parent.opener.document.getElementById....;

but not returning data...

the syntax is correct?

thnk's

Antonio by italy