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
Vandy7Vandy7 

Accessing command link

Hai all, I have a command link defined in a visualforce page.On clicking that,I want the value to be filled in a text area which is another visualforce page.Can anyone help me to this?
Best Answer chosen by Admin (Salesforce Developers) 
sforce2009sforce2009

Parent Page

 

<apex:page >
  <apex:form >
      <apex:inputTextarea id="txtTest"/>
      <script>
          var objTA = document.getElementById('{!$Component.txtTest}');
      </script>
      <apex:commandButton onclick="javascript&colon;return openPopup();" value="Open Popup"/>
  </apex:form>
  <script>
      function openPopup()
      {
          curPopupWindow = window.open("../apex/ChildPage", "_blank","width=500, height=500,dependent=no,toolbar=no,status=no,directories=no,menubar=no,scrollbars=1,resizable=no", true);  ;
          return false;
      }
      
      function populateParent(Name)
      {
           objTA.value = Name;   
           curPopupWindow.close();
      }
  </script>
</apex:page>

 

ChildPage

<apex:page >
  <apex:form >
      <apex:commandLink onclick="populate()" value="Populate Parent Page"/>
  </apex:form>
  <script>
      function populate()
      {
          top.window.opener.populateParent('Value to be populated in Text Area');
      }
  </script>
</apex:page>

All Answers

dke01dke01

can you provide a little more information about what your trying to do exactly.

 

There is no server side session/cache in visual force so the only way to pass values between pages is

 

  1. Save it into the DB
  2. Save it in a cookie via javascript
  3. Have the command link return a PageReference to the new URL and set a Query string paramater of the value you want.
Vandy7Vandy7
Fine,I will explain you the scenario. I have a textarea defined in a visualforce page.Also,I have a command Button(say,SELECT TEMPLATE).On clicking the button,I want to move to a visualforcepage where I have a list of templates(Here,they are of the form commandLink). Now,on clicking the commandlink,I want the value to be filled in the textarea of the first visualforce page.Hope you got it. Thanks in advance.
sforce2009sforce2009
You can use a small javascript to achieve this from your child window. Use top.opener property to set a value in your parent page.
Vandy7Vandy7

Thanks for your response but I am not able to do it properly and getting errors.Can you please elaborate it by pasting an example code?

 

sforce2009sforce2009

Parent Page

 

<apex:page >
  <apex:form >
      <apex:inputTextarea id="txtTest"/>
      <script>
          var objTA = document.getElementById('{!$Component.txtTest}');
      </script>
      <apex:commandButton onclick="javascript&colon;return openPopup();" value="Open Popup"/>
  </apex:form>
  <script>
      function openPopup()
      {
          curPopupWindow = window.open("../apex/ChildPage", "_blank","width=500, height=500,dependent=no,toolbar=no,status=no,directories=no,menubar=no,scrollbars=1,resizable=no", true);  ;
          return false;
      }
      
      function populateParent(Name)
      {
           objTA.value = Name;   
           curPopupWindow.close();
      }
  </script>
</apex:page>

 

ChildPage

<apex:page >
  <apex:form >
      <apex:commandLink onclick="populate()" value="Populate Parent Page"/>
  </apex:form>
  <script>
      function populate()
      {
          top.window.opener.populateParent('Value to be populated in Text Area');
      }
  </script>
</apex:page>

This was selected as the best answer
Vandy7Vandy7

Thanks for the reply,but I am not able to move to the child page at all.

 

And,what is that onclick="javascript&colon;return openPopup();"

 

If I remove this,I can move to the child page.

 

Please reply

Vandy7Vandy7

Thanks for your code sample.I was able to pass values from child window to the parent window.

 

But the case what you have told is applicable only when i have a single command link.How do I pass values when I have more than one command link.

 

I have pasted the code the child window VF page.

<apex:page showHeader="false">
<apex:form id="f">
<script>
function populate()
 {
var selected=document.getElementById('{!$Component.f:pb:pbs:cl}').innerHTML;
top.window.opener.populateParent(selected);
}
</script>
<apex:pageBlock id="pb">
<apex:pageBlockSection title="Click on the links below to select a template" columns="2" id="pbs" showHeader="true" collapsible="false">
<apex:pageBlockSectionItem>Name</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >Description</apex:pageBlockSectionItem>
<apex:commandLink value="Marketing:Product Inquiry Response" onclick="populate()" id="cl"/>
<apex:outputText value="Standard email response to website product inquiries"></apex:outputText>
<apex:commandLink value="Sales:New Customer Email" onclick="populate()"/>
<apex:outputText value="Email to new customers"></apex:outputText>
<apex:commandLink value="SUPPORT:Self-Service New User Login Information (SAMPLE)" onclick="populate"/>
<apex:outputText value="Notification of login and password to new Self-Service user"></apex:outputText>
<apex:commandLink value="Support:Self-Service Reset Password" onclick="populate()"/>
<apex:outputText value="Notification of new password when self-service password is reset"></apex:outputText>
<apex:commandLink value="Support: Case Created (Phone Inquiries)" onclick="populate()"/>
<apex:outputText value="Notification to customer about case created through phone call"></apex:outputText>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

 

 

 

 

<apex:page showHeader="false">
<apex:form id="f">
<script>
function populate()
 {
var selected=document.getElementById('{!$Component.f:pb:pbs:cl}').innerHTML;
top.window.opener.populateParent(selected);
}
</script>
<apex:pageBlock id="pb">
<apex:pageBlockSection title="Click on the links below to select a template" columns="2" id="pbs" showHeader="true" collapsible="false">
<apex:pageBlockSectionItem labelStyleClass="font-weight:bold">Name</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >Description</apex:pageBlockSectionItem>
<apex:commandLink value="Marketing:Product Inquiry Response" onclick="populate()" id="cl"/>
<apex:outputText value="Standard email response to website product inquiries"></apex:outputText>
<apex:commandLink value="Sales:New Customer Email" onclick="populate()"/>
<apex:outputText value="Email to new customers"></apex:outputText>
<apex:commandLink value="SUPPORT:Self-Service New User Login Information (SAMPLE)" onclick="populate"/>
<apex:outputText value="Notification of login and password to new Self-Service user"></apex:outputText>