Author: trong.tran
Date: 2010-09-10 08:00:21 -0400 (Fri, 10 Sep 2010)
New Revision: 4145
Modified:
portal/branches/navcontroller/portlet/web/src/main/webapp/groovy/portal/webui/component/UIPortalNavigation.gtmpl
portal/branches/navcontroller/web/portal/src/main/webapp/groovy/webui/core/UISitemapTree.gtmpl
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestHandler.java
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/url/PortalURL.java
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplication.java
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplicationLifecycle.java
Log:
Change/Improve PortalURL to generate the same URI in both ajax and non ajax url
Modified:
portal/branches/navcontroller/portlet/web/src/main/webapp/groovy/portal/webui/component/UIPortalNavigation.gtmpl
===================================================================
---
portal/branches/navcontroller/portlet/web/src/main/webapp/groovy/portal/webui/component/UIPortalNavigation.gtmpl 2010-09-10
09:17:55 UTC (rev 4144)
+++
portal/branches/navcontroller/portlet/web/src/main/webapp/groovy/portal/webui/component/UIPortalNavigation.gtmpl 2010-09-10
12:00:21 UTC (rev 4145)
@@ -79,10 +79,8 @@
label = entityEncoder.encode(label);
nodeURL.setResource(node);
- String nonAjaxURL = nodeURL.setParameters(null).setAjax(false).toString();
- if(uicomponent.isUseAjax()){
- nodeURL.setParameters(new Parameter(PortalRequestContext.TARGET_NODE,
node.getUri()));
- }
+ String nonAjaxURL = nodeURL.setAjax(false).toString();
+ String ajaxURL = nodeURL.setAjax(true).toString();
String pageURI = Util.getPortalRequestContext().getPortalURI() + node.getUri();
if(node.pageReference != null) {
@@ -93,7 +91,7 @@
<div class="ItemIcon $icon">
""";
if(uicomponent.isUseAjax()) {
- print "<a href=\"" + nonAjaxURL + "\"
onclick=\"" + nodeURL.setAjax(true).toString() + "; return
false;\">$label</a>";
+ print "<a href=\"" + nonAjaxURL + "\"
onclick=\"" + ajaxURL + "; return false;\">$label</a>";
} else {
print "<a href=\"" + nonAjaxURL +
"\">$label</a>"
}
@@ -166,12 +164,12 @@
label=entityEncoder.encode(label);
if(node.pageReference != null) {
nodeURL.setResource(node);
- String nonAjaxURL =
nodeURL.setParameters(null).setAjax(false).toString();
+ String nonAjaxURL =
nodeURL.setAjax(false).toString();
+ String ajaxURL = nodeURL.setAjax(true).toString();
if(uicomponent.isUseAjax()) {
- nodeURL.setParameters(new
Parameter(PortalRequestContext.TARGET_NODE, node.getUri()));
%>
- <a class="TabLabel ${iconType}"
onclick="<%=nodeURL.setAjax(true).toString()%>; return false;"
href="$nonAjaxURL">$label</a>
+ <a class="TabLabel ${iconType}"
onclick="$ajaxURL; return false;"
href="$nonAjaxURL">$label</a>
<%
} else {
%>
Modified:
portal/branches/navcontroller/web/portal/src/main/webapp/groovy/webui/core/UISitemapTree.gtmpl
===================================================================
---
portal/branches/navcontroller/web/portal/src/main/webapp/groovy/webui/core/UISitemapTree.gtmpl 2010-09-10
09:17:55 UTC (rev 4144)
+++
portal/branches/navcontroller/web/portal/src/main/webapp/groovy/webui/core/UISitemapTree.gtmpl 2010-09-10
12:00:21 UTC (rev 4145)
@@ -20,6 +20,7 @@
def actionCollapseAll = uicomponent.event("CollapseAllNode");
ResourceURL nodeURL =
pcontext.createURL(org.exoplatform.portal.url.navigation.NavigationLocator.TYPE);
+ nodeURL.setAjax(true);
public void renderNodes(TreeNode rootTree, ResourceURL nodeURL, boolean useAjax) {
List childrenNodes=rootTree.getChildren();
@@ -36,13 +37,7 @@
actionExpand = uicomponent.event("ExpandNode", nav.getId() + "::"
+ node.getUri());
def actionCollapse = "ajaxAsyncGetRequest('" +
uicomponent.url("CollapseNode",nav.getId() + "::" + node.getUri()) +
"', true)";
- if(useAjax){
- nodeURL.setAjax(true);
- nodeURL.setParameters(new Parameter(PortalRequestContext.TARGET_NODE,
node.getUri()));
- } else {
- nodeURL.setResource(node);
- }
- actionLink = nodeURL.toString();
+ String actionLink = nodeURL.setResource(node).toString();
lastNode = '';
@@ -58,7 +53,7 @@
<div class="CollapseIcon ClearFix"
onclick="eXo.portal.UIPortal.collapseExpand(this);$actionCollapse">
""";
if(treeNode.getNode().getPageReference() == null) println "<a
class='NodeIcon DefaultPageIcon'
href='javascript:void(0);'>$label</a>";
- else println "<a class='NodeIcon DefaultPageIcon'
href='$actionLink'>$label</a>";
+ else println "<a class='NodeIcon DefaultPageIcon'
href=\"$actionLink\">$label</a>";
println """
</div>
<div class="ChildrenContainer" style="display: block">
@@ -72,7 +67,7 @@
<div class="ExpandIcon ClearFix"
onclick="if(eXo.portal.UIPortal.collapseExpand(this)){$actionExpand}">
""";
if(treeNode.getNode().getPageReference() == null) println "<a
class='NodeIcon DefaultPageIcon'
href='javascript:void(0);'>$label</a>";
- else println "<a class='NodeIcon DefaultPageIcon'
href='$actionLink'>$label</a>";
+ else println "<a class='NodeIcon DefaultPageIcon'
href=\"$actionLink\">$label</a>";
println """
</div>
<div class="ChildrenContainer" style="display: none">
@@ -100,7 +95,7 @@
}
}
- }
+ }
%>
<div id="UISiteMap" class="UISitemap" >
Modified:
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java
===================================================================
---
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java 2010-09-10
09:17:55 UTC (rev 4144)
+++
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestContext.java 2010-09-10
12:00:21 UTC (rev 4145)
@@ -86,7 +86,7 @@
final static public String UI_COMPONENT_ACTION = "portal:action";
final static public String UI_COMPONENT_ID = "portal:componentId";
-
+
final static public String TARGET_NODE = "portal:targetNode";
final static public String CACHE_LEVEL = "portal:cacheLevel";
@@ -124,11 +124,11 @@
private final PortalURLBuilder urlBuilder;
private Map<String, String[]> parameterMap;
-
+
private Locale locale = Locale.ENGLISH;
private PageNavigation targetNav;
-
+
private PageNode targetNode_;
/** . */
@@ -233,7 +233,7 @@
@Override
public <R, L extends ResourceLocator<R>> ResourceURL<R, L>
newURL(ResourceType<R, L> resourceType, L locator)
{
- return new PortalURL<R,L>(this, locator, false);
+ return new PortalURL<R, L>(this, locator, false);
}
public void refreshResourceBundle() throws Exception
@@ -282,52 +282,6 @@
return locatorFactory;
}
- /**
- *
- *
- * Process current Portal Request URI. if current require uri is not equal to last one
then
- * an event of type UIPortalApplication.CHANGE_NODE will be retuned, otherwise it
returns <code>null</code>
- *
- * @return
- * @throws Exception
- */
- public Event<UIComponent> lookChangeNodeEvent() throws Exception
- {
- UIPortalApplication uiPortalApp = (UIPortalApplication)uiApplication_;
- List<PageNavigation> navigations = uiPortalApp.getNavigations();
-
- String lastNodePath = uiPortalApp.getLastNodePath();
- String nodePath;
- // Do not need to process if the request uri is not changed from last one
- // Or look if this is a change node event in Ajax
- if(nodePath_.equals(lastNodePath))
- {
- nodePath = request_.getParameter(PortalRequestContext.TARGET_NODE);
- if (nodePath == null)
- {
- return null;
- }
- }
- else
- {
- uiPortalApp.setLastNodePath(nodePath_);
- nodePath = nodePath_;
- }
-
- Object[] targets = Util.findBestMatchNavigationAndNode(navigations, nodePath);
- if(targets == null)
- {
- targetNav = navigations.get(0);
- targetNode_ = Util.findFirstAvailableNode(targetNav, this);
- }
- else
- {
- targetNav = (PageNavigation)targets[0];
- targetNode_ = (PageNode)targets[1];
- }
- return uiPortalApp.createEvent(PageNodeEvent.CHANGE_NODE, Event.Phase.PROCESS,
this);
- }
-
public Orientation getOrientation()
{
return ((UIPortalApplication)uiApplication_).getOrientation();
@@ -442,11 +396,11 @@
return targetNode_;
}
- public void setTargetNode(PageNode naviNode)
+ public void setTargetNode(PageNode targetNode)
{
- targetNode_ = naviNode;
+ targetNode_ = targetNode;
}
-
+
public URLBuilder<UIComponent> getURLBuilder()
{
return urlBuilder;
Modified:
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestHandler.java
===================================================================
---
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestHandler.java 2010-09-10
09:17:55 UTC (rev 4144)
+++
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/application/PortalRequestHandler.java 2010-09-10
12:00:21 UTC (rev 4145)
@@ -108,12 +108,6 @@
if (uiApp != null)
{
uiApp.processDecode(context);
-
- Event<UIComponent> changeNodeEvent = context.lookChangeNodeEvent();
- if(changeNodeEvent != null)
- {
- changeNodeEvent.broadcast();
- }
}
if (!context.isResponseComplete() && !context.getProcessRender())
Modified:
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/url/PortalURL.java
===================================================================
---
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/url/PortalURL.java 2010-09-10
09:17:55 UTC (rev 4144)
+++
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/url/PortalURL.java 2010-09-10
12:00:21 UTC (rev 4145)
@@ -82,32 +82,25 @@
//
StringBuilder url = new StringBuilder();
- if (ajax)
+ if (locator.getResource() == null)
{
- url.append(requestContext.getRequestURI());
+ throw new IllegalStateException("No resource set of the portal URL");
}
- else
+
+ //
+ url.append(requestContext.getPortalURI());
+
+ //
+ try
{
- if (locator.getResource() == null)
- {
- throw new IllegalStateException("No resource set of the portal
URL");
- }
-
- //
- url.append(requestContext.getPortalURI());
-
- //
- try
- {
- locator.append(url);
- }
- catch (IOException e)
- {
- AssertionError ae = new AssertionError();
- ae.initCause(e);
- throw ae;
- }
+ locator.append(url);
}
+ catch (IOException e)
+ {
+ AssertionError ae = new AssertionError();
+ ae.initCause(e);
+ throw ae;
+ }
if (ajax || params != null)
{
Modified:
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplication.java
===================================================================
---
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplication.java 2010-09-10
09:17:55 UTC (rev 4144)
+++
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplication.java 2010-09-10
12:00:21 UTC (rev 4145)
@@ -19,21 +19,18 @@
package org.exoplatform.portal.webui.workspace;
-import org.exoplatform.container.ExoContainer;
import org.exoplatform.portal.Constants;
import org.exoplatform.portal.application.PortalRequestContext;
import org.exoplatform.portal.config.DataStorage;
-import org.exoplatform.portal.config.NoSuchDataException;
import org.exoplatform.portal.config.UserPortalConfig;
-import org.exoplatform.portal.config.UserPortalConfigService;
import org.exoplatform.portal.config.model.Container;
-import org.exoplatform.portal.config.model.Page;
import org.exoplatform.portal.config.model.PageNavigation;
import org.exoplatform.portal.config.model.PageNode;
import org.exoplatform.portal.resource.Skin;
import org.exoplatform.portal.resource.SkinConfig;
import org.exoplatform.portal.resource.SkinService;
import org.exoplatform.portal.resource.SkinURL;
+import org.exoplatform.portal.url.navigation.NavigationLocator;
import org.exoplatform.portal.webui.application.UIPortlet;
import org.exoplatform.portal.webui.navigation.PageNavigationUtils;
import org.exoplatform.portal.webui.page.UIPageActionListener.ChangeNodeActionListener;
@@ -51,6 +48,7 @@
import org.exoplatform.services.resources.Orientation;
import org.exoplatform.services.resources.ResourceBundleManager;
import org.exoplatform.web.application.javascript.JavascriptConfigService;
+import org.exoplatform.web.url.ResourceURL;
import org.exoplatform.webui.application.WebuiRequestContext;
import org.exoplatform.webui.config.annotation.ComponentConfig;
import org.exoplatform.webui.config.annotation.EventConfig;
@@ -59,7 +57,6 @@
import org.exoplatform.webui.core.UIComponentDecorator;
import org.exoplatform.webui.core.UIContainer;
import org.exoplatform.webui.event.Event;
-import org.exoplatform.webui.event.Event.Phase;
import java.io.Writer;
import java.util.ArrayList;
@@ -120,6 +117,10 @@
private UIPortal showedUIPortal;
+ private boolean isAjaxInLastRequest;
+
+ private String lastNonAjaxUri;
+
/**
* The constructor of this class is used to build the tree of UI components
* that will be aggregated in the portal page.<br/>
@@ -507,24 +508,90 @@
uiContainer.setStorageId(container.getStorageId());
PortalDataMapper.toUIContainer(uiContainer, container);
UISiteBody uiSiteBody = uiContainer.findFirstComponentOfType(UISiteBody.class);
- //uiSiteBody.setUIComponent(uiPortal);
uiSiteBody.setUIComponent(this.showedUIPortal);
uiContainer.setRendered(true);
uiViewWS.setUIComponent(uiContainer);
}
else
{
- //uiViewWS.setUIComponent(uiPortal);
uiViewWS.setUIComponent(this.showedUIPortal);
}
- // uiWorkingWorkspace.addChild(UIPortalToolPanel.class, null,
- // null).setRendered(false);
- // editInlineWS.addChild(UIPortalToolPanel.class, null,
- // null).setRendered(false);
addChild(UIMaskWorkspace.class, UIPortalApplication.UI_MASK_WS_ID, null);
}
/**
+ * The processDecode() method is doing 3 actions: <br/>
+ * 1) if this is a non ajax request and the last is an ajax one,
+ * then we check if the requested nodePath is equal to last non ajax nodePath and
+ * is not equal to the last nodePath, the server performs a 302 redirect on the last
nodePath.<br/>
+ * 2) if the nodePath exist but is equals to the current one
+ * then we also call super and stops here.<br/>
+ * 3) if the requested nodePath is not equals to the current one or current
+ * page no longer exists, then an event of type PageNodeEvent.CHANGE_NODE
+ * is sent to the associated EventListener; a call to super is then done.
+ */
+ @Override
+ public void processDecode(WebuiRequestContext context) throws Exception
+ {
+ PortalRequestContext pcontext = (PortalRequestContext)context;
+ String nodePath = pcontext.getNodePath();
+ boolean isAjax = pcontext.useAjax();
+
+ if (!isAjax)
+ {
+ if (isAjaxInLastRequest)
+ {
+ isAjaxInLastRequest = false;
+ if (nodePath.equals(lastNonAjaxUri) &&
!nodePath.equals(lastNodePath))
+ {
+ ResourceURL<PageNode, NavigationLocator> nodeURL =
+
pcontext.createURL(org.exoplatform.portal.url.navigation.NavigationLocator.TYPE);
+ nodeURL.setResource(getShowedUIPortal().getSelectedNode());
+ pcontext.sendRedirect(nodeURL.toString());
+ return;
+ }
+ }
+ lastNonAjaxUri = nodePath;
+ }
+
+ isAjaxInLastRequest = isAjax;
+
+ if (!nodePath.equals(lastNodePath))
+ {
+ lastNodePath = nodePath;
+
+ List<PageNavigation> navigations = getNavigations();
+
+ Object[] targets = Util.findBestMatchNavigationAndNode(navigations, nodePath);
+ PageNavigation targetNav;
+ PageNode targetNode;
+ if (targets == null)
+ {
+ targetNav = navigations.get(0);
+ targetNode = Util.findFirstAvailableNode(targetNav, pcontext);
+ }
+ else
+ {
+ targetNav = (PageNavigation)targets[0];
+ targetNode = (PageNode)targets[1];
+ }
+
+ pcontext.setTargetNav(targetNav);
+ pcontext.setTargetNode(targetNode);
+
+ Event<UIComponent> changeNodeEvent =
createEvent(PageNodeEvent.CHANGE_NODE, Event.Phase.PROCESS, pcontext);
+ changeNodeEvent.broadcast();
+ }
+
+ if (!isAjax)
+ {
+ lastNonAjaxUri = nodePath;
+ }
+
+ super.processDecode(pcontext);
+ }
+
+ /**
* The processrender() method handles the creation of the returned HTML
* either for a full page render or in the case of an AJAX call The first
* request, Ajax is not enabled (means no ajaxRequest parameter in the
@@ -681,31 +748,6 @@
{
this.userPortalConfig_ = userPortalConfig;
}
-
- private boolean isPageExist() throws Exception
- {
- WebuiRequestContext context = Util.getPortalRequestContext();
- ExoContainer appContainer =
context.getApplication().getApplicationServiceContainer();
- UserPortalConfigService userPortalConfigService =
-
(UserPortalConfigService)appContainer.getComponentInstanceOfType(UserPortalConfigService.class);
- Page page = null;
- PageNode pageNode = Util.getUIPortal().getSelectedNode();
- if (pageNode != null)
- {
- try
- {
- if (pageNode.getPageReference() != null)
- {
- page = userPortalConfigService.getPage(pageNode.getPageReference(),
context.getRemoteUser());
- }
- }
- catch (NoSuchDataException nsde)
- {
- return false;
- }
- }
- return (page != null);
- }
public void localizeNavigations()
{
Modified:
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplicationLifecycle.java
===================================================================
---
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplicationLifecycle.java 2010-09-10
09:17:55 UTC (rev 4144)
+++
portal/branches/navcontroller/webui/portal/src/main/java/org/exoplatform/portal/webui/workspace/UIPortalApplicationLifecycle.java 2010-09-10
12:00:21 UTC (rev 4145)
@@ -46,8 +46,13 @@
if (uiTarget == null)
return;
if (uiTarget == uicomponent)
- super.processDecode(uicomponent, context);
- uiTarget.processDecode(context);
+ {
+ super.processDecode(uicomponent, context);
+ }
+ else
+ {
+ uiTarget.processDecode(context);
+ }
}
/**