voyent
runtime expressions in iframe tag sc  XML
Forum Index -> General Help
Author Message
aravindra

Joined: 07/Oct/2007 00:00:00
Messages: 18
Offline


Hi,
I need to set the src attribute of <iframe/> dynamically. Looks like Ice tags dont support any kind of runtime expressions. Please confirm.

I was trying to acheive this using Javascript. But it doesnt work for me.

Here is my JS declared in <head>
Code:
 <script language="JavaScript" type="text/javascript" >
 
  
  function setFrameSource( fUrl ) {
  alert(fUrl);
  document.getElementById('newsFrame').src =fUrl'
  
  }
  
  
  </script>


I am invokoing this function in Backing bean as follows:

Code:
 		this.currentLink = (String)FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("link");
 JavascriptContext.addJavascriptCall(FacesContext.getCurrentInstance(), "setFrameSource('"+this.currentLink+"');");
 


Is this the right way of doing it? Any alternative solution?

I have the url in a binding variable. I need to set it as the Iframe src var : #{newsItem.url}.


Thanks in advance
AR

philip.breau


Joined: 08/May/2006 00:00:00
Messages: 2989
Offline


It should work the way your trying, you just have to make sure that the Javascirpt is being properly rendered. But the easiest thing to do is just use Facelets. Then you can do this:

Code:
 <iframe src="#{newsItem.url}"/>
 


Philip

.
aravindra

Joined: 07/Oct/2007 00:00:00
Messages: 18
Offline


Hi Philip,
Thanks for such a quick response. But <iframe src="#{newsItem.url}"/> doesnt work for me.

Code:
 <f:facet name="body">
 	<ice:panelGrid id="details" width="100%" cellpadding="0"
 							border="1" cellspacing="0" columns="1"styleClass="popupModalBody">
 	<ice:outputText value="#{newsBean.currentLink}" />
 	<iframe id="newsFrame" src="#{newsBean.currentLink}" height="800" width="800" >
 	</iframe>
 							
 	</ice:panelGrid>
 
 </f:facet>
 


<ice:outputText value="#{newsBean.currentLink}" /> in the above code prints the correct url.
Also, there is nothing wrong with the iframe because if I have "http://www.yahoo.com" in src, the iframe loads.

Thanks,
AR
philip.breau


Joined: 08/May/2006 00:00:00
Messages: 2989
Offline


In order to use my my suggestion you'd have to use Facelets as well. Is your Javascript function rendering properly to the page?

Philip

.
aravindra

Joined: 07/Oct/2007 00:00:00
Messages: 18
Offline


Hi Philip,
The javascript is rendered properly in the page. Here is my jspx:

