-
15. Re: Is the header a portlet?
rutfield Sep 14, 2006 5:53 PM (in response to andrewboyd)Glad to. It is basically the portletswap iframe for 2.4 with different URL and height/width. I thought I'd try this one first.
This is a trimmed down version that exhbits the issues.
I do not have a jboss-portlet.xml (unlike the samples in the reference guide). If I add a to my iframe-object.xml, I get an error.
The portal's Admin says it is using the emptyRenderer, but the items still show up.
I'd really appreciate a push in the right direction.
Thanks.
CR
iframe-object.xml<?xml version="1.0" encoding="UTF-8"?> <deployments> <deployment> <if-exists>overwrite</if-exists> <parent-ref>default</parent-ref> <page> <page-name>IFrame</page-name> <window> <window-name>IFramePortletWindow</window-name> <instance-ref>IFramePortletInstance</instance-ref> <region>center</region> <height>0</height> <properties> <property> <name>theme.windowRendererId</name> <value>emptyRenderer</value> </property> <property> <name>theme.decorationRendererId</name> <value>emptyRenderer</value> </property> <property> <name>theme.portletRendererId</name> <value>emptyRenderer</value> </property> </properties> </window> </page> </deployment> </deployments>
IFramePortlet.javapackage org.jboss.portlet.iframe; import javax.portlet.ActionRequest; import javax.portlet.ActionResponse; import javax.portlet.GenericPortlet; import javax.portlet.PortletException; import javax.portlet.PortletMode; import javax.portlet.PortletPreferences; import javax.portlet.PortletRequestDispatcher; import javax.portlet.PortletSecurityException; import javax.portlet.RenderRequest; import javax.portlet.RenderResponse; import java.io.IOException; /** * User: Chris Mills (millsy@jboss.com) * Date: 04-Mar-2006 * Time: 10:45:10 */ public class IFramePortlet extends GenericPortlet { private static final String defaultURL = "http://www.rutfield.info"; private static final String defaultHeight = "104px"; private static final String defaultWidth = "204px"; private static final String defaultNonIFrameMessage = "Your browser does not support iframes."; public void processAction(ActionRequest request, ActionResponse response) throws PortletException, PortletSecurityException, IOException { String op = request.getParameter("op"); StringBuffer message = new StringBuffer(1024); if((op != null) && (op.trim().length() > 0)) { if(op.equalsIgnoreCase("update")) { PortletPreferences prefs = request.getPreferences(); String url = request.getParameter("url"); String height = request.getParameter("height"); String width = request.getParameter("width"); String noIFrameMessage = request.getParameter("noiframemessage"); boolean px = false; boolean save = true; if((url != null) && (height != null) && (width != null) && (noIFrameMessage != null)) { if(!url.startsWith("http://")) { save = false; message.append("URLs must start with 'http://'<br/>"); } try { if(height.endsWith("px")) { height = height.substring(0, height.length() - 2); } Integer.parseInt(height); } catch(NumberFormatException nfe) { //Bad height value save = false; message.append("Height must be an integer<br/>"); } try { if(width.endsWith("px")) { px = true; width = width.substring(0, width.length() - 2); } else if(width.endsWith("%")) { width = width.substring(0, width.length() - 1); } Integer.parseInt(width); } catch(NumberFormatException nfe) { //Bad height value save = false; message.append("Width must be an integer<br/>"); } if(save) { prefs.setValue("iframeheight", height + "px"); prefs.setValue("iframewidth", px ? width + "px" : width + "%"); prefs.setValue("iframeurl", url); prefs.setValue("iframemessage", noIFrameMessage); prefs.store(); response.setPortletMode(PortletMode.VIEW); return; } } } else if(op.equalsIgnoreCase("cancel")) { response.setPortletMode(PortletMode.VIEW); return; } else { message.append("Operation not found"); } } else { message.append("Operation is null"); } response.setRenderParameter("message", message.toString()); response.setPortletMode(PortletMode.EDIT); } public void doView(RenderRequest request, RenderResponse response) { try { setRenderAttributes(request); response.setContentType("text/html"); PortletRequestDispatcher prd = getPortletContext().getRequestDispatcher("/WEB-INF/iframe/iframe.jsp"); prd.include(request, response); } catch(Exception e) { e.printStackTrace(); } } public void doEdit(RenderRequest request, RenderResponse response) throws IOException, PortletException { setRenderAttributes(request); response.setContentType("text/html"); response.setTitle("Edit"); PortletRequestDispatcher prd = getPortletContext().getRequestDispatcher("/WEB-INF/iframe/edit.jsp"); prd.include(request, response); } private void setRenderAttributes(RenderRequest request) { PortletPreferences prefs = request.getPreferences(); request.setAttribute("iframeurl", prefs.getValue("iframeurl", IFramePortlet.defaultURL)); request.setAttribute("iframeheight", prefs.getValue("iframeheight", IFramePortlet.defaultHeight)); request.setAttribute("iframewidth", prefs.getValue("iframewidth", IFramePortlet.defaultWidth)); request.setAttribute("iframemessage", prefs.getValue("iframemessage", IFramePortlet.defaultNonIFrameMessage)); } }
iframe.jsp<%@ page language="java" extends="org.jboss.portal.core.servlet.jsp.PortalJsp" %> <%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %> <portlet:defineObjects/> <table width="<%= request.getAttribute("iframewidth") %>"> <tr> <td> <iframe src="<%= request.getAttribute("iframeurl") %>" width="<%= request.getAttribute("iframewidth") %>" height="<%= request.getAttribute("iframeheight") %>" border="0"> Your browser does not support iframes </iframe> </td> </tr> </table>
-
16. Re: Is the header a portlet?
rutfield Sep 15, 2006 6:14 AM (in response to andrewboyd)All I am trying to do is put an HTML frame into the header. I can create a new theme and put the frame in a portlet, but that really seems to overcomplicate what sounds like a straightforward task.
12.6.1 in the reference guide describes using JSP tags for header content injection. Is that a better approach than described here? If so, which JSP file should include it? -
17. Re: Is the header a portlet?
peterj Sep 15, 2006 11:52 AM (in response to andrewboyd)Note that section 12.6.1 is about injecting HTML header content. That is, it goes between the < head >< /head > tags in the HTML page. That section is not about injecting things into the banner of the page (often also referred to as the header).
-
18. Re: Is the header a portlet?
peterj Sep 16, 2006 6:19 PM (in response to andrewboyd)I tried your iframe protlet and after a few changes it showed up just fine, in the banner area, without any decorations.
First, in iframe-object.xml, the statement:<region>center</region>
places the iframe in the center column, not in the banner(header). If you want it in the banner area, use:<region>navigation</region>
Second, in iframe-object.xml, the statement:<page-name>IFrame</page-name>
causes a new page, named IFrame to be created, and the portlet window to be placed on that page. Not sure if that is what you really intended, so I changed it to:<page-name>default</page-name>
However, I image that since the iframe is in the bannner area that you really want it to show up on all the pages. In that case, you will need several < deployment > entries, each with all the same subnodes though with different < page-name > entries, one for each page.
Fianlly, you stated that you could not provide a jboss-portal.xml file because you were getting errors on the < portal > entry. I think the cause is that you earlier deployed the iframe portal, possibly deleted the war file, and are now deploying it again. You really need the jboss-portal.xml file because it links the portal name to the instance name, which is used in the iframe-object.xml file.
I think that perhaps the previous deployment of the iframe portlet is what is causing the problem. If you are still just experimenting, I suggest wiping out your database and starting over with a fresh installation of the portal. If you can't do that, rename your portlet and instances. -
19. Re: Is the header a portlet?
rutfield Sep 16, 2006 7:00 PM (in response to andrewboyd)Thank you for taking the time to do this.
I really appreciate it.
Your explanation makes a lot of sense (now that you said it). I will give it a shot.
CR