Author: rgielen
Date: Tue Aug 14 06:49:45 2007
New Revision: 565756

URL: http://svn.apache.org/viewvc?view=rev&rev=565756
Log:
WW-2109:
id resolution for <s:form> - minor cleanups

Modified:
    
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Form.java
    
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/ServletUrlRenderer.java
    
struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/components/PortletUrlRenderer.java

Modified: 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Form.java
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Form.java?view=diff&rev=565756&r1=565755&r2=565756
==============================================================================
--- 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Form.java 
(original)
+++ 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/Form.java 
Tue Aug 14 06:49:45 2007
@@ -20,26 +20,6 @@
  */
 package org.apache.struts2.components;
 
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.struts2.views.annotations.StrutsTag;
-import org.apache.struts2.views.annotations.StrutsTagAttribute;
-import org.apache.struts2.StrutsConstants;
-import org.apache.struts2.dispatcher.Dispatcher;
-import org.apache.struts2.dispatcher.mapper.ActionMapping;
-//import org.apache.struts2.portlet.context.PortletActionContext;
-//import org.apache.struts2.portlet.util.PortletUrlHelper;
-import org.apache.struts2.views.util.UrlHelper;
-
-import com.opensymphony.xwork2.ActionContext;
-import com.opensymphony.xwork2.ActionInvocation;
 import com.opensymphony.xwork2.ObjectFactory;
 import com.opensymphony.xwork2.config.Configuration;
 import com.opensymphony.xwork2.config.RuntimeConfiguration;
@@ -48,11 +28,18 @@
 import com.opensymphony.xwork2.inject.Inject;
 import com.opensymphony.xwork2.interceptor.MethodFilterInterceptorUtil;
 import com.opensymphony.xwork2.util.ValueStack;
-import com.opensymphony.xwork2.util.TextUtils;
 import com.opensymphony.xwork2.validator.ActionValidatorManagerFactory;
 import com.opensymphony.xwork2.validator.FieldValidator;
 import com.opensymphony.xwork2.validator.ValidationInterceptor;
 import com.opensymphony.xwork2.validator.Validator;
+import org.apache.struts2.StrutsConstants;
+import org.apache.struts2.views.annotations.StrutsTag;
+import org.apache.struts2.views.annotations.StrutsTagAttribute;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.*;
+import java.util.Set;
 
 /**
  * <!-- START SNIPPET: javadoc -->
@@ -222,32 +209,30 @@
      * </ol>
      */
     protected void populateComponentHtmlId(Form form) {
-        boolean isAjax = "ajax".equalsIgnoreCase(this.theme);
-
-        String action = null;
-        if (this.action != null) {
-            // if it isn't specified, we'll make somethig up
-            action = findString(this.action);
-        }
-
         if (id != null) {
             addParameter("id", escape(id));
+        } else if (this.action != null) {
+            // if it isn't specified, we'll make somethig up
+            String action = findString(this.action);
+            if (action != null) {
+                addParameter("id", escape(action));
+            }
         }
+
         urlRenderer.renderFormUrl(this);
     }
 
     /**
-     * @param isAjax
-     * @param namespace
-     * @param action
+     * Evaluate client side JavaScript Enablement.
+     * @param actionName the actioName to check for
+     * @param namespace the namespace to check for
+     * @param actionMethod the method to ckeck for
      */
-
-
     protected void evaluateClientSideJsEnablement(String actionName, String 
namespace, String actionMethod) {
 
