You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by mr...@apache.org on 2006/07/11 06:08:41 UTC
svn commit: r420703 - in
/struts/struts2/trunk/core/src/main/java/org/apache/struts2/jsf:
FacesSetupInterceptor.java StrutsNavigationHandler.java
Author: mrdon
Date: Mon Jul 10 21:08:40 2006
New Revision: 420703
URL: http://svn.apache.org/viewvc?rev=420703&view=rev
Log:
Improving JSF navigation to fail over to configured handler if Struts
result cannot be located
WW-1358
Modified:
struts/struts2/trunk/core/src/main/java/org/apache/struts2/jsf/FacesSetupInterceptor.java
struts/struts2/trunk/core/src/main/java/org/apache/struts2/jsf/StrutsNavigationHandler.java
Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/jsf/FacesSetupInterceptor.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/jsf/FacesSetupInterceptor.java?rev=420703&r1=420702&r2=420703&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/jsf/FacesSetupInterceptor.java (original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/jsf/FacesSetupInterceptor.java Mon Jul 10 21:08:40 2006
@@ -83,7 +83,8 @@
.getFactory(FactoryFinder.APPLICATION_FACTORY))
.getApplication();
if (!(application.getNavigationHandler() instanceof StrutsNavigationHandler)) {
- application.setNavigationHandler(new StrutsNavigationHandler());
+ application.setNavigationHandler(new StrutsNavigationHandler(
+ application.getNavigationHandler()));
}
if (!(application.getVariableResolver() instanceof StrutsVariableResolver)) {
application.setVariableResolver(new StrutsVariableResolver(
Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/jsf/StrutsNavigationHandler.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/jsf/StrutsNavigationHandler.java?rev=420703&r1=420702&r2=420703&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/jsf/StrutsNavigationHandler.java (original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/jsf/StrutsNavigationHandler.java Mon Jul 10 21:08:40 2006
@@ -17,19 +17,37 @@
*/
package org.apache.struts2.jsf;
+import java.util.Map;
+
+import javax.faces.FactoryFinder;
import javax.faces.application.NavigationHandler;
import javax.faces.context.FacesContext;
import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.config.entities.ActionConfig;
+import com.opensymphony.xwork2.config.entities.ResultConfig;
/**
* Overrides the JFS navigation by delegating the result to handling by the core
- * result code lookup and execution.
+ * result code lookup and execution. If a result cannot be found, the previous
+ * NavigationHandler is called.
*/
public class StrutsNavigationHandler extends NavigationHandler {
+
+ private NavigationHandler parent;
+
+ /**
+ * Creates the handler
+ *
+ * @param handler The old NavigationHandler to possibly delegate to
+ */
+ public StrutsNavigationHandler(NavigationHandler handler) {
+ this.parent = handler;
+ }
/**
- * Stores any outcomes as the result code
+ * Stores any outcomes as the result code, failing over to the old
+ * NavigationHandler
*
* @param facesContext The faces context
* @param fromAction The action we are coming from
@@ -39,7 +57,27 @@
public void handleNavigation(FacesContext facesContext, String fromAction, String outcome) {
ActionContext ctx = ActionContext.getContext();
if (outcome != null) {
- ctx.getActionInvocation().setResultCode(outcome);
+ ActionConfig config = ctx.getActionInvocation().getProxy().getConfig();
+ Map results = config.getResults();
+
+ ResultConfig resultConfig = null;
+
+ synchronized (config) {
+ try {
+ resultConfig = (ResultConfig) results.get(outcome);
+ } catch (NullPointerException e) {
+ }
+ if (resultConfig == null) {
+ // If no result is found for the given resultCode, try to get a wildcard '*' match.
+ resultConfig = (ResultConfig) results.get("*");
+ }
+ }
+ if (resultConfig != null) {
+ ctx.getActionInvocation().setResultCode(outcome);
+ } else {
+ // Failing over to parent handler
+ parent.handleNavigation(facesContext, fromAction, outcome);
+ }
}
}