You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by cr...@apache.org on 2005/07/07 23:35:04 UTC
svn commit: r209652 -
/struts/shale/trunk/core-library/src/java/org/apache/shale/remote/RemoteCommand.java
Author: craigmcc
Date: Thu Jul 7 14:35:02 2005
New Revision: 209652
URL: http://svn.apache.org/viewcvs?rev=209652&view=rev
Log:
Update the command that intercepts remoting requests to optionally (but on by
default) create a JSF FacesContext for the current request. Among other things,
this allows the use of programmatic value binding and method binding expression
evaluations during the creation of the corresponding response.
Modified:
struts/shale/trunk/core-library/src/java/org/apache/shale/remote/RemoteCommand.java
Modified: struts/shale/trunk/core-library/src/java/org/apache/shale/remote/RemoteCommand.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/core-library/src/java/org/apache/shale/remote/RemoteCommand.java?rev=209652&r1=209651&r2=209652&view=diff
==============================================================================
--- struts/shale/trunk/core-library/src/java/org/apache/shale/remote/RemoteCommand.java (original)
+++ struts/shale/trunk/core-library/src/java/org/apache/shale/remote/RemoteCommand.java Thu Jul 7 14:35:02 2005
@@ -22,6 +22,13 @@
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
+import javax.faces.FactoryFinder;
+import javax.faces.application.Application;
+import javax.faces.application.ApplicationFactory;
+import javax.faces.context.FacesContext;
+import javax.faces.context.FacesContextFactory;
+import javax.faces.lifecycle.Lifecycle;
+import javax.faces.lifecycle.LifecycleFactory;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.chain.Catalog;
import org.apache.commons.chain.CatalogFactory;
@@ -53,6 +60,15 @@
/**
+ * <p>The JavaServer Faces lifecycle identifier of the <code>Lifecycle</code>
+ * instance we will be using.</p>
+ */
+ private String lifecycleId = LifecycleFactory.DEFAULT_LIFECYCLE;
+ public String getLifecycleId() { return this.lifecycleId; }
+ public void setLifecycleId(String lifecycleId) { this.lifecycleId = lifecycleId; }
+
+
+ /**
* <p>Comma-delimited list of regular expression pattern(s) the context
* relative URI of this request must match in order to be processed. The
* default value matches any request that ends with ".remote".</p>
@@ -62,6 +78,18 @@
public void setPatterns(String patterns) { this.patterns = patterns; }
+ /**
+ * <p>Flag indicating whether or not we should construct a
+ * JavaServer Faces <code>FacesContext</code> for each request.
+ * Default value is <code>true</code>.</p>
+ */
+ private boolean usingFacesContext = true;
+ public boolean isUsingFacesContext() { return this.usingFacesContext; }
+ public void setUsingFacesContext(boolean usingFacesContext) {
+ this.usingFacesContext = usingFacesContext;
+ }
+
+
// --------------------------------------------------------- Command Methods
@@ -83,6 +111,7 @@
public boolean execute(Context context) throws Exception {
// Calculate the context-relative URI for this request
+ // FIXME - support portlet environments also
ShaleWebContext swcontext = (ShaleWebContext) context;
HttpServletRequest request = swcontext.getRequest();
String servletPath = request.getServletPath();
@@ -108,6 +137,15 @@
return true;
}
+ // If requested, create a FacesContext for this request
+ FacesContext facesContext = null;
+ if (isUsingFacesContext()) {
+ facesContext = facesContextFactory().getFacesContext(swcontext.getContext(),
+ swcontext.getRequest(),
+ swcontext.getResponse(),
+ lifecycle());
+ }
+
// Construct a RemoteContext and execute this command with it
// FIXME - do we want to carry over attributes from swcontext too?
RemoteContext rcontext =
@@ -115,6 +153,14 @@
swcontext.getRequest(),
swcontext.getResponse());
command.execute(rcontext);
+
+ // If we created a FacesContext for this request, clean it up appropriately
+ if (facesContext != null) {
+ facesContext.responseComplete(); // Not sure this is needed since we
+ // did not actually run the lifecycle
+ }
+
+ // Return true to indicate this chain has been completed
return true;
}
@@ -124,6 +170,28 @@
/**
+ * <p>The cached <code>Application</code> for this application.</p>
+ */
+ private Application application = null;
+
+
+ /**
+ * <p>Return the <code>Application</code> for this application,
+ * caching it upon first retrieval.</p>
+ */
+ private Application application() {
+
+ if (application == null) {
+ ApplicationFactory applicationFactory = (ApplicationFactory)
+ FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
+ application = applicationFactory.getApplication();
+ }
+ return application;
+
+ }
+
+
+ /**
* <p>The cached <code>Catalog</code> instance in which we will look
* up commands to be executed.</p>
*/
@@ -140,6 +208,49 @@
catalog = CatalogFactory.getInstance().getCatalog(catalogName);
}
return catalog;
+
+ }
+
+
+ /**
+ * <p>The cached <code>FacesContextFactory</code> for this application.</p>
+ */
+ private FacesContextFactory facesContextFactory = null;
+
+
+ /**
+ * <p>Return the <code>FacesContextFactory</code> for this application,
+ * caching it upon first retrieval.</p>
+ */
+ private FacesContextFactory facesContextFactory() {
+
+ if (facesContextFactory == null) {
+ facesContextFactory = (FacesContextFactory)
+ FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
+ }
+ return facesContextFactory;
+
+ }
+
+
+ /**
+ * <p>The cached <code>Lifecycle</code> for this application.</p>
+ */
+ private Lifecycle lifecycle = null;
+
+
+ /**
+ * <p>Return the <code>Lifecycle</code> for this application,
+ * caching it upon first retrieval.</p>
+ */
+ private Lifecycle lifecycle() {
+
+ if (lifecycle == null) {
+ LifecycleFactory lifecycleFactory = (LifecycleFactory)
+ FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
+ lifecycle = lifecycleFactory.getLifecycle(getLifecycleId());
+ }
+ return lifecycle;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org