Author: sohil.shah(a)jboss.com
Date: 2008-01-15 22:11:23 -0500 (Tue, 15 Jan 2008)
New Revision: 9521
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/listener/
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/listener/AnchorListener.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/listener/ListenerUtil.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/listener/SubmitListener.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/protocol/AsyncGetAction.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/protocol/AsyncPostAction.java
Removed:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/protocol/AsyncActivateAction.java
Modified:
branches/presentation/
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/MyGWTPrototype.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/Portal.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/Session.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/Util.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/protocol/AjaxUpdateWindowStateAction.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/service/PortalRPC.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/service/PortalRPCAsync.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/widget/PortletWindow.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/client/controller/UIController.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/ajax/entry/GWTClientFilter.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/ajax/entry/PortalEntryPoint.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ManagedObject.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/protocol/GetActivation.java
branches/presentation/presentation/src/main/org/jboss/portal/presentation/protocol/PostActivation.java
branches/presentation/presentation/src/resources/client/ajax/src/org/jboss/portal/presentation/ajax/public/mygwt.html
Log:
Ajax User Agent - improved event processing after testing for JSF support
Property changes on: branches/presentation
___________________________________________________________________
Name: svn:ignore
- thirdparty
.classpath
.project
.settings
core-samples
cms
core-admin
core-cms
search
workflow
+ thirdparty
.classpath
.project
.settings
core-samples
cms
core-admin
core-cms
search
workflow
presentation-samples
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/MyGWTPrototype.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/MyGWTPrototype.java 2008-01-15
23:52:11 UTC (rev 9520)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/MyGWTPrototype.java 2008-01-16
03:11:23 UTC (rev 9521)
@@ -23,9 +23,15 @@
package org.jboss.portal.presentation.ajax.client;
import com.google.gwt.core.client.EntryPoint;
+import com.google.gwt.user.client.DOM;
+import com.google.gwt.user.client.Element;
+import com.google.gwt.user.client.Event;
+import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.HTML;
+import com.google.gwt.user.client.ui.Widget;
+import com.google.gwt.core.client.JavaScriptObject;
import net.mygwt.ui.client.Style;
import net.mygwt.ui.client.event.BaseEvent;
@@ -42,6 +48,9 @@
*/
public class MyGWTPrototype implements EntryPoint
{
+ private static JavaScriptObject originalSubmitFunction = null;
+ private static JavaScriptObject overrideSubmitFunction = null;
+
/**
*
*/
@@ -51,8 +60,9 @@
RootPanel.get("currentPage").add(panel);
// Fillup panel with MyGWT widgets for testing
- this.createButtonWidget(panel);
- this.createPortletWindowWidget(panel);
+ //this.createButtonWidget(panel);
+ //this.createPortletWindowWidget(panel);
+ this.loadTestHTML(panel);
}
/**
@@ -111,4 +121,206 @@
panel.add(contentPanel);
}
+
+ /**
+ *
+ * @param panel
+ */
+ private void loadTestHTML(VerticalPanel panel)
+ {
+ this.originalSubmitFunction = this.getOriginalSubmitFunction();
+ this.overrideSubmitFunction = this.getOverRideSubmitFunction();
+ this.overwriteSubmit(this.overrideSubmitFunction);
+
+ this.startClickListener();
+
+ HTML html = new HTML("<div class='window-normal-button'>" +
+ "<form id='testform' method='post'
action='http://www.google.com'>" +
+ "<input type=\"hidden\"
name=\"j_id_jsp_1600481012_9\" value=\"j_id_jsp_1600481012_9\"
/>" +
+ "<input type='Button' value='Hello
World'
onclick='document.getElementById(\"testform\").submit();'>" +
+ "<br/>" +
+ "<span><a href='#'
onclick='document.getElementById(\"testform\").submit();'
class='portlet-font'>Test Command Link</a></span>" +
+ "<br/>" +
+ "<a href='http://www.google.com'
class='portlet-font'><span>Test Plain Link</span></a>"
+
+ "<br/>" +
+ "<input type='submit'>" +
+ "</form>" +
+ "</div>");
+
+ ContentPanel contentPanel = new ContentPanel(Style.HEADER);
+ contentPanel.add(html);
+ contentPanel.setSize(200, 200);
+
+ //html.addClickListener(new ContentListener());
+
+ panel.add(contentPanel);
+ }
+
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
+ /**
+ *
+ * @param currentForm
+ * @return
+ */
+ public static native JavaScriptObject getOriginalSubmitFunction()
+ /*-{
+ return $wnd.HTMLFormElement.prototype.submit;
+ }-*/;
+
+ /**
+ *
+ * @param currentForm
+ * @return
+ */
+ public static native JavaScriptObject getOverRideSubmitFunction()
+ /*-{
+ function overrideSubmit(event)
+ {
+ var target = null;
+ if(event != null)
+ {
+ target = event.target;
+
@org.jboss.portal.presentation.ajax.client.MyGWTPrototype::submitCallback(Lcom/google/gwt/user/client/Event;Lcom/google/gwt/user/client/Element;)(event,target);
+ }
+ else
+ {
+ target = this;
+
@org.jboss.portal.presentation.ajax.client.MyGWTPrototype::submitCallback(Lcom/google/gwt/user/client/Element;)(target);
+ }
+ }
+ return overrideSubmit;
+ }-*/;
+
+ /**
+ *
+ * @param currentForm
+ * @return
+ */
+ public static native void overwriteSubmit(JavaScriptObject overrideSubmitFunction)
+ /*-{
+ $wnd.addEventListener('submit', overrideSubmitFunction, true);
+ $wnd.HTMLFormElement.prototype.submit = overrideSubmitFunction;
+ }-*/;
+
+ /**
+ *
+ * @param currentForm
+ * @return
+ */
+ public static native void forceSubmit(JavaScriptObject originalSubmitFunction,
JavaScriptObject overrideSubmitFunction, JavaScriptObject form)
+ /*-{
+ $wnd.HTMLFormElement.prototype.submit = originalSubmitFunction;
+ form.submit();
+ $wnd.HTMLFormElement.prototype.submit = overrideSubmitFunction;
+ }-*/;
+
+ /**
+ *
+ * @param currentForm
+ * @return
+ */
+ public static native String serializeForm(Element currentForm)
+ /*-{
+ var formData = $wnd.Form.serialize(currentForm);
+ return formData;
+ }-*/;
+
+ /**
+ *
+ *
+ */
+ public static void submitCallback(Event event, Element currentForm)
+ {
+ String action = DOM.getElementAttribute(currentForm, "action");
+ String method = DOM.getElementAttribute(currentForm, "method");
+ String enctype = DOM.getElementAttribute(currentForm, "enctype");
+ String serializedForm = serializeForm(currentForm);
+
+ /*System.out.println("---------------------------------------------");
+ System.out.println(event);
+ System.out.println(action);
+ System.out.println(method);
+ System.out.println(enctype);
+ System.out.println(serializedForm);*/
+
+ DOM.eventPreventDefault(event);
+
+ //Force a submit
+ forceSubmit(originalSubmitFunction, overrideSubmitFunction, currentForm);
+ }
+
+ /**
+ *
+ *
+ */
+ public static void submitCallback(Element currentForm)
+ {
+ String action = DOM.getElementAttribute(currentForm, "action");
+ String method = DOM.getElementAttribute(currentForm, "method");
+ String enctype = DOM.getElementAttribute(currentForm, "enctype");
+ String serializedForm = serializeForm(currentForm);
+
+ /*System.out.println("---------------------------------------------");
+ System.out.println(action);
+ System.out.println(method);
+ System.out.println(enctype);
+ System.out.println(serializedForm);*/
+
+ //Force a submit
+ forceSubmit(originalSubmitFunction, overrideSubmitFunction, currentForm);
+ }
+ //--------Testing Anchor click
listener----------------------------------------------------------------------------------------------------------------
+ /**
+ *
+ * @param currentForm
+ * @return
+ */
+ public static native void startClickListener()
+ /*-{
+ function listenClick(event)
+ {
+ if(event != null)
+ {
+
@org.jboss.portal.presentation.ajax.client.MyGWTPrototype::clickCallback(Lcom/google/gwt/user/client/Event;Lcom/google/gwt/user/client/Element;)(event,event.target);
+ }
+ else
+ {
+
@org.jboss.portal.presentation.ajax.client.MyGWTPrototype::clickCallback(Lcom/google/gwt/user/client/Element;)(this);
+ }
+ }
+ $wnd.addEventListener('click', listenClick, true);
+ }-*/;
+
+ /**
+ *
+ * @param target
+ */
+ public static void clickCallback(Event event, Element target)
+ {
+ if(target.toString().toUpperCase().trim().indexOf("</A>") != -1
&& DOM.getElementAttribute(target, "ONCLICK") == null)
+ {
+ DOM.eventPreventDefault(event);
+ System.out.println(target);
+ }
+ }
+
+ public static void clickCallback(Element target)
+ {
+ if(target.toString().toUpperCase().trim().indexOf("</A>") != -1
&& DOM.getElementAttribute(target, "ONCLICK") == null)
+ {
+ System.out.println(target);
+ }
+ }
+
//--------------------------------------------------------------------------------------------------------------------------------------------------------------
+ /**
+ *
+ */
+ /*private class ContentListener implements ClickListener
+ {
+ public void onClick(Widget sender)
+ {
+ Event event = DOM.eventGetCurrentEvent();
+ Element target = DOM.eventGetTarget(event);
+ System.out.println(target);
+ }
+ }*/
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/Portal.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/Portal.java 2008-01-15
23:52:11 UTC (rev 9520)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/Portal.java 2008-01-16
03:11:23 UTC (rev 9521)
@@ -24,9 +24,10 @@
import com.google.gwt.core.client.EntryPoint;
-import org.jboss.portal.presentation.ajax.client.model.AjaxUIPage;
import org.jboss.portal.presentation.ajax.client.protocol.Caller;
import org.jboss.portal.presentation.ajax.client.protocol.AjaxViewUIObjectAction;
+import org.jboss.portal.presentation.ajax.client.listener.SubmitListener;
+import org.jboss.portal.presentation.ajax.client.listener.AnchorListener;
/**
* This is the Entry Point of the client-side Ajax agent of the Presentation Framework
@@ -44,6 +45,9 @@
//Load the default page of the default portal upon loading the user agent
AjaxViewUIObjectAction action = new
AjaxViewUIObjectAction("/default/default");
action.execute(this);
+
+ Session.getInstance().setSubmitListener(new SubmitListener());
+ Session.getInstance().setAnchorListener(new AnchorListener());
}
/**
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/Session.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/Session.java 2008-01-15
23:52:11 UTC (rev 9520)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/Session.java 2008-01-16
03:11:23 UTC (rev 9521)
@@ -26,6 +26,8 @@
import java.util.HashMap;
import org.jboss.portal.presentation.ajax.client.model.AjaxUIContext;
+import org.jboss.portal.presentation.ajax.client.listener.SubmitListener;
+import org.jboss.portal.presentation.ajax.client.listener.AnchorListener;
/**
* This is the client side Session. This is a singleton since there should only be one
session for each client
@@ -51,6 +53,16 @@
private AjaxUIContext uiContext = null;
/**
+ *
+ */
+ private SubmitListener submitListener = null;
+
+ /**
+ *
+ */
+ private AnchorListener anchorListener = null;
+
+ /**
* @gwt.typeArgs <java.lang.String, java.lang.Object>
*/
private Map attributes = null;
@@ -98,6 +110,42 @@
/**
*
+ * @return
+ */
+ public SubmitListener getSubmitListener()
+ {
+ return submitListener;
+ }
+
+ /**
+ *
+ * @param progSubmitListener
+ */
+ public void setSubmitListener(SubmitListener submitListener)
+ {
+ this.submitListener = submitListener;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public AnchorListener getAnchorListener()
+ {
+ return anchorListener;
+ }
+
+ /**
+ *
+ * @param anchorListener
+ */
+ public void setAnchorListener(AnchorListener anchorListener)
+ {
+ this.anchorListener = anchorListener;
+ }
+
+ /**
+ *
* @param attributeKey
* @param value
*/
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/Util.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/Util.java 2008-01-15
23:52:11 UTC (rev 9520)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/Util.java 2008-01-16
03:11:23 UTC (rev 9521)
@@ -35,7 +35,7 @@
*
*/
public class Util
-{
+{
/**
*
* @param portalPage
@@ -81,9 +81,9 @@
//layout the page and its corresponding windows
LayoutManager.doLayout(displayWindows);
- }
+ }
}
-
+
/**
*
* @param portalPage
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/listener/AnchorListener.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/listener/AnchorListener.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/listener/AnchorListener.java 2008-01-16
03:11:23 UTC (rev 9521)
@@ -0,0 +1,91 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, 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.presentation.ajax.client.listener;
+
+import com.google.gwt.user.client.DOM;
+import com.google.gwt.user.client.Element;
+import com.google.gwt.user.client.Event;
+import com.google.gwt.user.client.ui.Widget;
+import com.google.gwt.user.client.ui.ClickListener;
+
+import org.jboss.portal.presentation.ajax.client.Util;
+import org.jboss.portal.presentation.ajax.client.protocol.AsyncGetAction;
+import org.jboss.portal.presentation.ajax.client.protocol.Caller;
+
+/**
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ *
+ */
+public class AnchorListener implements Caller, ClickListener
+{
+ /**
+ *
+ * @param callback
+ */
+ public AnchorListener()
+ {
+ }
+ //-------ClickListener
impl------------------------------------------------------------------------------------------------------------------------
+ /**
+ *
+ */
+ public void onClick(Widget sender)
+ {
+ Event event = DOM.eventGetCurrentEvent();
+ Element target = DOM.eventGetTarget(event);
+
+ //Process normal click
+ if(target.toString().toUpperCase().trim().indexOf("</A>") != -1
&& DOM.getElementAttribute(target, "ONCLICK") == null)
+ {
+ String link = DOM.getElementAttribute(target, "HREF");
+
+ //A link inside the portlet window was clicked
+ //Load its content asynchronously inside this window
+ boolean isPartialRefreshAllowed =
ListenerUtil.isPartialRefreshAllowed(link.trim());
+ if(isPartialRefreshAllowed)
+ {
+ DOM.eventPreventDefault(event);
+ handlePartialRefreshLink(link.trim());
+ }
+ }
+ }
+
//------------------------------------------------------------------------------------------------------------------------------------------------------
+ /**
+ *
+ * @param url
+ * @param portletWindow
+ */
+ private void handlePartialRefreshLink(String url)
+ {
+ AsyncGetAction action = new AsyncGetAction(url);
+ action.execute(this);
+ }
+ //----Caller
impl---------------------------------------------------------------------------------------------------------------------------------------------------------
+ /**
+ *
+ */
+ public void callback(Object result)
+ {
+ Util.displayPortalPage();
+ }
+}
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/listener/ListenerUtil.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/listener/ListenerUtil.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/listener/ListenerUtil.java 2008-01-16
03:11:23 UTC (rev 9521)
@@ -0,0 +1,115 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, 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.presentation.ajax.client.listener;
+
+import com.google.gwt.core.client.GWT;
+
+/**
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ *
+ */
+public class ListenerUtil
+{
+ /**
+ *
+ * @param url
+ * @return
+ */
+ public static boolean isPartialRefreshAllowed(String url)
+ {
+ String basePortalURL = GWT.getModuleBaseURL();
+
+ /**
+ * TODO: This is hard coded for now, but must be populated from the Portal
deployment environment
+ * If Portal is installed at Root context, this value will be an empty string
+ */
+ String portalContext = "presentation";
+
+ //Make sure this is not just an anchor link with real submission in the onclick
event
+ if(url.length() == 0 || url.startsWith("#"))
+ {
+ return false;
+ }
+
+ if(url.startsWith(basePortalURL))
+ {
+ //This is an Absolute URL, but it points back to
+ //the Portal
+ //An Async Page Refresh call should be allowed in this case
+ return true;
+ }
+
+ if(url.startsWith("http://"))
+ {
+ //This is an Absolute URL and does not point back
+ //to the Portal
+ //Async Page Refresh call should not be allowed
+ return false;
+ }
+ else
+ {
+ //This is a relative URL.
+
+ //Make sure it points back to the Portal for an Async Page Refresh
+ //If it points to some other resource like another third-party web application
etc, the response
+ //has nothing to do with Portal
+ //(unless ofcourse the client side processor of the Portal, wants to
+ //take this response and aggregate this inside the current Portal Page and
Window being displayed. This is an exceptional usecase
+ //and not desired behavior for every scenario from end user standpoint)
+ //As standard behavior, Async Page Refresh to be done, only when Portlet Markup
is sending a request back to the Portal
+ if(url.startsWith("/"))
+ {
+ if(!portalContext.equals(""))
+ {
+ String urlContext = null;
+ int index = url.indexOf('/', 1);
+ if(index != -1)
+ {
+ urlContext = url.substring(1, index);
+ }
+ else
+ {
+ urlContext = url.substring(1);
+ }
+
+ if(!portalContext.equals(urlContext))
+ {
+ //This request is not being sent to the Portal. It is being sent to
some other web application
+ return false;
+ }
+ }
+ else
+ {
+ //If Portal is running on root context, there is no way to tell from
client side, if this request is actually
+ //to be sent to the Portal or some other web application. Hence, in the
interest of functional safety/correctness
+ //no Async Page Refresh here
+ //If Portal is running on Root context, Partial Refresh will happen only
for pure relative links
+ return false;
+ }
+ }
+
+ //If I get here, Async Page Refresh through the Portal should be allowed
+ return true;
+ }
+ }
+}
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/listener/SubmitListener.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/listener/SubmitListener.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/listener/SubmitListener.java 2008-01-16
03:11:23 UTC (rev 9521)
@@ -0,0 +1,174 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, 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.presentation.ajax.client.listener;
+
+import com.google.gwt.core.client.JavaScriptObject;
+import com.google.gwt.user.client.DOM;
+import com.google.gwt.user.client.Element;
+import com.google.gwt.user.client.Event;
+
+import org.jboss.portal.presentation.ajax.client.Util;
+import org.jboss.portal.presentation.ajax.client.Session;
+import org.jboss.portal.presentation.ajax.client.protocol.AsyncPostAction;
+import org.jboss.portal.presentation.ajax.client.protocol.Caller;
+
+/**
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ *
+ */
+public class SubmitListener implements Caller
+{
+ private JavaScriptObject originalSubmitFunction = null;
+ private JavaScriptObject overrideSubmitFunction = null;
+
+ /**
+ *
+ *
+ */
+ public SubmitListener()
+ {
+ this.originalSubmitFunction = this.getOriginalSubmitFunction();
+ this.overrideSubmitFunction = this.getOverRideSubmitFunction();
+ this.overwriteSubmit(this.overrideSubmitFunction);
+ }
+
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
+ /**
+ *
+ *
+ */
+ public static void submitCallback(Event event, Element currentForm)
+ {
+ DOM.eventPreventDefault(event);
+ SubmitListener.submitCallback(currentForm);
+ }
+
+ /**
+ *
+ *
+ */
+ public static void submitCallback(Element currentForm)
+ {
+ Session.getInstance().getSubmitListener().handlePartialRefreshForm(currentForm);
+ }
+
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
+ /**
+ *
+ * @param url
+ * @param portletWindow
+ */
+ private void handlePartialRefreshForm(Element currentForm)
+ {
+ String url = DOM.getElementAttribute(currentForm, "action");
+ String method = DOM.getElementAttribute(currentForm, "method");
+ String enctype = DOM.getElementAttribute(currentForm, "enctype");
+ String postData = serializeForm(currentForm);
+
+ boolean isPartialRefreshAllowed =
ListenerUtil.isPartialRefreshAllowed(url.trim());
+ if((isPartialRefreshAllowed) && (enctype == null ||
!enctype.equals("multipart/form-data")))
+ {
+ AsyncPostAction action = new AsyncPostAction(url, postData);
+ action.execute(this);
+ }
+ else
+ {
+ //Go ahead and perform a regular form submit
+ this.forceSubmit(originalSubmitFunction, overrideSubmitFunction, currentForm);
+ }
+ }
+ //----Caller
impl---------------------------------------------------------------------------------------------------------------------------------------------------------
+ /**
+ *
+ */
+ public void callback(Object result)
+ {
+ Util.displayPortalPage();
+ }
+ //---low-level native Javascripts
layer------------------------------------------------------------------------------------------------------------------------
+ /**
+ *
+ * @param currentForm
+ * @return
+ */
+ public native JavaScriptObject getOriginalSubmitFunction()
+ /*-{
+ return $wnd.HTMLFormElement.prototype.submit;
+ }-*/;
+
+ /**
+ *
+ * @param currentForm
+ * @return
+ */
+ public native JavaScriptObject getOverRideSubmitFunction()
+ /*-{
+ function overrideSubmit(event)
+ {
+ var target = null;
+ if(event != null)
+ {
+ target = event.target;
+
@org.jboss.portal.presentation.ajax.client.listener.SubmitListener::submitCallback(Lcom/google/gwt/user/client/Event;Lcom/google/gwt/user/client/Element;)(event,target);
+ }
+ else
+ {
+ target = this;
+
@org.jboss.portal.presentation.ajax.client.listener.SubmitListener::submitCallback(Lcom/google/gwt/user/client/Element;)(target);
+ }
+ }
+ return overrideSubmit;
+ }-*/;
+
+ /**
+ *
+ * @param currentForm
+ * @return
+ */
+ public native void overwriteSubmit(JavaScriptObject overrideSubmitFunction)
+ /*-{
+ $wnd.addEventListener('submit', overrideSubmitFunction, true);
+ $wnd.HTMLFormElement.prototype.submit = overrideSubmitFunction;
+ }-*/;
+
+ /**
+ *
+ * @param currentForm
+ * @return
+ */
+ public native void forceSubmit(JavaScriptObject originalSubmitFunction,
JavaScriptObject overrideSubmitFunction, JavaScriptObject form)
+ /*-{
+ $wnd.HTMLFormElement.prototype.submit = originalSubmitFunction;
+ form.submit();
+ $wnd.HTMLFormElement.prototype.submit = overrideSubmitFunction;
+ }-*/;
+
+ /**
+ *
+ * @param currentForm
+ * @return
+ */
+ public static native String serializeForm(Element currentForm)
+ /*-{
+ var formData = $wnd.Form.serialize(currentForm);
+ return formData;
+ }-*/;
+}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/protocol/AjaxUpdateWindowStateAction.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/protocol/AjaxUpdateWindowStateAction.java 2008-01-15
23:52:11 UTC (rev 9520)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/protocol/AjaxUpdateWindowStateAction.java 2008-01-16
03:11:23 UTC (rev 9521)
@@ -85,9 +85,8 @@
* TODO: Handle exception properly
*/
}
- };
- Map queryParams = new HashMap();
- queryParams.put("windowstate", this.windowState);
- portalRPC.asyncActivate(this.getTargetId(), queryParams, callback);
+ };
+ String url = this.getTargetId() + "?" + "windowstate=" +
this.windowState;
+ portalRPC.asyncGet(url, callback);
}
}
Deleted:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/protocol/AsyncActivateAction.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/protocol/AsyncActivateAction.java 2008-01-15
23:52:11 UTC (rev 9520)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/protocol/AsyncActivateAction.java 2008-01-16
03:11:23 UTC (rev 9521)
@@ -1,90 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, 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.presentation.ajax.client.protocol;
-
-import org.jboss.portal.presentation.ajax.client.Session;
-import org.jboss.portal.presentation.ajax.client.model.AjaxUIObject;
-import org.jboss.portal.presentation.ajax.client.model.AjaxUIPage;
-import org.jboss.portal.presentation.ajax.client.service.PortalRPC;
-import org.jboss.portal.presentation.ajax.client.service.PortalRPCAsync;
-
-import java.util.Map;
-import java.util.HashMap;
-
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.user.client.rpc.AsyncCallback;
-import com.google.gwt.user.client.rpc.ServiceDefTarget;
-
-/**
- * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
- *
- */
-public class AsyncActivateAction extends ClientAction
-{
- /**
- *
- */
- private String url = null;
-
- /**
- *
- * @param targetId
- */
- public AsyncActivateAction(String url)
- {
- this.url = url;
- }
-
- /**
- *
- */
- public void execute(final Caller caller)
- {
- PortalRPCAsync portalRPC = (PortalRPCAsync)GWT.create(PortalRPC.class);
-
((ServiceDefTarget)portalRPC).setServiceEntryPoint(GWT.getModuleBaseURL()+"/portalrpc");
- AsyncCallback callback = new AsyncCallback()
- {
- public void onSuccess(Object result)
- {
- if(result instanceof AjaxShowUIObjectResponse)
- {
- AjaxUIObject uiObject = ((AjaxShowUIObjectResponse)result).getUiObject();
- Session.getInstance().getUiContext().addObject(uiObject);
- if(uiObject instanceof AjaxUIPage)
- {
- Session.getInstance().setAttribute(Session.display, uiObject.getId());
- }
- caller.callback(uiObject);
- }
- }
-
- public void onFailure(Throwable caught)
- {
- /**
- * TODO: Handle exception properly
- */
- }
- };
- portalRPC.asyncActivate(this.url, callback);
- }
-}
Copied:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/protocol/AsyncGetAction.java
(from rev 9447,
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/protocol/AsyncActivateAction.java)
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/protocol/AsyncGetAction.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/protocol/AsyncGetAction.java 2008-01-16
03:11:23 UTC (rev 9521)
@@ -0,0 +1,90 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, 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.presentation.ajax.client.protocol;
+
+import org.jboss.portal.presentation.ajax.client.Session;
+import org.jboss.portal.presentation.ajax.client.model.AjaxUIObject;
+import org.jboss.portal.presentation.ajax.client.model.AjaxUIPage;
+import org.jboss.portal.presentation.ajax.client.service.PortalRPC;
+import org.jboss.portal.presentation.ajax.client.service.PortalRPCAsync;
+
+import java.util.Map;
+import java.util.HashMap;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.google.gwt.user.client.rpc.ServiceDefTarget;
+
+/**
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ *
+ */
+public class AsyncGetAction extends ClientAction
+{
+ /**
+ *
+ */
+ private String url = null;
+
+ /**
+ *
+ * @param targetId
+ */
+ public AsyncGetAction(String url)
+ {
+ this.url = url;
+ }
+
+ /**
+ *
+ */
+ public void execute(final Caller caller)
+ {
+ PortalRPCAsync portalRPC = (PortalRPCAsync)GWT.create(PortalRPC.class);
+
((ServiceDefTarget)portalRPC).setServiceEntryPoint(GWT.getModuleBaseURL()+"/portalrpc");
+ AsyncCallback callback = new AsyncCallback()
+ {
+ public void onSuccess(Object result)
+ {
+ if(result instanceof AjaxShowUIObjectResponse)
+ {
+ AjaxUIObject uiObject = ((AjaxShowUIObjectResponse)result).getUiObject();
+ Session.getInstance().getUiContext().addObject(uiObject);
+ if(uiObject instanceof AjaxUIPage)
+ {
+ Session.getInstance().setAttribute(Session.display, uiObject.getId());
+ }
+ caller.callback(uiObject);
+ }
+ }
+
+ public void onFailure(Throwable caught)
+ {
+ /**
+ * TODO: Handle exception properly
+ */
+ }
+ };
+ portalRPC.asyncGet(this.url, callback);
+ }
+}
Added:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/protocol/AsyncPostAction.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/protocol/AsyncPostAction.java
(rev 0)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/protocol/AsyncPostAction.java 2008-01-16
03:11:23 UTC (rev 9521)
@@ -0,0 +1,92 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, 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.presentation.ajax.client.protocol;
+
+import org.jboss.portal.presentation.ajax.client.Session;
+import org.jboss.portal.presentation.ajax.client.model.AjaxUIObject;
+import org.jboss.portal.presentation.ajax.client.model.AjaxUIPage;
+import org.jboss.portal.presentation.ajax.client.service.PortalRPC;
+import org.jboss.portal.presentation.ajax.client.service.PortalRPCAsync;
+
+import java.util.Map;
+import java.util.HashMap;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.google.gwt.user.client.rpc.ServiceDefTarget;
+
+/**
+ * @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
+ *
+ */
+public class AsyncPostAction extends ClientAction
+{
+ /**
+ *
+ */
+ private String url = null;
+ private String body = null;
+
+ /**
+ *
+ * @param targetId
+ */
+ public AsyncPostAction(String url, String body)
+ {
+ this.url = url;
+ this.body = body;
+ }
+
+ /**
+ *
+ */
+ public void execute(final Caller caller)
+ {
+ PortalRPCAsync portalRPC = (PortalRPCAsync)GWT.create(PortalRPC.class);
+
((ServiceDefTarget)portalRPC).setServiceEntryPoint(GWT.getModuleBaseURL()+"/portalrpc");
+ AsyncCallback callback = new AsyncCallback()
+ {
+ public void onSuccess(Object result)
+ {
+ if(result instanceof AjaxShowUIObjectResponse)
+ {
+ AjaxUIObject uiObject = ((AjaxShowUIObjectResponse)result).getUiObject();
+ Session.getInstance().getUiContext().addObject(uiObject);
+ if(uiObject instanceof AjaxUIPage)
+ {
+ Session.getInstance().setAttribute(Session.display, uiObject.getId());
+ }
+ caller.callback(uiObject);
+ }
+ }
+
+ public void onFailure(Throwable caught)
+ {
+ /**
+ * TODO: Handle exception properly
+ */
+ }
+ };
+ portalRPC.asyncPost(this.url, this.body, callback);
+ }
+}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/service/PortalRPC.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/service/PortalRPC.java 2008-01-15
23:52:11 UTC (rev 9520)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/service/PortalRPC.java 2008-01-16
03:11:23 UTC (rev 9521)
@@ -43,19 +43,14 @@
public ClientResponse loadObject(String objectId);
/**
- * Asynchronously send a UI activation to the Portal Server
- *
- * @param uiObjectId
- * @gwt.typeArgs queryParams <java.lang.String, java.lang.String>
- * @return
+ * Asynchronously send a UI Get Activation to the Portal Server
+ *
*/
- public ClientResponse asyncActivate(String uiObjectId, Map queryParams);
+ public ClientResponse asyncGet(String url);
/**
- * Asynchronously send a UI activation to the Portal Server
- *
- * @param url
- * @return
+ * Asynchronously send a UI Post activation to the Portal Server
+ *
*/
- public ClientResponse asyncActivate(String url);
+ public ClientResponse asyncPost(String url, String body);
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/service/PortalRPCAsync.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/service/PortalRPCAsync.java 2008-01-15
23:52:11 UTC (rev 9520)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/service/PortalRPCAsync.java 2008-01-16
03:11:23 UTC (rev 9521)
@@ -40,19 +40,14 @@
public void loadObject(String objectId, AsyncCallback callback);
/**
- * Asynchronously send a UI activation to the Portal Server
- *
- * @param uiObjectId
- * @gwt.typeArgs queryParams <java.lang.String, java.lang.String>
- * @param callback
+ * Asynchronously send a UI Get Activation to the Portal Server
+ *
*/
- public void asyncActivate(String uiObjectId, Map queryParams, AsyncCallback
callback);
+ public void asyncGet(String url, AsyncCallback callback);
/**
- * Asynchronously send a UI activation to the Portal Server
- *
- * @param url
- * @param callback
+ * Asynchronously send a UI Post activation to the Portal Server
+ *
*/
- public void asyncActivate(String url, AsyncCallback callback);
+ public void asyncPost(String url, String body, AsyncCallback callback);
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/widget/PortletWindow.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/widget/PortletWindow.java 2008-01-15
23:52:11 UTC (rev 9520)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/ajax/client/widget/PortletWindow.java 2008-01-16
03:11:23 UTC (rev 9521)
@@ -22,13 +22,7 @@
******************************************************************************/
package org.jboss.portal.presentation.ajax.client.widget;
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.user.client.DOM;
-import com.google.gwt.user.client.Element;
-import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.HTML;
-import com.google.gwt.user.client.ui.ClickListener;
-import com.google.gwt.user.client.ui.Widget;
import net.mygwt.ui.client.widget.ContentPanel;
import net.mygwt.ui.client.Style;
@@ -40,10 +34,8 @@
import org.jboss.portal.presentation.ajax.client.Util;
import org.jboss.portal.presentation.ajax.client.Session;
import org.jboss.portal.presentation.ajax.client.model.AjaxUIWindow;
-import org.jboss.portal.presentation.ajax.client.model.AjaxUIPage;
import org.jboss.portal.presentation.ajax.client.protocol.AjaxUpdateWindowStateAction;
import org.jboss.portal.presentation.ajax.client.protocol.Caller;
-import org.jboss.portal.presentation.ajax.client.protocol.AsyncActivateAction;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
@@ -137,151 +129,20 @@
portletWindow.add(windowContent);
//Event Listener for actions perfomed inside the portlet window content
- //itself. Used for performing Partial Refresh of a Portal Page
- ClickListener contentListener = new ContentListener();
- windowContent.addClickListener(contentListener);
+ //itself. Used for performing Partial Refresh of a Portal Page
+ windowContent.addClickListener(Session.getInstance().getAnchorListener());
}
return portletWindow;
}
-
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
+ //----Caller
impl---------------------------------------------------------------------------------------------------------------------------------------------------------
/**
*
*/
public void callback(Object result)
{
Util.displayPortalPage();
- }
-
- /**
- *
- *
- */
- private void refresh()
- {
- String display = (String)Session.getInstance().getAttribute(Session.display);
- AjaxUIPage displayedPage =
(AjaxUIPage)Session.getInstance().getUiContext().getObject(display);
-
- this.window = (AjaxUIWindow)displayedPage.getChild(this.getName());
- }
-
-
//-------------------------------------------------------------------------------------------------------------------------------------------------------------
- /**
- *
- * @param url
- * @param portletWindow
- */
- private void handlePartialRefreshLink(String url, Widget windowContent)
- {
- AsyncActivateAction action = new AsyncActivateAction(url);
- action.execute(this);
- }
-
- /**
- *
- * @param url
- * @param portletWindow
- */
- private void handlePartialRefreshForm(String url, String method, String postData,
Widget windowContent)
- {
- if(postData != null && postData.trim().length() > 0)
- {
- if(url.indexOf('?') == -1)
- {
- url = url + "?" + postData;
- }
- else
- {
- url = url + "&" + postData;
- }
- }
- AsyncActivateAction action = new AsyncActivateAction(url);
- action.execute(this);
- }
-
- /**
- *
- * @param url
- * @return
- */
- private boolean isPartialRefreshAllowed(String url)
- {
- String basePortalURL = GWT.getModuleBaseURL();
- String portalContext = "presentation"; //This is hard coded for now, but
must be populated from the Portal deployment environment
- //If Portal is installed at Root context, this value will be an empty string
-
- if(url.startsWith(basePortalURL))
- {
- //This is an Absolute URL, but it points back to
- //the Portal
- //An Async Page Refresh call should be allowed in this case
- return true;
- }
-
- if(url.startsWith("http://"))
- {
- //This is an Absolute URL and does not point back
- //to the Portal
- //Async Page Refresh call should not be allowed
- return false;
- }
- else
- {
- //This is a relative URL.
-
- //Make sure it points back to the Portal for an Async Page Refresh
- //If it points to some other resource like another third-party web application
etc, the response
- //has nothing to do with Portal
- //(unless ofcourse the client side processor of the Portal, wants to
- //take this response and aggregate this inside the current Portal Page and
Window being displayed. This is an exceptional usecase
- //and not desired behavior for every scenario from end user standpoint)
- //As standard behavior, Async Page Refresh to be done, only when Portlet Markup
is sending a request back to the Portal
- if(url.startsWith("/"))
- {
- if(!portalContext.equals(""))
- {
- String urlContext = null;
- int index = url.indexOf('/', 1);
- if(index != -1)
- {
- urlContext = url.substring(1, index);
- }
- else
- {
- urlContext = url.substring(1);
- }
-
- if(!portalContext.equals(urlContext))
- {
- //This request is not being sent to the Portal. It is being sent to
some other web application
- return false;
- }
- }
- else
- {
- //If Portal is running on root context, there is no way to tell from
client side, if this request is actually
- //to be sent to the Portal or some other web application. Hence, in the
interest of functional safety/correctness
- //no Async Page Refresh here
- //If Portal is running on Root context, Partial Refresh will happen only
for pure relative links
- return false;
- }
- }
-
- //If I get here, Async Page Refresh through the Portal should be allowed
- return true;
- }
- }
-
- /**
- *
- * @param currentForm
- * @return
- */
- public native String serializeForm(Element currentForm)
- /*-{
- var formData = $wnd.Form.serialize(currentForm);
- return formData;
- }-*/;
+ }
//-----------------------------------------------------------------------------------------------------------------------------------------------------
/**
*
@@ -340,50 +201,5 @@
Info.show("Help", "Loading Help Mode....", "Loading
Help Mode....");
}
}
- }
-
- /**
- *
- */
- private class ContentListener implements ClickListener
- {
- public void onClick(Widget sender)
- {
- Event event = DOM.eventGetCurrentEvent();
- Element target = DOM.eventGetTarget(event);
-
- if(target.toString().toUpperCase().trim().indexOf("</A>") !=
-1)
- {
- String link = DOM.getElementAttribute(target, "HREF");
-
- //A link inside the portlet window was clicked
- //Load its content asynchronously inside this window
- boolean isPartialRefreshAllowed = isPartialRefreshAllowed(link.trim());
- if(isPartialRefreshAllowed)
- {
- DOM.eventPreventDefault(event);
- handlePartialRefreshLink(link.trim(), sender);
- }
- }
- else if(target.toString().toUpperCase().trim().indexOf("INPUT") != -1
&&
- target.toString().toUpperCase().trim().indexOf("SUBMIT") !=
-1
- )
- {
- Element currentForm = DOM.getParent(target);
- String enctype = DOM.getElementAttribute(currentForm, "enctype");
- String action = DOM.getElementAttribute(currentForm, "action");
- boolean isPartialRefreshAllowed = isPartialRefreshAllowed(action.trim());
- if((isPartialRefreshAllowed) && (enctype == null ||
!enctype.equals("multipart/form-data")))
- {
- DOM.eventPreventDefault(event);
-
- //Call a native javascript function here
- String method = DOM.getElementAttribute(currentForm, "method");
- String serializedForm = serializeForm(currentForm);
-
- handlePartialRefreshForm(action.trim(), method, serializedForm, sender);
- }
- }
- }
- }
+ }
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/client/controller/UIController.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/client/controller/UIController.java 2008-01-15
23:52:11 UTC (rev 9520)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/client/controller/UIController.java 2008-01-16
03:11:23 UTC (rev 9521)
@@ -49,6 +49,7 @@
import java.io.PrintWriter;
import java.util.List;
import java.util.Collection;
+import java.util.Map;
/**
* The UIServer is responsible for generating the output that is sent back to the client
based on the Portal state of a particular Portal Request
@@ -180,14 +181,16 @@
{
ServerInvocationContext invocationContext = invocation.getServerContext();
String requestPath = invocation.getServerContext().getPortalRequestPath();
+ WebRequest webReq =
((ServerInvocationContextImpl)invocation.getContext()).getWebRequest();
+ Map queryParameters = webReq.getQueryParameterMap();
//
- if (requestPath.startsWith("/invoke/"))
+ if (queryParameters != null &&
queryParameters.containsKey("action"))
{
UIObject target = presentationContext.getUIContext();
//
- int from = "/invoke/".length();
+ int from = 1;
while (true)
{
int pos = requestPath.indexOf('/', from);
@@ -207,11 +210,8 @@
break;
}
from = pos + 1;
- }
+ }
- // I know but it will go away later when we remove dependency on server module
- WebRequest webReq =
((ServerInvocationContextImpl)invocation.getContext()).getWebRequest();
-
//
if (target != null)
{
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/ajax/entry/GWTClientFilter.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/ajax/entry/GWTClientFilter.java 2008-01-15
23:52:11 UTC (rev 9520)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/ajax/entry/GWTClientFilter.java 2008-01-16
03:11:23 UTC (rev 9521)
@@ -22,6 +22,9 @@
******************************************************************************/
package org.jboss.portal.presentation.impl.ajax.entry;
+import java.util.Map;
+import java.util.Enumeration;
+import java.util.HashMap;
import java.io.IOException;
import java.io.InputStream;
import java.io.ByteArrayOutputStream;
@@ -35,6 +38,9 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.jboss.portal.presentation.protocol.GetActivation;
+import org.jboss.portal.presentation.protocol.PostActivation;
+
/**
* This filter is activated or deactivated depending on whether the Portal needs to runs
in Ajax mode or Classic Html mode
*
@@ -105,6 +111,35 @@
response.getOutputStream().flush();
return;
}
+
+
+ String method = request.getMethod();
+ String url = request.getRequestURL().toString();
+ String targetId = this.parseTargetId(url);
+ Map queryParameters = new HashMap();
+ Enumeration paramNames = request.getParameterNames();
+ if(paramNames != null)
+ {
+ while(paramNames.hasMoreElements())
+ {
+ String name = (String)paramNames.nextElement();
+ String value = (String)request.getParameter(name);
+ queryParameters.put(name, new String[]{value});
+ }
+ }
+ if(method.equalsIgnoreCase("get"))
+ {
+ GetActivation get = new GetActivation(targetId, queryParameters);
+ request.getSession().setAttribute("serverAction", get);
+ }
+ else
+ {
+ PostActivation post = new PostActivation(targetId, queryParameters, null);
+ request.getSession().setAttribute("serverAction", post);
+ }
+
+
+ response.sendRedirect(contextPath+"/"+"index.html");
}
/**
@@ -151,4 +186,26 @@
return content;
}
+
+ /**
+ *
+ * @param url
+ * @return
+ */
+ private String parseTargetId(String url)
+ {
+ String targetId = null;
+
+ int fromIndex = 0; //hard coding the portal deployment context for now
+ fromIndex = url.indexOf("presentation") != -1 ?
url.indexOf("presentation") + "presentation".length() : 0;
+ targetId = url.indexOf('?') != -1 ? url.substring(fromIndex,
url.indexOf('?')):url.substring(fromIndex);
+
+ //Removes the PATH data if any found
+ if(targetId.indexOf(';')!=-1)
+ {
+ targetId = targetId.substring(0, targetId.indexOf(';'));
+ }
+
+ return targetId;
+ }
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/ajax/entry/PortalEntryPoint.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/ajax/entry/PortalEntryPoint.java 2008-01-15
23:52:11 UTC (rev 9520)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/ajax/entry/PortalEntryPoint.java 2008-01-16
03:11:23 UTC (rev 9521)
@@ -2,8 +2,6 @@
import java.util.Map;
-import java.util.List;
-import java.util.Iterator;
import java.util.StringTokenizer;
import java.util.HashMap;
import java.net.URLDecoder;
@@ -35,15 +33,10 @@
import org.jboss.portal.presentation.ajax.client.service.PortalRPC;
import org.jboss.portal.presentation.ajax.client.model.AjaxUIObject;
-import org.jboss.portal.presentation.ajax.client.model.AjaxUIPage;
-import org.jboss.portal.presentation.ajax.client.model.AjaxUIContext;
-import org.jboss.portal.presentation.ajax.client.model.AjaxUIPortal;
-import org.jboss.portal.presentation.ajax.client.model.Page;
-import org.jboss.portal.presentation.ajax.client.model.Window;
import org.jboss.portal.presentation.ajax.client.protocol.ClientResponse;
import org.jboss.portal.presentation.ajax.client.protocol.AjaxShowUIObjectResponse;
-import org.jboss.portal.presentation.server.ProcessorResponse;
import org.jboss.portal.presentation.protocol.GetActivation;
+import org.jboss.portal.presentation.protocol.PostActivation;
import com.google.gwt.user.client.rpc.SerializationException;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
@@ -130,48 +123,57 @@
{
try
{
- AjaxUIObject uiObject = null;
+ ClientResponse clientResponse = null;
HttpServletRequest request = this.getThreadLocalRequest();
+ Object pendingServerAction =
request.getSession().getAttribute("serverAction");
+ if(pendingServerAction != null)
+ {
+ request.setAttribute("serverAction", pendingServerAction);
+ request.getSession().removeAttribute("serverAction");
+ }
+
//execute the call on the Portal
this.callPortalServer();
//Setup the initial UIContext for the client session
- uiObject = (AjaxUIObject)request.getAttribute("uiObject");
+ AjaxUIObject uiObject =
(AjaxUIObject)request.getAttribute("uiObject");
+ if(uiObject != null)
+ {
+ clientResponse = new AjaxShowUIObjectResponse(uiObject);
+ }
- return new AjaxShowUIObjectResponse(uiObject);
+ return clientResponse;
}
catch(Exception e)
{
throw new RuntimeException(e);
}
}
-
+
/**
*
- * @param objectId
- * @param windowState
+ * @param url
* @return
*/
- public ClientResponse asyncActivate(String uiObjectId, Map queryParams)
+ public ClientResponse asyncGet(String url)
{
try
{
ClientResponse clientResponse = null;
-
+
HttpServletRequest request = this.getThreadLocalRequest();
-
- Map params = new HashMap();
- for(Iterator itr=queryParams.keySet().iterator(); itr.hasNext();)
- {
- String key = (String)itr.next();
- String value = (String)queryParams.get(key);
- params.put(key, new String[]{value});
- }
- GetActivation get = new GetActivation(uiObjectId, params);
+ //Parse the query parameters into a Map of name value pairs
+ Map queryParams = this.parseQueryParams(url);
+ //Parse the UIObject target id
+ String targetId = this.parseTargetId(url);
+
+
+ GetActivation get = new GetActivation(targetId, queryParams);
+
request.setAttribute("serverAction", get);
//execute the call on the Portal
@@ -195,52 +197,106 @@
/**
*
* @param url
+ * @param body
* @return
*/
- public ClientResponse asyncActivate(String url)
+ public ClientResponse asyncPost(String url, String body)
{
try
{
- Map queryParams = new HashMap();
+ ClientResponse clientResponse = null;
+
+ HttpServletRequest request = this.getThreadLocalRequest();
+
+ //Parse the query parameters into a Map of name value pairs
+ Map queryParams = this.parseQueryParams(url);
- //Parse the query parameters into a Map of name value pairs
- if(url.indexOf('?') != -1)
+ //Parse the UIObject target id
+ String targetId = this.parseTargetId(url);
+
+ //Parse the serialized post body into parameters
+ StringTokenizer st = new StringTokenizer(body, "&");
+ while(st.hasMoreTokens())
{
- String queryString = url.substring(url.indexOf('?')+1);
- StringTokenizer st = new StringTokenizer(queryString, "&");
- while(st.hasMoreTokens())
- {
- String token = st.nextToken();
- int equalIndex = token.indexOf('=');
- String name = token.substring(0, equalIndex);
- String value = token.substring(equalIndex+1);
- queryParams.put(name, URLDecoder.decode(value, "UTF-8"));
- }
+ String token = st.nextToken();
+ int equalIndex = token.indexOf('=');
+ String name = token.substring(0, equalIndex);
+ String value = token.substring(equalIndex+1);
+
+ queryParams.put(URLDecoder.decode(name, "UTF-8"), new
String[]{URLDecoder.decode(value, "UTF-8")});
}
+
+ PostActivation post = new PostActivation(targetId, queryParams, null);
- //Parse the UIObject id
- String uiObjectId = null;
- int invokeIndex = url.indexOf("presentation"); //hard coding the
portal deployment context for now
- int endIndex = url.indexOf('?');
- if(endIndex != -1)
+ request.setAttribute("serverAction", post);
+
+ //execute the call on the Portal
+ this.callPortalServer();
+
+ //Setup the initial UIContext for the client session
+ AjaxUIObject uiObject =
(AjaxUIObject)request.getAttribute("uiObject");
+ if(uiObject != null)
{
- uiObjectId = url.substring(invokeIndex+"presentation".length(),
endIndex);
+ clientResponse = new AjaxShowUIObjectResponse(uiObject);
}
- else
- {
- uiObjectId = url.substring(invokeIndex+"presentation".length());
- }
- return this.asyncActivate(uiObjectId, queryParams);
+ return clientResponse;
}
catch(Exception e)
{
throw new RuntimeException(e);
}
}
-
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------
+
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------
/**
*
+ */
+ private Map parseQueryParams(String url) throws Exception
+ {
+ Map queryParams = new HashMap();
+
+ if(url.indexOf('?') != -1)
+ {
+ String queryString = url.substring(url.indexOf('?')+1);
+ StringTokenizer st = new StringTokenizer(queryString, "&");
+ while(st.hasMoreTokens())
+ {
+ String token = st.nextToken();
+ int equalIndex = token.indexOf('=');
+ String name = token.substring(0, equalIndex);
+ String value = token.substring(equalIndex+1);
+
+ queryParams.put(name, new String[]{URLDecoder.decode(value,
"UTF-8")});
+ }
+ }
+
+ return queryParams;
+ }
+
+ /**
+ *
+ * @param url
+ * @return
+ */
+ private String parseTargetId(String url)
+ {
+ String targetId = null;
+
+ int fromIndex = 0; //hard coding the portal deployment context for now
+ fromIndex = url.indexOf("presentation") != -1 ?
url.indexOf("presentation") + "presentation".length() : 0;
+ targetId = url.indexOf('?') != -1 ? url.substring(fromIndex,
url.indexOf('?')):url.substring(fromIndex);
+
+ //Removes the PATH data if any found
+ if(targetId.indexOf(';')!=-1)
+ {
+ targetId = targetId.substring(0, targetId.indexOf(';'));
+ }
+
+ return targetId;
+ }
+
+ /**
+ *
*
*/
private void callPortalServer() throws Exception
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ManagedObject.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ManagedObject.java 2008-01-15
23:52:11 UTC (rev 9520)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/impl/model/container/ManagedObject.java 2008-01-16
03:11:23 UTC (rev 9521)
@@ -250,10 +250,18 @@
}
//
- for (UIContainerObject child : getChildren())
+ Collection<UIContainerObject> children = getChildren();
+ for (UIContainerObject child : children)
{
- if (child.getName().equals(name))
+ String childName = child.getName();
+ if(childName == null)
{
+ String id = child.getId();
+ childName = id.substring(id.lastIndexOf('/')+1);
+ }
+
+ if (childName.equals(name))
+ {
return child;
}
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/protocol/GetActivation.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/protocol/GetActivation.java 2008-01-15
23:52:11 UTC (rev 9520)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/protocol/GetActivation.java 2008-01-16
03:11:23 UTC (rev 9521)
@@ -23,6 +23,7 @@
package org.jboss.portal.presentation.protocol;
import java.util.Map;
+import java.util.Iterator;
/**
* @author <a href="mailto:sshah@redhat.com">Sohil Shah</a>
@@ -34,4 +35,25 @@
{
super(targetId, queryParameters);
}
+
+ /**
+ *
+ */
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer();
+
+ if(this.queryParameters != null)
+ {
+ buffer.append("QueryString---------------\n");
+ for(Iterator itr=this.queryParameters.keySet().iterator(); itr.hasNext();)
+ {
+ String key = (String)itr.next();
+ String[] value = (String[])this.queryParameters.get(key);
+ buffer.append(key+"="+value[0]+"\n");
+ }
+ }
+
+ return buffer.toString();
+ }
}
Modified:
branches/presentation/presentation/src/main/org/jboss/portal/presentation/protocol/PostActivation.java
===================================================================
---
branches/presentation/presentation/src/main/org/jboss/portal/presentation/protocol/PostActivation.java 2008-01-15
23:52:11 UTC (rev 9520)
+++
branches/presentation/presentation/src/main/org/jboss/portal/presentation/protocol/PostActivation.java 2008-01-16
03:11:23 UTC (rev 9521)
@@ -24,6 +24,7 @@
import org.jboss.portal.web.Body;
+import java.util.Iterator;
import java.util.Map;
/**
@@ -52,4 +53,33 @@
{
return body;
}
+
+ public String toString()
+ {
+ StringBuffer buffer = new StringBuffer();
+
+ if(this.queryParameters != null)
+ {
+ buffer.append("QueryString---------------\n");
+ for(Iterator itr=this.queryParameters.keySet().iterator(); itr.hasNext();)
+ {
+ String key = (String)itr.next();
+ String[] value = (String[])this.queryParameters.get(key);
+ buffer.append(key+"="+value[0]+"\n");
+ }
+ }
+
+ if(this.body != null && ((Body.Form)this.body).getParameters() != null)
+ {
+ buffer.append("PostBody---------------\n");
+ for(Iterator itr=((Body.Form)this.body).getParameters().keySet().iterator();
itr.hasNext();)
+ {
+ String key = (String)itr.next();
+ String[] value = ((Body.Form)this.body).getParameters().get(key);
+ buffer.append(key+"="+value[0]+"\n");
+ }
+ }
+
+ return buffer.toString();
+ }
}
Modified:
branches/presentation/presentation/src/resources/client/ajax/src/org/jboss/portal/presentation/ajax/public/mygwt.html
===================================================================
---
branches/presentation/presentation/src/resources/client/ajax/src/org/jboss/portal/presentation/ajax/public/mygwt.html 2008-01-15
23:52:11 UTC (rev 9520)
+++
branches/presentation/presentation/src/resources/client/ajax/src/org/jboss/portal/presentation/ajax/public/mygwt.html 2008-01-16
03:11:23 UTC (rev 9521)
@@ -10,6 +10,7 @@
<!-- If you add any GWT meta tags, they must -->
<!-- be added before this line. -->
<!-- -->
+ <script language='javascript'
src='prototype.js'></script>
<script language='javascript'
src='org.jboss.portal.presentation.ajax.MyGWT.nocache.js'></script>
</head>