Code:
 
 <f:view xmlns:h="http://java.sun.com/jsf/html"
 	xmlns:f="http://java.sun.com/jsf/core"
 	xmlns:ui="http://java.sun.com/jsf/facelets"
 	xmlns:jsp="http://java.sun.com/JSP/Page"
 	xmlns:ice="http://www.icesoft.com/icefaces/component">
 	<jsp:directive.page import="javax.faces.context.FacesContext" />
 	<ice:outputDeclaration doctypeRoot="HTML"
 		doctypePublic="-//W3C//DTD HTML 4.01 Transitional//EN"
 		doctypeSystem="http://www.w3.org/TR/html4/loose.dtd" />
 	<html>
 	<head>
  <script language="JavaScript" type="text/javascript" >
 
  
  function setFrameSource( fUrl ) {
  alert(fUrl);
  document.getElementById('newsFrame').src =fUrl'
  
  }
 
  
  </script>	
 	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
 	<title><ice:outputText value="ICEfaces, Ajax for Java EE" /></title>
 	<ice:outputStyle href="/resources/css/xp/xp.css" />
 	<ice:outputStyle href="/resources/css/mar.css" />
 	<ice:outputStyle href="/resources/css/showcase_style.css"
 		rel="stylesheet" type="text/css" />
 	</head>
 	<body>
 	<ice:form id="iceform" xmlns:h="http://java.sun.com/jsf/html"
 		xmlns:f="http://java.sun.com/jsf/core"
 		xmlns:ice="http://www.icesoft.com/icefaces/component">
 	<ice:panelTab>
         <ice:panelBorder id="page"
                 styleClass="pnlBrdrDemo"
                          renderNorth="#{true}"
                          renderSouth="#{true}"
                          renderCenter="#{true}"
                          renderWest="#{true}"
                          renderEast="#{true}">
 
             <f:facet name="north">
                 <ice:outputText id="north" value="North"/>
             </f:facet>
 
             <f:facet name="west">
                 <ice:panelGrid id="west" columns="1">
 					<ice:panelSeries var="items" value="#{newsBean.westList}">
 
 						<div class="siteHeader"><ice:outputText
 							value="#{items.siteName}" /></div>
 						<ice:dataTable rows="10" value="#{items.siteNewsItems}" var="newsItem"
 							style="border: medium solid #555555; width: 350px;">
 							<ice:column>
 
 								<ice:graphicImage value="images/bullet.gif"/>
 								
 									<ice:commandLink partialSubmit="true"
 										actionListener="#{newsBean.showNewsPopup}">
 										<f:param name="link" value="#{newsItem.url}" />
 										<ice:outputText value="#{newsItem.title}" />
 									</ice:commandLink>								
 								<ice:outputLink value="#{newsItem.url}">
 									<ice:graphicImage value="images/offsite.gif"/>
 								</ice:outputLink>
 							</ice:column>
 
 						</ice:dataTable>
 
 
 					</ice:panelSeries>
                 </ice:panelGrid>
             </f:facet>
 
             <f:facet name="east">
                 <ice:panelGrid id="east" columns="1">
 					<ice:panelSeries var="items" value="#{newsBean.eastList}">
 
 						<div class="siteHeader"><ice:outputText
 							value="#{items.siteName}" /></div>
 						<ice:dataTable rows="10" value="#{items.siteNewsItems}" var="newsItem"
 							style="border: medium solid #555555; width: 350px;">
 							<ice:column>
 
 								<ice:graphicImage value="images/bullet.gif"/>
 								<ice:outputLink value="#{newsItem.url}">
 									<ice:outputText value="#{newsItem.title}" />
 								</ice:outputLink>
 							</ice:column>
 
 						</ice:dataTable>
 
 
 					</ice:panelSeries>
                 </ice:panelGrid>
             </f:facet>
 
             <f:facet name="center">
 					<ice:panelSeries var="items" value="#{newsBean.centerList}">
 
 						<div class="siteHeader"><ice:outputText
 							value="#{items.siteName}" /></div>
 						<ice:dataTable rows="10" value="#{items.siteNewsItems}" var="newsItem"
 							style="border: medium solid #555555; width: 350px;">
 							<ice:column>
 
 								<ice:graphicImage value="images/bullet.gif"/>
 								<ice:outputLink value="#{newsItem.url}">
 									<ice:outputText value="#{newsItem.title}" />
 								</ice:outputLink>
 							</ice:column>
 
 						</ice:dataTable>
 
 
 					</ice:panelSeries>
             </f:facet>
 
             <f:facet name="south">
                 <ice:outputText id="south" value="South"/>
             </f:facet>
         </ice:panelBorder>
 
     </ice:panelTab>
 		<ice:panelTabSet id="icepnltabset"
 			styleClass="componentPanelTabSetLayout">
 			
 			<ice:panelCollapsible expanded="#{true}">
 
 				
 
 				<ice:panelPopup id="draggablePP" draggable="true"
 					rendered="#{newsBean.newsDetailsVisible == 'true'}"
 					style="z-index: 1000; top: 300px; left: 300px; position: absolute; width: 600px; height: 600px;">
 
 					<f:facet name="header">
 						<ice:panelGrid id="draggablePanelGrid" width="100%"
 							cellpadding="0" cellspacing="0" columns="2"
 							columnClasses="none, popupButton">
 							<ice:outputText value="Event Details" />
 							<ice:commandButton id="popupClose" type="button"
 								image="#{newsBean.closePopupImage}"
 								actionListener="#{newsBean.closeNewsDetails}"
 								style="cursor: pointer;" />
 
 						</ice:panelGrid>
 					</f:facet>
 
 					<f:facet name="body">
 						<ice:panelGrid id="details" width="100%" cellpadding="0"
 							border="1" cellspacing="0" columns="1"
 							styleClass="popupModalBody">
 							<ice:outputText value="#{newsBean.currentLink}" />
 							<iframe id="newsFrame" src="#{newsBean.currentLink}" height="800" width="800" >
 							</iframe>
 							
 						</ice:panelGrid>
 
 					</f:facet>
 
 				</ice:panelPopup>
 
 			</ice:panelCollapsible>
 
 		</ice:panelTabSet>
 	</ice:form>
 	</body>
 	</html>
 </f:view>
 


Is there anything I am missing?
The iframs is in panelPopup.

Thanks in advance.
philip.breau


Joined: 08/May/2006 00:00:00
Messages: 2989
Offline


You have to use Facelets if you want to use any expressions outside of a component context. iframe isn't a component, so currently, as you're not using Facelets, you can't use the expression currentLink.

Philip

.
jacob.alvarez

Joined: 30/Nov/2006 00:00:00
Messages: 55
Offline


Hi,

I have used facelets, and the expression:

<iframe src="#{newsItem.url}"/>

works if newsItem.url does not change over time. If you change it over time or you want to use ajax push you will have to use alternatives. To get around this, I had to use something like:

#{newsItem.iframe}

newsItem.getIframe() returns "<iframe src=..../>"

I have not tested this issue with icefaces 1.7 or 1.6.2.

Thanks,
ryandawson

Joined: 04/Oct/2007 00:00:00
Messages: 13
Offline


I've been doing this with the facelets mentioned above and it seems to work fine for me on 1.6.1.
 
Forum Index -> General Help
Go to:   
Powered by JForum 2.1.7ice © JForum Team