         // Only evaluate if Client-Side js is to be enable when validate=true
         Boolean validate = (Boolean) getParameters().get("validate");
-        if (validate != null && validate.booleanValue()) {
+        if (validate != null && validate) {
 
             addParameter("performValidation", Boolean.FALSE);
 
@@ -255,9 +240,8 @@
             ActionConfig actionConfig = 
runtimeConfiguration.getActionConfig(namespace, actionName);
 
             if (actionConfig != null) {
-                List interceptors = actionConfig.getInterceptors();
-                for (Iterator i = interceptors.iterator(); i.hasNext();) {
-                    InterceptorMapping interceptorMapping = 
(InterceptorMapping) i.next();
+                List<InterceptorMapping> interceptors = 
actionConfig.getInterceptors();
+                for (InterceptorMapping interceptorMapping : interceptors) {
                     if 
(ValidationInterceptor.class.isInstance(interceptorMapping.getInterceptor())) {
                         ValidationInterceptor validationInterceptor = 
(ValidationInterceptor) interceptorMapping.getInterceptor();
 
@@ -280,10 +264,9 @@
             return Collections.EMPTY_LIST;
         }
 
-        List all = 
ActionValidatorManagerFactory.getInstance().getValidators(actionClass, (String) 
getParameters().get("actionName"));
-        List validators = new ArrayList();
-        for (Iterator iterator = all.iterator(); iterator.hasNext();) {
-            Validator validator = (Validator) iterator.next();
+        List<Validator> all = 
ActionValidatorManagerFactory.getInstance().getValidators(actionClass, (String) 
getParameters().get("actionName"));
+        List<Validator> validators = new ArrayList<Validator>();
+        for (Validator validator : all) {
             if (validator instanceof FieldValidator) {
                 FieldValidator fieldValidator = (FieldValidator) validator;
                 if (fieldValidator.getFieldName().equals(name)) {

Modified: 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/ServletUrlRenderer.java
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/ServletUrlRenderer.java?view=diff&rev=565756&r1=565755&r2=565756
==============================================================================
--- 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/ServletUrlRenderer.java
 (original)
+++ 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/components/ServletUrlRenderer.java
 Tue Aug 14 06:49:45 2007
@@ -93,13 +93,11 @@
        public void renderFormUrl(Form formComponent) {
                String namespace = 
formComponent.determineNamespace(formComponent.namespace, 
formComponent.getStack(),
                                formComponent.request);
-               String action = null;
+               String action;
 
                if(formComponent.action != null) {
                        action = formComponent.findString(formComponent.action);
-               }
-               
-               if (formComponent.action == null) {
+               } else {
                        // no action supplied? ok, then default to the current 
request
                        // (action or general URL)
                        ActionInvocation ai = (ActionInvocation) 
formComponent.getStack().getContext().get(
@@ -154,19 +152,19 @@
                        }
 
                        // if the id isn't specified, use the action name
-                       if (formComponent.getId() == null) {
-                               formComponent.addParameter("id", action);
+                       if (formComponent.getId() == null  && action!=null ) {
+                               formComponent.addParameter("id", 
formComponent.escape(action));
                        }
                } else if (action != null) {
                        // Since we can't find an action alias in the 
configuration, we just
                        // assume the action attribute supplied is the path to 
be used as
                        // the URI this form is submitting to.
 
-      // Warn user that the specified namespace/action combo
-      // was not found in the configuration.
-      if (namespace != null) {
-          LOG.warn("No configuration found for the specified action: '" + 
action + "' in namespace: '" + namespace + "'. Form action defaulting to 
'action' attribute's literal value.");
-      }
+            // Warn user that the specified namespace/action combo
+            // was not found in the configuration.
+            if (namespace != null) {
+              LOG.warn("No configuration found for the specified action: '" + 
action + "' in namespace: '" + namespace + "'. Form action defaulting to 
'action' attribute's literal value.");
+            }
 
                        String result = UrlHelper.buildUrl(action, 
formComponent.request, formComponent.response, null);
                        formComponent.addParameter("action", result);

Modified: 
struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/components/PortletUrlRenderer.java
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/components/PortletUrlRenderer.java?view=diff&rev=565756&r1=565755&r2=565756
==============================================================================
--- 
struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/components/PortletUrlRenderer.java
 (original)
+++ 
struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/components/PortletUrlRenderer.java
 Tue Aug 14 06:49:45 2007
@@ -20,20 +20,17 @@
  */
 package org.apache.struts2.components;
 
-import java.io.IOException;
-import java.io.Writer;
-
+import com.opensymphony.xwork2.util.TextUtils;
 import org.apache.struts2.StrutsException;
-import org.apache.struts2.components.URL;
-import org.apache.struts2.components.UrlRenderer;
 import org.apache.struts2.portlet.util.PortletUrlHelper;
 
-import com.opensymphony.xwork2.util.TextUtils;
+import java.io.IOException;
+import java.io.Writer;
 
 /**
- * Implementation of the [EMAIL PROTECTED] URLRenderer} interface that renders 
URLs for portlet environments.
+ * Implementation of the [EMAIL PROTECTED] UrlRenderer} interface that renders 
URLs for portlet environments.
  * 
- * @see URLRenderer
+ * @see UrlRenderer
  *
  */
 public class PortletUrlRenderer implements UrlRenderer {
@@ -48,30 +45,30 @@
                        scheme = urlComponent.scheme;
                }
 
-              String result;
-               if (urlComponent.value == null && urlComponent.action != null) {
-                       result = PortletUrlHelper.buildUrl(urlComponent.action, 
urlComponent.namespace, urlComponent.method, urlComponent.parameters, 
urlComponent.portletUrlType, urlComponent.portletMode, 
urlComponent.windowState);
-               } else {
-                       result = 
PortletUrlHelper.buildResourceUrl(urlComponent.value, urlComponent.parameters);
-               }
-               if ( urlComponent.anchor != null && 
urlComponent.anchor.length() > 0 ) {
-                   result += '#' + urlComponent.anchor;
-               }
-
-               String var = urlComponent.getVar();
-
-               if (var != null) {
-                       urlComponent.putInContext(result);
-
-                   // add to the request and page scopes as well
-                       urlComponent.req.setAttribute(var, result);
-               } else {
-                   try {
-                       writer.write(result);
-                   } catch (IOException e) {
-                       throw new StrutsException("IOError: " + e.getMessage(), 
e);
-                   }
-               }
+        String result;
+        if (urlComponent.value == null && urlComponent.action != null) {
+                result = PortletUrlHelper.buildUrl(urlComponent.action, 
urlComponent.namespace, urlComponent.method, urlComponent.parameters, 
urlComponent.portletUrlType, urlComponent.portletMode, 
urlComponent.windowState);
+        } else {
+                result = PortletUrlHelper.buildResourceUrl(urlComponent.value, 
urlComponent.parameters);
+        }
+        if ( urlComponent.anchor != null && urlComponent.anchor.length() > 0 ) 
{
+            result += '#' + urlComponent.anchor;
+        }
+
+        String var = urlComponent.getVar();
+
+        if (var != null) {
+            urlComponent.putInContext(result);
+
+            // add to the request and page scopes as well
+            urlComponent.req.setAttribute(var, result);
+        } else {
+            try {
+                writer.write(result);
+            } catch (IOException e) {
+                throw new StrutsException("IOError: " + e.getMessage(), e);
+            }
+        }
        }
 
        /**


Reply via email to