[jboss-user] [JBoss Portal] - Re: Is the header a portlet?

rutfield do-not-reply at jboss.com
Thu Sep 14 17:53:15 EDT 2006


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.java

  | 
  | 
  | package 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 at 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>

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3971700#3971700

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3971700



More information about the jboss-user mailing list