diff --git a/source/java/org/alfresco/web/app/servlet/FacesHelper.java b/source/java/org/alfresco/web/app/servlet/FacesHelper.java
index 701ac2b0f2..32c5c917e5 100644
--- a/source/java/org/alfresco/web/app/servlet/FacesHelper.java
+++ b/source/java/org/alfresco/web/app/servlet/FacesHelper.java
@@ -93,15 +93,12 @@ public final class FacesHelper
*/
private static FacesContext getFacesContextImpl(Object request, Object response, Object context)
{
- FacesContext facesContext = FacesContext.getCurrentInstance();
- if (facesContext != null) return facesContext;
-
FacesContextFactory contextFactory = (FacesContextFactory)FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
LifecycleFactory lifecycleFactory = (LifecycleFactory)FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
Lifecycle lifecycle = lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
// Doesn't set this instance as the current instance of FacesContext.getCurrentInstance
- facesContext = contextFactory.getFacesContext(context, request, response, lifecycle);
+ FacesContext facesContext = contextFactory.getFacesContext(context, request, response, lifecycle);
// Set using our inner class
InnerFacesContext.setFacesContextAsCurrent(facesContext);
diff --git a/source/java/org/alfresco/web/app/servlet/ajax/InvokeCommand.java b/source/java/org/alfresco/web/app/servlet/ajax/InvokeCommand.java
index 79d19cbdbc..16bba53def 100644
--- a/source/java/org/alfresco/web/app/servlet/ajax/InvokeCommand.java
+++ b/source/java/org/alfresco/web/app/servlet/ajax/InvokeCommand.java
@@ -16,12 +16,16 @@
*/
package org.alfresco.web.app.servlet.ajax;
-import java.lang.annotation.*;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Enumeration;
import javax.faces.FactoryFinder;
import javax.faces.component.UIViewRoot;
@@ -75,24 +79,51 @@ public class InvokeCommand extends BaseAjaxCommand
final HttpServletResponse response)
throws ServletException, IOException
{
-
-
UserTransaction tx = null;
ResponseWriter writer = null;
try
{
- final VariableResolver vr = facesContext.getApplication().getVariableResolver();
-
final int indexOfDot = expression.indexOf('.');
final String variableName = expression.substring(0, indexOfDot);
final String methodName = expression.substring(indexOfDot + 1);
-
+
if (logger.isDebugEnabled())
logger.debug("Invoking method represented by " + expression +
" on variable " + variableName +
" with method " + methodName);
- final Object bean = vr.resolveVariable(facesContext, variableName);
+ // retrieve the managed bean, this is really weak but if the
+ // request comes from a portal server the bean we need to get
+ // is in the session with a prefix chosen by the portal vendor,
+ // to cover this scenario we have to go through the names of
+ // all the objects in the session to find the bean we want.
+ Object bean = null;
+ Enumeration enumNames = request.getSession().getAttributeNames();
+ while (enumNames.hasMoreElements())
+ {
+ String name = (String)enumNames.nextElement();
+ if (name.endsWith(variableName))
+ {
+ bean = request.getSession().getAttribute(name);
+
+ if (logger.isDebugEnabled())
+ logger.debug("Found bean " + bean + " in the session");
+
+ break;
+ }
+ }
+
+ // if we didn't find the bean it may be a request scope bean, in which
+ // case go through the variable resolver to create it.
+ if (bean == null)
+ {
+ VariableResolver vr = facesContext.getApplication().getVariableResolver();
+ bean = vr.resolveVariable(facesContext, variableName);
+
+ if (logger.isDebugEnabled())
+ logger.debug("Created bean " + bean + " via the variable resolver");
+ }
+
final Method method = bean.getClass().getMethod(methodName);
final String responseMimetype =
@@ -103,6 +134,7 @@ public class InvokeCommand extends BaseAjaxCommand
if (logger.isDebugEnabled())
logger.debug("invoking method " + method +
" with repsonse mimetype " + responseMimetype);
+
writer = this.setupResponseWriter(responseMimetype,
response,
facesContext);
diff --git a/source/java/org/alfresco/web/ui/common/Utils.java b/source/java/org/alfresco/web/ui/common/Utils.java
index e7045a3119..09fd3b26e0 100644
--- a/source/java/org/alfresco/web/ui/common/Utils.java
+++ b/source/java/org/alfresco/web/ui/common/Utils.java
@@ -58,7 +58,6 @@ import org.alfresco.service.cmr.repository.InvalidNodeRefException;
import org.alfresco.service.cmr.repository.NoTransformerException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
-import org.alfresco.service.cmr.repository.Path;
import org.alfresco.web.app.Application;
import org.alfresco.web.app.servlet.DownloadContentServlet;
import org.alfresco.web.app.servlet.ExternalAccessServlet;
@@ -1305,6 +1304,12 @@ public final class Utils
out.write(context.getExternalContext().getRequestContextPath());
out.write("/scripts/ajax/common.js\"> \n");
+ // set the context path
+ out.write("\n");
+
// add marker to request
context.getExternalContext().getRequestMap().put(DOJO_SCRIPTS_WRITTEN, Boolean.TRUE);
}
@@ -1353,6 +1358,12 @@ public final class Utils
out.write(context.getExternalContext().getRequestContextPath());
out.write("/scripts/ajax/common.js\"> \n");
+ // set the context path
+ out.write("\n");
+
// add marker to request
context.getExternalContext().getRequestMap().put(YAHOO_SCRIPTS_WRITTEN, Boolean.TRUE);
}
diff --git a/source/web/scripts/ajax/common.js b/source/web/scripts/ajax/common.js
index eea0efedfb..e1e83cdadb 100644
--- a/source/web/scripts/ajax/common.js
+++ b/source/web/scripts/ajax/common.js
@@ -32,6 +32,15 @@ function handleErrorYahoo(msg)
alert(msg);
}
+/**
+ * Sets the context path to use, useful for portals where
+ * the URL can be different from the app's context path.
+ */
+function setContextPath(contextPath)
+{
+ _alfContextPath = contextPath;
+}
+
/**
* Calculates and returns the context path for the current page
*/