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
Gabe Rothman 8Gabe Rothman 8 

Banging my head against a wall -- visualforce page pass picklist value into apex:iframe src parameter

Hey folks, I know I'm gonna feel stupid when I get the answer here, but I just can't seem to get this right.  I'm trying to create a visualforce page that populates other visualforce pages within an iframe based on a picklist selection, btu I can't seem to figure out how to pass the selected picklist value into the src parameter of my iframe component. I've deleted a bunch of the broken code that hasn't worked so the code is pretty simple at this point.

Can someone help me sort it out?  Thanks!

Controller:
public class domoDashboardController {
    
    public List<String> pagename {
        get {
            if (pagename == null) {
                pagename = new List<String>();
                list<ApexPage> pages = [SELECT Name FROM ApexPage WHERE Name != 'domoDashBoardViewer' AND Name LIKE 'DOMO_%' ORDER BY Name ASC];
                for (ApexPage page : pages){
        			pagename.add(page.Name);
        		}
      		}
      		return pagename;          
    	}
    	set;
  	}
    
}

VF Page:
<apex:page controller="domoDashboardController">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
    <apex:pageBlock title="DOMO Dashboard Viewer" mode="edit">
        
        <apex:form>
            <table width="100%" border="0">
                <tr>
                    <td style="font-weight:bold; padding-left: 5px; padding-top:10px; width: 125px;">                    
                        Select Dashboard:
                    </td>                
                    <td style="font-weight:bold; padding-top:8px;">
    					<select id="pagename">
                        	<option value=""></option>
                            <apex:repeat value="{!pagename}" var="pag">
                            	<option value="{!pag}">{!pag}</option>
                            </apex:repeat>
                        </select>     
                    </td>     
                </tr>
            </table>
            <apex:pageBlock>    
                <table width="100%" border="0">
                    <tr>
                        <apex:page id="thePage">
							<apex:iframe src="" scrolling="true" id="theIframe"/>
                        </apex:page>
                    </tr>
                </table>
            </apex:pageBlock>
		</Apex:form>
    </apex:pageBlock> 
    
</apex:page>

 
Best Answer chosen by Gabe Rothman 8
Vishwajeet kumarVishwajeet kumar
Contoller : 
public class domoDashboardController {
public String pageName{get;set;}
public String iframeURL{get;Set;}
    
    public List<SelectOption>  pageNameList {
        get {
            if (pageNameList == null) {
                pageNameList = new List<SelectOption>();
                list<ApexPage> pages = [SELECT Name FROM ApexPage WHERE Name != 'domoDashBoardViewer' AND Name LIKE 'DOMO_%' ORDER BY Name ASC];
                for (ApexPage page : pages){
        			pageNameList .add(new SelectOption(page.Name,page.Name);
        		}
      		}
      		return pagename;          
    	}
    	set;
  	}    
}

public void setIframeUrl(){
if(pageName != null){
 iframeURL = '/'+ pageName ;
pageName = null;
}
}

Page :

<apex:page controller="domoDashboardController">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
    <apex:pageBlock title="DOMO Dashboard Viewer" mode="edit">
        
        <apex:form>
            <table width="100%" border="0">
                <tr>
                    <td style="font-weight:bold; padding-left: 5px; padding-top:10px; width: 125px;">                    
                        Select Dashboard:
                    </td>                
                    <td style="font-weight:bold; padding-top:8px;">
    					<apex:selectList value="{!pageName}">
                    <apex:actionSupport event="onchange" action="{!setIframeUrl}" rerender="thePage"/>
                    <apex:selectOptions value="{!pageNameList}"/>
                </apex:selectList >   
                    </td>     
                </tr>
            </table>
            <apex:pageBlock>    
                <table width="100%" border="0">
                    <tr>
                        <apex:page id="thePage">
							<apex:iframe src="" scrolling="true" id="theIframe"/>
                        </apex:page>
                    </tr>
                </table>
            </apex:pageBlock>
		</Apex:form>
    </apex:pageBlock> 
    
</apex:page>
Try above it should work.

 

All Answers

Vishwajeet kumarVishwajeet kumar
Prepare a String URL parameter in controller based Selection from Select Option. Use variable in Src field as <apex:iframe src="{![variable]}"/>.
Re-render the iFrame block, each time select option is changed.
Gabe Rothman 8Gabe Rothman 8
Hi Vishwajeet, sorry to be pushy, but would it be possible for you post some sample code of how to implement that.  I'm just not sure how to identify which picklist value is selected and then how to set the string variable to that value.  Thanks so much for your help!
Vishwajeet kumarVishwajeet kumar
Contoller : 
public class domoDashboardController {
public String pageName{get;set;}
public String iframeURL{get;Set;}
    
