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 2001/05/13 00:35:43 UTC

cvs commit: jakarta-struts/web/example registration.jsp

craigmcc    01/05/12 15:35:43

  Modified:    src/share/org/apache/struts/util RequestUtils.java
               web/example registration.jsp
  Log:
  Fix the way that RequestUtils.computeParameters() adds parameters to a URL
  dynamically:
  * Append to the correct Map (results) instead of the input map (map).
  * Do not try to add parameters with null values.  This will cause problems
    for many containers -- in Servlet 2.3 trying to add a request or session
    attribute with setAttribute("foo", null) is treated the same as calling
    removeAttribute("foo"), but many 2.2 containers don't handle this right.
  * Allow the single-parameter value mechanism to use non-String values
    again, by using toString() instead of a String cast.
  
  PR: Bugzilla #1719
  Submitted by:	Hal Deadman <Ha...@tallan.com>
  
  Revision  Changes    Path
  1.14      +40 -30    jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java
  
  Index: RequestUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- RequestUtils.java	2001/05/12 20:34:01	1.13
  +++ RequestUtils.java	2001/05/12 22:35:43	1.14
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java,v 1.13 2001/05/12 20:34:01 craigmcc Exp $
  - * $Revision: 1.13 $
  - * $Date: 2001/05/12 20:34:01 $
  + * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/util/RequestUtils.java,v 1.14 2001/05/12 22:35:43 craigmcc Exp $
  + * $Revision: 1.14 $
  + * $Date: 2001/05/12 22:35:43 $
    *
    * ====================================================================
    *
  @@ -95,7 +95,7 @@
    * in the Struts controller framework.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.13 $ $Date: 2001/05/12 20:34:01 $
  + * @version $Revision: 1.14 $ $Date: 2001/05/12 22:35:43 $
    */
   
   public class RequestUtils {
  @@ -185,8 +185,9 @@
           // Locate the Map containing our multi-value parameters map
           Map map = null;
           try {
  -            map = (Map) lookup(pageContext, name,
  -                               property, scope);
  +            if (name != null)
  +                map = (Map) lookup(pageContext, name,
  +                                   property, scope);
           } catch (ClassCastException e) {
               saveException(pageContext, e);
               throw new JspException
  @@ -205,35 +206,44 @@
               results = new HashMap();
   
           // Add the single-value parameter (if any)
  -        if (paramId != null) {
  -            String paramValue = null;
  +        if ((paramId != null) && (paramName != null)) {
  +
  +            Object paramValue = null;
               try {
  -                paramValue =(String) lookup(pageContext, paramName,
  -                                            paramProperty, paramScope);
  -            } catch (ClassCastException e) {
  -                saveException(pageContext, e);
  -                throw new JspException
  -                    (messages.getMessage("parameters.single", paramName,
  -                                         paramProperty, paramScope));
  +                paramValue = lookup(pageContext, paramName,
  +                                    paramProperty, paramScope);
               } catch (JspException e) {
                   saveException(pageContext, e);
                   throw e;
               }
  -            Object mapValue = map.get(paramId);
  -            if (mapValue == null)
  -                map.put(paramId, paramValue);
  -            else if (mapValue instanceof String) {
  -                String newValues[] = new String[2];
  -                newValues[0] = (String) mapValue;
  -                newValues[1] = paramValue;
  -                map.put(paramId, newValues);
  -            } else /* if (mapValue instanceof String[]) */ {
  -                String oldValues[] = (String[]) mapValue;
  -                String newValues[] = new String[oldValues.length + 1];
  -                System.arraycopy(oldValues, 0, newValues, 0, oldValues.length);
  -                newValues[oldValues.length] = paramValue;
  -                map.put(paramId, newValues);
  +
  +            if (paramValue != null) {
  +
  +                String paramString = null;
  +                if (paramValue instanceof String)
  +                    paramString = (String) paramValue;
  +                else
  +                    paramString = paramValue.toString();
  +
  +                Object mapValue = results.get(paramId);
  +                if (mapValue == null)
  +                    results.put(paramId, paramString);
  +                else if (mapValue instanceof String) {
  +                    String newValues[] = new String[2];
  +                    newValues[0] = (String) mapValue;
  +                    newValues[1] = paramString;
  +                    results.put(paramId, newValues);
  +                } else /* if (mapValue instanceof String[]) */ {
  +                    String oldValues[] = (String[]) mapValue;
  +                    String newValues[] = new String[oldValues.length + 1];
  +                    System.arraycopy(oldValues, 0, newValues, 0,
  +                                     oldValues.length);
  +                    newValues[oldValues.length] = paramString;
  +                    results.put(paramId, newValues);
  +                }
  +
               }
  +
           }
   
           // Add our transaction control token (if requested)
  @@ -244,7 +254,7 @@
                   token = (String)
                       session.getAttribute(Action.TRANSACTION_TOKEN_KEY);
               if (token != null)
  -                map.put(Constants.TOKEN_KEY, token);
  +                results.put(Constants.TOKEN_KEY, token);
           }
   
           // Return the completed Map
  
  
  
  1.19      +4 -2      jakarta-struts/web/example/registration.jsp
  
  Index: registration.jsp
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/web/example/registration.jsp,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- registration.jsp	2001/02/20 05:20:11	1.18
  +++ registration.jsp	2001/05/12 22:35:43	1.19
  @@ -165,9 +165,11 @@
   
   </table>
   
  -<app:linkUser page="/editSubscription.do?action=Create">
  +<html:link page="/editSubscription.do?action=Create" paramId="username"
  + paramName="registrationForm" paramProperty="username">
     <bean:message key="registration.addSubscription"/>
  -</app:linkUser>
  +</html:link>
  +                     
   
   </logic:equal>