webwork/src/main/webwork/dispatcher ServletDispatcher.java,1.39,1.40

[email protected] Sun, 23 Jun 2002 16:56:26 -0700
Newsgroups gmane.comp.java.webwork.cvs
Message-ID <[email protected]>
Update of /cvsroot/webwork/webwork/src/main/webwork/dispatcher
In directory usw-pr-cvs1:/tmp/cvs-serv30812

Modified Files:
	ServletDispatcher.java 
Log Message:
fix to support actions with no views

Index: ServletDispatcher.java
===================================================================
RCS file: /cvsroot/webwork/webwork/src/main/webwork/dispatcher/ServletDispatcher.java,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- ServletDispatcher.java	17 Jun 2002 13:30:21 -0000	1.39
+++ ServletDispatcher.java	23 Jun 2002 23:56:24 -0000	1.40
@@ -15,9 +15,9 @@
 import webwork.config.Configuration;
 import webwork.multipart.MultiPartRequest;
 import webwork.multipart.MultiPartRequestWrapper;
+import webwork.util.BeanUtil;
 import webwork.util.LoggerUtil;
 import webwork.util.ValueStack;
-import webwork.util.BeanUtil;
 
 import javax.servlet.RequestDispatcher;
 import javax.servlet.ServletConfig;
@@ -121,7 +121,7 @@
       //saveDir
       try {
          saveDir = Configuration.getString("webwork.multipart.saveDir");
-         if (saveDir.compareTo("")==0)
+         if (saveDir.compareTo("") == 0)
             throw new IllegalArgumentException("saveDir=null");
       } catch (IllegalArgumentException e) {
          //use default
@@ -187,8 +187,7 @@
       // Set thread locals so that actions can be initialized properly
       ActionContext oldContext = ActionContext.getContext();
 
-      try
-      {
+      try {
          String candidateAction = servletPath;
          String actionName = "";
          String result = "";
@@ -196,8 +195,7 @@
          Action prevAction = null;
 
          //--------------- run action chain
-         while(isAction(candidateAction))
-         {
+         while (isAction(candidateAction)) {
             //strip directories and extension
             actionName = getActionName(candidateAction);
             //set action's context
@@ -221,7 +219,7 @@
 
             //copy previous actions attributes to new action
             try {
-               if (prevAction!=null) {
+               if (prevAction != null) {
                   BeanUtil.copy(prevAction, action);
                   prevAction = null;
                }
@@ -255,19 +253,21 @@
                log.debug("Action has no result");
                throw new ServletException("System error while executing " + action.getClass());
             }
-            candidateAction = getView(aRequest, actionName, result);
+            if (Action.NONE.equals(result.trim())) {
+               candidateAction = null;
+            } else {
+               candidateAction = getView(aRequest, actionName, result);
+            }
          }//while
 
 
          //------------ show view
          String view = candidateAction;
          // Only show if a view is assigned to this actions result
-         if (view != null)
-         {
+         if (view != null && !"".equals(view.trim())) {
             // Show view
             if (!view.startsWith("/")) view = actionPath + view; // Add path prefix
-            try
-            {
+            try {
                log.debug("View:" + view);
 
                // Push view name onto NDC
@@ -328,11 +328,10 @@
     * @return String
     */
    private String getView(HttpServletRequest aRequest, String actionName, String result)
-   throws ServletException
+         throws ServletException
    {
       String view = null;
-      if ((view = aRequest.getParameter(result)) == null)
-      {
+      if ((view = aRequest.getParameter(result)) == null) {
          try {
             view = (String) mapping.getView(actionName, result);
          } catch (IllegalArgumentException e) {
@@ -368,22 +367,22 @@
       // Get action name ("Foo.action" -> "Foo" action)
       int beginIdx = name.lastIndexOf("/");
       int endIdx = name.lastIndexOf(".");
-      return name.substring((beginIdx==-1 ? 0 : beginIdx + 1),
-            endIdx==-1 ? name.length() : endIdx);
+      return name.substring((beginIdx == -1 ? 0 : beginIdx + 1),
+            endIdx == -1 ? name.length() : endIdx);
    }
 
    /**
     * Is this string an action? Determines if the string
-    * ends with the action extension which is defined by
-    * the property "webwork.action.extension"
+    * ends with "." + action extension. The action extension is defined by
+    * the property "webwork.action.extension" somewhere in the string.
     *
     * @param action The string to test
     * @return boolean Whether the string is an action
     */
    private boolean isAction(String action)
    {
-      return (action==null) ? false :
-         action.endsWith(Configuration.getString("webwork.action.extension"));
+      return (action == null) ? false :
+            action.endsWith("." + Configuration.getString("webwork.action.extension"));
    }
 
 




-------------------------------------------------------
Sponsored by:
ThinkGeek at http://www.ThinkGeek.com/