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
brunol11brunol11 

How to Pass a Value from a VF page to Iframe in other VF Page

Hi everybody!

 

I wrote 2 Visual Force Pages:

  • The first one ("Autenticar_Cod") is a simple page wich refers to a custom object named "Faturamento__c" and shows the value of a field named "Autentica_Fatura__c" followed by the current date.
  • The second one has a <apex:repeat> tag and, after select the records in a related tab, should open a page with <apex:Iframe> and show the content of the first page.

The issue is: I can´t pass  "Autentica_Fatura__c" field value to the second page. The frames appears only with the current date and nothing else.

 

Is it possible to be done? How?

 

Here follows the 2 page code:

 

VF Page: Autenticar_Cod 

<apex:page standardController="Faturamento__c" name="AuthCode" recordSetVar="MyFat" showHeader="False" sidebar="False" renderAs="html" >
  <apex:form title="Clique no código para autenticar" onclick="window.print()">
   <html>
    <head>
    </head>
    <body>
      <apex:outputText >{!Faturamento__c.Autentica_Fatura__c}</apex:outputText>
      <apex:outputText value="{0,date,yyMMdd}">
      <apex:param value="{!NOW()}" />
     </apex:outputText>
    </body>
   </html>
  </apex:form></apex:page>

 VF Page: Autenticar_Frame

<apex:page standardController="Faturamento__c" recordSetVar="MyFaturas" showHeader="False" sidebar="False" renderAs="html" >
 <apex:repeat value="{!selected}" var="Boleto" id="Repetidor" >
  <apex:form title="Clique no código para autenticar" onclick="window.history.go(-1)">

   <html>
    <head>
     <script type="text/javascript">
      function goBack()
       {
         window.history.go(-1)
       }
     </script>
    </head>
    <body>
     <apex:iframe frameborder="true" height="30" width="40%" src="Autenticar_Cod" scrolling="true" id="theIframe"> 
     </apex:iframe>
    </body>
   </html>
  </apex:form>
 </apex:repeat>
 <input type="button" value="Retornar" onclick="goBack()" /> </apex:page>
 
Thanks in advance for any ideas!

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

So in Autenticar_Frame, do your records come through correctly - i.e. you have the expected number of iframes etc, and do you have the id of the records as part of the selected property?

 

If that is the case, you should be able to provide this as a parameter to your iframe:

 

 <apex:iframe frameborder="true" height="30" width="40%" src="Autenticar_Cod?id={!boleto.id}" scrolling="true" id="theIframe"> 
 </apex:iframe>

 However, I don't think you need a recordsetvar for the Autenticar_Cod page, as you are only displaying a single record.

All Answers

bob_buzzardbob_buzzard

So are the Autentica_Fatura__c the ids of records that you want to pass into the iframe?  If so, I think you'll need to pass these as parameters on the URL.  Standard list controllers work on existing filters (list views) or when you build the list of records yourself through an extension controller.  In this case you'd pass all the ids as parameters, then in the extension constructor you'd set up the recordsetvar in the "parent" list controller.

 

Is there a particular reason why you have to use an iframe?  if you used a page include, you could have the same controller instance backing both of them and not have to worry about passing list  back and forth to the browser.

brunol11brunol11

Hi Bob!

 

The reason is beaceuse the user has to print each field "Autentica_Fatura__c" appart from other.

For instance: A cliente paid 4 billings and the salesforce user has to detach 4 pieces of paper from that billings and insert each one in a Text Only Printer and print it´s authentication code wich is the "Autentica_Fatura__c". Most times the client pays more than 6 billings at a time. So i need to post in a VF page all the billings to be printed one at a time.

 

 

 My uestion is exactly this: How to pass the parameters? Where do I insert the variable at first page? 

At second page all I have to do is insert the parameter after the page name, like "Autentica_cod?idvar={!Boletos.Id}" ?

 

Thanks a lot!

bob_buzzardbob_buzzard

In the first page, what action does the user take to produce the iframe?  E.g. do they click a link, button etc?  And does this go back to an action method on your controller?

brunol11brunol11

The user enters into the "Contratacao__c" tab, then goes to "Faturamento__c" related tab, select the desired billings to print the authentication and clicks on the "Auth" custom button wich redirects to the 2nd page above (Autenticar_Frame) and should create the repeated frames, each one contains the code to be printed.

 

Everything goes fine except the value of {!Faturamento__c.Autentica_Fatura__c} is not appearing inside the frames.

 

Thx a Ton for your help.

bob_buzzardbob_buzzard

So in Autenticar_Frame, do your records come through correctly - i.e. you have the expected number of iframes etc, and do you have the id of the records as part of the selected property?

 

If that is the case, you should be able to provide this as a parameter to your iframe:

 

 <apex:iframe frameborder="true" height="30" width="40%" src="Autenticar_Cod?id={!boleto.id}" scrolling="true" id="theIframe"> 
 </apex:iframe>

 However, I don't think you need a recordsetvar for the Autenticar_Cod page, as you are only displaying a single record.

This was selected as the best answer
brunol11brunol11

Hi Bob!

 

I don´t have the exactly words to thank you for helping me. You´re great!

The code is working super fine.

 

Thanks a lot!!!

 

Bruno Lube