Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding iframe to JSF components

Tags:

iframe

jsf

widget

Is it possible to add an iframe to a JSF component(RichFaces, PrimeFaces) from backing bean?

I need to embed externel webpages in my homepage. And user needs to set this url. I cannot use jQuery.

I am not able to find any iframe equivalent JSF component. Is there any particular reason for this?

like image 360
charishma Avatar asked Jun 07 '11 08:06

charishma


2 Answers

Just use plain HTML.

<iframe src="#{bean.iframeUrl}"></iframe>

The most probable reason why a component doesn't exist is because there would be no extra advantages to offer when wrapping it in a JSF component. For example <p>, <br>, <hr>, etc have also no JSF equivalent.

like image 128
BalusC Avatar answered Oct 09 '22 00:10

BalusC


Yes possible. We can use plain HTML with in xhtml file. I have tried it. It is working good. below i have given my code.

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<f:view locale="#{facesContext.externalContext.requestLocale}">
<h:head>
    <title>
        <h:outputText value="your application title"></h:outputText>
    </title>
    <style type="text/css">
        #imagepgframe { 
            width: 100%;
            height: 100%;
            position: absolute;
        }
        #wrap { 
            width: 100%;
            position: absolute;
            top: 0px; 
            left: 0;
            bottom: 0;
            overflow-y: hidden;
            overflow-x: hidden;
        }
    </style>
</h:head>
<h:body>
    <h:form>
        <div id="wrap"> 
            <iframe id="imagepgframe" name="imagepgframe" frameborder="0" scrolling="auto" src="#{bean.iframeUrl}">
              <p>Your browser does not support iframes.</p>
            </iframe>
        </div>
    </h:form>
</h:body>

Thanks.

like image 26
Ganesa Vijayakumar Avatar answered Oct 09 '22 00:10

Ganesa Vijayakumar