Author: chris.laprun(a)jboss.com
Date: 2008-11-17 12:42:10 -0500 (Mon, 17 Nov 2008)
New Revision: 12299
Added:
modules/portlet/trunk/samples/src/main/java/org/jboss/portal/portlet/samples/basic/AJAXResourcePortlet.java
modules/portlet/trunk/samples/src/main/java/org/jboss/portal/portlet/samples/basic/HeaderInjectionPortlet.java
Removed:
modules/portlet/trunk/samples/src/main/java/org/jboss/portal/portlet/samples/basic/HeaderPortlet.java
Modified:
modules/portlet/trunk/portal/src/main/resources/simple-portal-war/demo/demo3.jsp
modules/portlet/trunk/samples/src/main/artifacts/basic-portlet-war/WEB-INF/portlet.xml
Log:
- Renamed HeaderPortlet to AJAXResourcePortlet.
- Added HeaderInjectionPortlet.
Modified:
modules/portlet/trunk/portal/src/main/resources/simple-portal-war/demo/demo3.jsp
===================================================================
---
modules/portlet/trunk/portal/src/main/resources/simple-portal-war/demo/demo3.jsp 2008-11-17
14:06:49 UTC (rev 12298)
+++
modules/portlet/trunk/portal/src/main/resources/simple-portal-war/demo/demo3.jsp 2008-11-17
17:42:10 UTC (rev 12299)
@@ -16,7 +16,7 @@
<jsp:attribute name="rightcol">
<xportal:portlet name="ExceptionPortlet"
applicationName="samples-basic-portlet"/>
- <xportal:portlet name="HeaderPortlet"
applicationName="samples-basic-portlet" id="header-portlet"/>
+ <xportal:portlet name="AJAXResourcePortlet"
applicationName="samples-basic-portlet" id="header-portlet"/>
<xportal:portlet name="FailDuringInitPortlet"
applicationName="samples-basic-portlet"/>
<xportal:portlet name="ExceptionPortlet"
applicationName="samples-basic-portlet"/>
</jsp:attribute>
Modified:
modules/portlet/trunk/samples/src/main/artifacts/basic-portlet-war/WEB-INF/portlet.xml
===================================================================
---
modules/portlet/trunk/samples/src/main/artifacts/basic-portlet-war/WEB-INF/portlet.xml 2008-11-17
14:06:49 UTC (rev 12298)
+++
modules/portlet/trunk/samples/src/main/artifacts/basic-portlet-war/WEB-INF/portlet.xml 2008-11-17
17:42:10 UTC (rev 12299)
@@ -41,8 +41,8 @@
</portlet>
<portlet>
- <portlet-name>HeaderPortlet</portlet-name>
-
<portlet-class>org.jboss.portal.portlet.samples.basic.HeaderPortlet</portlet-class>
+ <portlet-name>AJAXResourcePortlet</portlet-name>
+
<portlet-class>org.jboss.portal.portlet.samples.basic.AJAXResourcePortlet</portlet-class>
<supports>
<mime-type>text/html</mime-type>
</supports>
@@ -50,11 +50,25 @@
<mime-type>text/javascript</mime-type>
</supports>
<portlet-info>
- <title>Header portlet</title>
+ <title>AJAX resource portlet</title>
</portlet-info>
</portlet>
<portlet>
+ <portlet-name>HeaderInjectionPortlet</portlet-name>
+
<portlet-class>org.jboss.portal.portlet.samples.basic.HeaderInjectionPortlet</portlet-class>
+ <supports>
+ <mime-type>text/html</mime-type>
+ </supports>
+ <supports>
+ <mime-type>text/javascript</mime-type>
+ </supports>
+ <portlet-info>
+ <title>Header injection portlet</title>
+ </portlet-info>
+ </portlet>
+
+ <portlet>
<portlet-name>FailDuringInitPortlet</portlet-name>
<portlet-class>org.jboss.portal.portlet.samples.basic.FailDuringInitPortlet</portlet-class>
<supports>
@@ -176,7 +190,7 @@
<filter-mapping>
<filter-name>FilterB</filter-name>
- <portlet-name>HeaderPortlet</portlet-name>
+ <portlet-name>AJAXResourcePortlet</portlet-name>
</filter-mapping>
<event-definition>
Copied:
modules/portlet/trunk/samples/src/main/java/org/jboss/portal/portlet/samples/basic/AJAXResourcePortlet.java
(from rev 12254,
modules/portlet/trunk/samples/src/main/java/org/jboss/portal/portlet/samples/basic/HeaderPortlet.java)
===================================================================
---
modules/portlet/trunk/samples/src/main/java/org/jboss/portal/portlet/samples/basic/AJAXResourcePortlet.java
(rev 0)
+++
modules/portlet/trunk/samples/src/main/java/org/jboss/portal/portlet/samples/basic/AJAXResourcePortlet.java 2008-11-17
17:42:10 UTC (rev 12299)
@@ -0,0 +1,179 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.portlet.samples.basic;
+
+import javax.portlet.GenericPortlet;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.PortletException;
+import javax.portlet.ResourceRequest;
+import javax.portlet.ResourceResponse;
+import javax.portlet.ResourceURL;
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletSecurityException;
+import javax.portlet.PortletURL;
+import javax.portlet.PortletMode;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class AJAXResourcePortlet extends GenericPortlet
+{
+ public final static int TITANIUM = 0;
+ public final static int PLATINUM = 1;
+ public final static int GOLD = 2;
+ public final static int SILVER = 3;
+ public final static int TIN = 4;
+
+ public void processAction(ActionRequest req, ActionResponse resp) throws
PortletException, PortletSecurityException, IOException
+ {
+
+ String repeatText = req.getParameter("repeat");
+ // set zip as render parameter
+ if (repeatText != null){
+ resp.setRenderParameter("repeat", repeatText);
+ }
+ // request view
+ resp.setPortletMode(PortletMode.VIEW);
+
+ }
+ public void render(RenderRequest req, RenderResponse resp) throws PortletException,
IOException
+ {
+ ResourceURL resourceURL = resp.createResourceURL();
+ PortletURL actionURL = resp.createActionURL();
+ //
+// Element elt = resp.createElement("script");
+// elt.setAttribute("type", "text/javascript");
+// elt.setAttribute("src", resourceURL.toString());
+// elt.appendChild(elt.getOwnerDocument().createTextNode(""));
+// resp.addProperty("script", elt);
+
+ //
+
+ resp.setContentType("text/html");
+ PrintWriter writer = resp.getWriter();
+ writer.print("" +
+ "<script type=\"text/javascript\">" +
+ "" +
+ // "function init(){\n" +
+ //" Event.observe('repeat', 'keyup', repeat(),
false);\n" +
+ // "}" +
+ "" +
+ "function browse(id) {" +
+ "var url = id;\n" +
+ "var pars = 'foo=bar';\n" +
+ "var target = 'output-div';\n" +
+ "var myAjax = new Ajax.Updater(target, url, {method: 'GET',
parameters: pars});" +
+ "}" +
+
+ "</script>");
+
+ writer.print("" +
+ "<div class='full-width'
style='padding:5px'>" +
+ "<h4>Partial Refresh Repeater Demo</h4>");
+ writer.print("" +
+ " <div class='half-width float-left'>" +
+ " <form method='post' id=\"testrepeatform\"
name=\"testrepeatform\" action=\"" + actionURL + "\"
onsubmit=\"new Ajax.Updater('repeat-div', '" + resourceURL +
"', {asynchronous:true, parameters:Form.serialize(this)}); return
false;\">\n" +
+ " <font class='portlet-font'>Repeat
Demo:</font><br/>\n" +
+ " <input class='portlet-form-input-field'
type='text' value='' size='12' name=\"repeat\"
id=\"repeat\" onkeyup=\"this.form.submit2.click();new
Effect.Highlight(document.getElementById('repeat-div'));\"/>\n" +
+ " <input class='portlet-form-input-field hidden'
type='submit' name='submit2' value='submit'
style=\"display:hidden;\">\n" +
+ " </form>\n" +
+ "</div>" +
+ "");
+ writer.print("<div id=\"repeat-container\"><div
id=\"repeat-div\" class='half-width float-left'
style='height:50px'></div></div>");
+// "<input type=\"text\" id=\"hidden-input\"
value=\"" + resourceURL.toString() + "\" />" +
+// "<a href='javascript:" + resp.getNamespace() +
"_handle()'>Click me to trigger script</a>" +
+ writer.print("<br class='clear'/><br
class='clear'/><hr/>" +
+ "<h4>Partial Refresh Product Catalog</h4>" +
+ "<div class='full-width'>" +
+ "");
+ writer.print("<div class='float-left third-width'>");
+ resourceURL.setParameter("prodId","1");
+ writer.print("<a href=\"javascript: browse(\'" +
resourceURL + "\');\">Product 1</a><br/>");
+
+ resourceURL.setParameter("prodId","2");
+ writer.print("<a href=\"javascript: browse(\'" +
resourceURL + "\');\">Product 2</a><br/>");
+
+ resourceURL.setParameter("prodId","3");
+ writer.print("<a href=\"javascript: browse(\'" +
resourceURL + "\');\">Product 3</a><br/>");
+
+ writer.print("<br class='clear'/></div>");
+ writer.print("<div class='float-left two-third-width'>"
+
+ "<h4 class='zero'>Product Details</h4>" +
+ "<div id=\"output-div\"></div>" +
+ "");
+ writer.print("<br class='clear'/></div>");
+ writer.print("<br class='clear'/></div>");
+ writer.print("<br class='clear'/></div>");
+
+
+
+ // writer.print("</div>");
+ }
+
+ public void serveResource(ResourceRequest req, ResourceResponse resp) throws
PortletException, IOException
+ {
+ String repeatText = req.getParameter("repeat");
+ String prodId = req.getParameter("prodId");
+
+ resp.setContentType("text/html");
+ PrintWriter writer = resp.getWriter();
+ if (repeatText != null){
+ writer.print("<div id=\"repeat-text\">"+
req.getPrivateParameterMap().get("repeat")[0] +"</div>");
+ }
+ if (prodId != null){
+ if (prodId.equals("1")){
+ writer.print("<div id=\"product-text\">Product ID:
"+ prodId +"" +
+ "<br/>" +
+ " B BY BURTON ALPHA<br/>" +
+ "Sale Price: $314.96 " +
+ "</div>");
+ }
+ if (prodId.equals("2")){
+ writer.print("<div id=\"product-text\">Product ID:
"+ prodId +"" +
+ "<br/>" +
+ "FORUM DESTROYER LTD<br/>" +
+ "$319.99 " +
+ "</div>");
+ }
+ if (prodId.equals("3")){
+ writer.print("<div id=\"product-text\">Product ID:
"+ prodId +"" +
+ "<br/>" +
+ "\n" +
+ "SANTA CRUZ ALLSTAR<br/>" +
+ "$256.00 " +
+ "</div>");
+ }
+
+ }
+
+
+
+
+ writer.close();
+ }
+}
Added:
modules/portlet/trunk/samples/src/main/java/org/jboss/portal/portlet/samples/basic/HeaderInjectionPortlet.java
===================================================================
---
modules/portlet/trunk/samples/src/main/java/org/jboss/portal/portlet/samples/basic/HeaderInjectionPortlet.java
(rev 0)
+++
modules/portlet/trunk/samples/src/main/java/org/jboss/portal/portlet/samples/basic/HeaderInjectionPortlet.java 2008-11-17
17:42:10 UTC (rev 12299)
@@ -0,0 +1,54 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2008, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.jboss.portal.portlet.samples.basic;
+
+import org.w3c.dom.Element;
+
+import javax.portlet.GenericPortlet;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.MimeResponse;
+import javax.portlet.PortletException;
+import java.io.IOException;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public class HeaderInjectionPortlet extends GenericPortlet
+{
+
+ @Override
+ protected void doView(RenderRequest renderRequest, RenderResponse renderResponse)
throws PortletException, IOException
+ {
+ renderResponse.getWriter().print("Look at browser title!");
+ }
+
+ @Override
+ protected void doHeaders(RenderRequest renderRequest, RenderResponse renderResponse)
+ {
+ Element element = renderResponse.createElement("title");
+ element.setTextContent("My new web browser title");
+ renderResponse.addProperty(MimeResponse.MARKUP_HEAD_ELEMENT, element);
+ }
+}
Deleted:
modules/portlet/trunk/samples/src/main/java/org/jboss/portal/portlet/samples/basic/HeaderPortlet.java
===================================================================
---
modules/portlet/trunk/samples/src/main/java/org/jboss/portal/portlet/samples/basic/HeaderPortlet.java 2008-11-17
14:06:49 UTC (rev 12298)
+++
modules/portlet/trunk/samples/src/main/java/org/jboss/portal/portlet/samples/basic/HeaderPortlet.java 2008-11-17
17:42:10 UTC (rev 12299)
@@ -1,181 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2008, Red Hat Middleware, LLC, and individual *
- * contributors as indicated by the @authors tag. See the *
- * copyright.txt in the distribution for a full listing of *
- * individual contributors. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
- ******************************************************************************/
-package org.jboss.portal.portlet.samples.basic;
-
-import javax.portlet.GenericPortlet;
-import javax.portlet.RenderRequest;
-import javax.portlet.RenderResponse;
-import javax.portlet.PortletException;
-import javax.portlet.ResourceRequest;
-import javax.portlet.ResourceResponse;
-import javax.portlet.ResourceURL;
-import javax.portlet.ActionRequest;
-import javax.portlet.ActionResponse;
-import javax.portlet.PortletSecurityException;
-import javax.portlet.PortletURL;
-import javax.portlet.PortletMode;
-import java.io.IOException;
-import java.io.PrintWriter;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 630 $
- */
-public class HeaderPortlet extends GenericPortlet
-{
- public final static int TITANIUM = 0;
- public final static int PLATINUM = 1;
- public final static int GOLD = 2;
- public final static int SILVER = 3;
- public final static int TIN = 4;
-
- public void processAction(ActionRequest req, ActionResponse resp) throws
PortletException, PortletSecurityException, IOException
- {
-
- String repeatText = req.getParameter("repeat");
- // set zip as render parameter
- if (repeatText != null){
- resp.setRenderParameter("repeat", repeatText);
- }
- // request view
- resp.setPortletMode(PortletMode.VIEW);
-
- }
- public void render(RenderRequest req, RenderResponse resp) throws PortletException,
IOException
- {
- ResourceURL resourceURL = resp.createResourceURL();
- PortletURL actionURL = resp.createActionURL();
- //
-// Element elt = resp.createElement("script");
-// elt.setAttribute("type", "text/javascript");
-// elt.setAttribute("src", resourceURL.toString());
-// elt.appendChild(elt.getOwnerDocument().createTextNode(""));
-// resp.addProperty("script", elt);
-
- //
-
- resp.setContentType("text/html");
- PrintWriter writer = resp.getWriter();
- writer.print("" +
- "<script type=\"text/javascript\">" +
- "" +
- // "function init(){\n" +
- //" Event.observe('repeat', 'keyup', repeat(),
false);\n" +
- // "}" +
- "" +
- "function browse(id) {" +
- "var url = id;\n" +
- "var pars = 'foo=bar';\n" +
- "var target = 'output-div';\n" +
- "var myAjax = new Ajax.Updater(target, url, {method: 'GET',
parameters: pars});" +
- "}" +
-
- "</script>");
-
- writer.print("" +
- "<div class='full-width'
style='padding:5px'>" +
- "<h4>Partial Refresh Repeater Demo</h4>");
- writer.print("" +
- " <div class='half-width float-left'>" +
- " <form method='post' id=\"testrepeatform\"
name=\"testrepeatform\" action=\"" + actionURL + "\"
onsubmit=\"new Ajax.Updater('repeat-div', '" + resourceURL +
"', {asynchronous:true, parameters:Form.serialize(this)}); return
false;\">\n" +
- " <font class='portlet-font'>Repeat
Demo:</font><br/>\n" +
- " <input class='portlet-form-input-field'
type='text' value='' size='12' name=\"repeat\"
id=\"repeat\" onkeyup=\"this.form.submit2.click();new
Effect.Highlight(document.getElementById('repeat-div'));\"/>\n" +
- " <input class='portlet-form-input-field hidden'
type='submit' name='submit2' value='submit'
style=\"display:hidden;\">\n" +
- " </form>\n" +
- "</div>" +
- "");
- writer.print("<div id=\"repeat-container\"><div
id=\"repeat-div\" class='half-width float-left'
style='height:50px'></div></div>");
-// "<input type=\"text\" id=\"hidden-input\"
value=\"" + resourceURL.toString() + "\" />" +
-// "<a href='javascript:" + resp.getNamespace() +
"_handle()'>Click me to trigger script</a>" +
- writer.print("<br class='clear'/><br
class='clear'/><hr/>" +
- "<h4>Partial Refresh Product Catalog</h4>" +
- "<div class='full-width'>" +
- "");
- writer.print("<div class='float-left third-width'>");
- resourceURL.setParameter("prodId","1");
- writer.print("<a href=\"javascript: browse(\'" +
resourceURL + "\');\">Product 1</a><br/>");
-
- resourceURL.setParameter("prodId","2");
- writer.print("<a href=\"javascript: browse(\'" +
resourceURL + "\');\">Product 2</a><br/>");
-
- resourceURL.setParameter("prodId","3");
- writer.print("<a href=\"javascript: browse(\'" +
resourceURL + "\');\">Product 3</a><br/>");
-
- writer.print("<br class='clear'/></div>");
- writer.print("<div class='float-left two-third-width'>"
+
- "<h4 class='zero'>Product Details</h4>" +
- "<div id=\"output-div\"></div>" +
- "");
- writer.print("<br class='clear'/></div>");
- writer.print("<br class='clear'/></div>");
- writer.print("<br class='clear'/></div>");
-
-
-
- // writer.print("</div>");
- }
-
- public void serveResource(ResourceRequest req, ResourceResponse resp) throws
PortletException, IOException
- {
- String repeatText = req.getParameter("repeat");
- String prodId = req.getParameter("prodId");
-
- String namespace =resp.getNamespace();
- //resp.setContentType("application/json");
- resp.setContentType("text/html");
- PrintWriter writer = resp.getWriter();
- if (repeatText != null){
- writer.print("<div id=\"repeat-text\">"+
req.getPrivateParameterMap().get("repeat")[0] +"</div>");
- }
- if (prodId != null){
- if (prodId.equals("1")){
- writer.print("<div id=\"product-text\">Product ID:
"+ prodId +"" +
- "<br/>" +
- " B BY BURTON ALPHA<br/>" +
- "Sale Price: $314.96 " +
- "</div>");
- }
- if (prodId.equals("2")){
- writer.print("<div id=\"product-text\">Product ID:
"+ prodId +"" +
- "<br/>" +
- "FORUM DESTROYER LTD<br/>" +
- "$319.99 " +
- "</div>");
- }
- if (prodId.equals("3")){
- writer.print("<div id=\"product-text\">Product ID:
"+ prodId +"" +
- "<br/>" +
- "\n" +
- "SANTA CRUZ ALLSTAR<br/>" +
- "$256.00 " +
- "</div>");
- }
-
- }
-
-
-
-
- writer.close();
- }
-}