Author: wesleyhales
Date: 2008-10-07 22:08:38 -0400 (Tue, 07 Oct 2008)
New Revision: 12046
Added:
branches/JBoss_Portal_Branch_2_7/core-samples/src/resources/portal-basic-samples-war/WEB-INF/jsp/ajax/
branches/JBoss_Portal_Branch_2_7/core-samples/src/resources/portal-basic-samples-war/WEB-INF/jsp/ajax/repeatrefresh.jsp
Modified:
branches/JBoss_Portal_Branch_2_7/core-samples/src/main/org/jboss/portal/core/samples/basic/RepeatRefreshPortlet.java
Log:
RepeatRefresh demo cleanup and dispatch to JSP
Modified:
branches/JBoss_Portal_Branch_2_7/core-samples/src/main/org/jboss/portal/core/samples/basic/RepeatRefreshPortlet.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core-samples/src/main/org/jboss/portal/core/samples/basic/RepeatRefreshPortlet.java 2008-10-07
19:36:55 UTC (rev 12045)
+++
branches/JBoss_Portal_Branch_2_7/core-samples/src/main/org/jboss/portal/core/samples/basic/RepeatRefreshPortlet.java 2008-10-08
02:08:38 UTC (rev 12046)
@@ -36,6 +36,8 @@
import javax.portlet.PortletSecurityException;
import javax.portlet.PortletURL;
import javax.portlet.PortletMode;
+import javax.portlet.PortletRequestDispatcher;
+import javax.portlet.PortletContext;
/**
* @author <a href="mailto:whales@redhat.com">Wesley Hales</a>
@@ -43,11 +45,7 @@
*/
public class RepeatRefreshPortlet 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;
+ private static final String JSP_PATH = "/WEB-INF/jsp/ajax";
public void processAction(ActionRequest req, ActionResponse resp) throws
PortletException, PortletSecurityException, IOException
{
@@ -55,67 +53,22 @@
String repeatText = req.getParameter("repeat");
// set the text from form input
if (repeatText != null){
- resp.setRenderParameter("repeat", repeatText);
+ resp.setRenderParameter("repeat", repeatText);
}
// request view
resp.setPortletMode(PortletMode.VIEW);
}
- public void render(RenderRequest req, RenderResponse resp) throws PortletException,
IOException
+ public void render(RenderRequest renderRequest, RenderResponse renderResponse) throws
PortletException, IOException
{
- ResourceURL resourceURL = resp.createResourceURL();
- PortletURL actionURL = resp.createActionURL();
+ //ResourceURL resourceURL = renderResponse.createResourceURL();
+ //PortletURL actionURL = renderResponse.createActionURL();
- resp.setContentType("text/html");
- PrintWriter writer = resp.getWriter();
- writer.print("" +
- "<script type=\"text/javascript\">" +
- "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>");
- 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>");
+ PortletContext context = getPortletContext();
+ //renderResponse.setContentType("text/html");
+ PortletRequestDispatcher rd = context.getRequestDispatcher(JSP_PATH +
"/repeatrefresh.jsp");
+ rd.include(renderRequest, renderResponse);
}
-
public void serveResource(ResourceRequest req, ResourceResponse resp) throws
PortletException, IOException
{
String repeatText = req.getParameter("repeat");
Added:
branches/JBoss_Portal_Branch_2_7/core-samples/src/resources/portal-basic-samples-war/WEB-INF/jsp/ajax/repeatrefresh.jsp
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core-samples/src/resources/portal-basic-samples-war/WEB-INF/jsp/ajax/repeatrefresh.jsp
(rev 0)
+++
branches/JBoss_Portal_Branch_2_7/core-samples/src/resources/portal-basic-samples-war/WEB-INF/jsp/ajax/repeatrefresh.jsp 2008-10-08
02:08:38 UTC (rev 12046)
@@ -0,0 +1,65 @@
+<%@ page import="javax.portlet.PortletURL" %>
+<%@ page import="javax.portlet.ResourceURL" %>
+<%@ taglib
uri="http://java.sun.com/portlet" prefix="portlet"
%>
+
+<portlet:defineObjects/>
+<%
+ResourceURL resourceURL = renderResponse.createResourceURL();
+%>
+<script type="text/javascript">
+ function ajaxRequest(url,target,params,highlightTarget)
+ {
+ new Ajax.Updater(target, url, {method: 'GET', asynchronous:true,
parameters:params});
+
+ if(highlightTarget){
+ new Effect.Highlight(document.getElementById(target));
+ }
+
+ }
+</script>
+
+
+<div class='full-width' style='padding:5px'>
+ <h4>Partial Refresh Repeater Demo</h4>
+
+ <div class='half-width float-left'>
+ <form method='post' id="testrepeatform"
name="testrepeatform" action="<portlet:actionURL/>"
+
onsubmit="ajaxRequest('<%=resourceURL%>','repeat-div',Form.serialize(this),true);
return false;">
+ <font class='portlet-font'>Repeat Demo:</font><br/>
+ <input class='portlet-form-input-field' type='text'
value='' size='12' name="repeat" id="repeat"
+ onkeyup="this.form.submit2.click();"/>
+ <input class='portlet-form-input-field hidden' type='submit'
name='submit2' value='submit'>
+ </form>
+ </div>
+
+ <div id="repeat-container">
+ <div id="repeat-div" class='half-width float-left'
style='height:50px'></div>
+ </div>
+
+ <br/><br/>
+ <hr/>
+ <h4>Partial Refresh Product Catalog</h4>
+
+ <div class='full-width'>
+
+ <div class='float-left third-width'>
+
+ <!--Here we set the parameters on the URL via the ajax request-->
+ <a href="javascript:
ajaxRequest('<%=resourceURL%>','output-div','prodId=1',true);">Product1</a><br/>
+
+ <!--For the next 2, we use the resourceURL to set the params-->
+ <%resourceURL.setParameter("prodId","2");%>
+ <a href="javascript:
ajaxRequest('<%=resourceURL%>','output-div','',true);">Product2</a><br/>
+ <%resourceURL.setParameter("prodId","3");%>
+ <a href="javascript:
ajaxRequest('<%=resourceURL%>','output-div','',true);">Product3</a><br/>
+
+ <br class='clear'/></div>
+
+ <div class='float-left two-third-width'>
+ <h4 class='zero'>Product Details</h4>
+
+ <div id="output-div"></div>
+
+ <br class='clear'/></div>
+ </div>
+</div>
\ No newline at end of file