    public List<SelectOption>  pageNameList {
        get {
            if (pageNameList == null) {
                pageNameList = new List<SelectOption>();
                list<ApexPage> pages = [SELECT Name FROM ApexPage WHERE Name != 'domoDashBoardViewer' AND Name LIKE 'DOMO_%' ORDER BY Name ASC];
                for (ApexPage page : pages){
        			pageNameList .add(new SelectOption(page.Name,page.Name);
        		}
      		}
      		return pagename;          
    	}
    	set;
  	}    
}

public void setIframeUrl(){
if(pageName != null){
 iframeURL = '/'+ pageName ;
pageName = null;
}
}

Page :

<apex:page controller="domoDashboardController">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
    <apex:pageBlock title="DOMO Dashboard Viewer" mode="edit">
        
        <apex:form>
            <table width="100%" border="0">
                <tr>
                    <td style="font-weight:bold; padding-left: 5px; padding-top:10px; width: 125px;">                    
                        Select Dashboard:
                    </td>                
                    <td style="font-weight:bold; padding-top:8px;">
    					<apex:selectList value="{!pageName}">
                    <apex:actionSupport event="onchange" action="{!setIframeUrl}" rerender="thePage"/>
                    <apex:selectOptions value="{!pageNameList}"/>
                </apex:selectList >   
                    </td>     
                </tr>
            </table>
            <apex:pageBlock>    
                <table width="100%" border="0">
                    <tr>
                        <apex:page id="thePage">
							<apex:iframe src="" scrolling="true" id="theIframe"/>
                        </apex:page>
                    </tr>
                </table>
            </apex:pageBlock>
		</Apex:form>
    </apex:pageBlock> 
    
</apex:page>
Try above it should work.

 
This was selected as the best answer
Vishwajeet kumarVishwajeet kumar
also, i missed to edit the iframe Url:
Modify it as : <apex:iframe src="{!iframeURL}" scrolling="true" id="theIframe"/>
Gabe Rothman 8Gabe Rothman 8
Perfect! This worked great. You rock! And yes, as I said in my first post, I'm definitely stupid for not realizing how to implement this in the first place :-)
Just for your reference, I made two adjustments.
I changed the "return pagename" in the code below to "return pageNameList"
01public List<SelectOption>  pageNameList {
02        get {
03            if (pageNameList == null) {
04                pageNameList = new List<SelectOption>();
05                list<ApexPage> pages = [SELECT Name FROM ApexPage WHERE Name !='domoDashBoardViewer' AND Name LIKE 'DOMO_%' ORDER BY Name ASC];
06                for (ApexPage page : pages){
07                    pageNameList .add(new SelectOption(page.Name,page.Name);
08                }
09            }
10            return pagename;         
11        }
12        set;
13    }
I also changed 
1public void setIframeUrl(){
2    if(pageName != null){
3        iframeURL = '/'+ pageName ;
4        pageName = null;
5   }
6}
to 
1public void setIframeUrl(){
2    if(pageName != null){
3        iframeURL = pageName ;
4        pageName = null;
5   }
6}
I didn't need the ' / ' + portion of the code because I'm not referencing a URL, I'm actually just referencing the name of the iframed VF page directly.  

Anyway, thanks again for your help.  I really appreciate it!