How to use IFrame in Portlets?


IFrames are implemented in Portlets to include URLs that point to a complete HTML page. JSR 168 API supports implementation of IFrames in Portlets. To implement IFrame in Portlets perform the following steps:
  • Build a Portlet JSR 168 project, say IFrameJSR.
  • Create/ include the html file that is to be embedded in the Portlet’s IFrame.
  • In the view jsp created, say IFrameJSRPortletView.jsp; build the absolute path for the source as follows:
String strURL = renderResponse.encodeURL(renderRequest.getContextPath() + "<relative file path>");

The relative path specified is the path of the file starting from the position after the context-root.
Next, add the <iframe> tag in the view jsp as follows:
<iframe id="Iframe" src='<%=strURL%>' width="500" height="15" marginwidth="0" marginheight="0" frameborder="1" scrolling="no" >

Above displays the attributes set for the inline frame. The inline frame has been created with a border and no scrolling.

Compile and build the Portlet application. The deployed Portlet will be displayed as shown in the figure below:


The above figure displays IFrame in a Portlet. The data displayed in the IFrame is sought from another html page. The IFrame can be modified to show more than one line data, along with scroll bars. While developing the IFrame, make a note on the width and the height size being used. It should not collide with the Portlet layout.


Anonymous said...

How can i keep the navigation of the user, if the the user open another portlet inside the same page. Now it happen that if user open iframeA that have a web application, navigates some page-complete some data, then open iframeB that have another web application, when he return to iframeA the iframe display to the user not where he was previoulsy, he start at the begininnig losing all what the he done.
It is a way to keep this?

Arun Khurana said...

I don't think it's possible to maintain the navigation state of the IFrame portlets specially if you are navigating away from the portal page and then coming back to the same page but changing the portlet state to minimize and then restoring it can be handled through java script.

Post a Comment

Recent Posts

Popular Posts

© 2011-2019 Web Portal Club