myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mmarinsc...@apache.org
Subject cvs commit: incubator-myfaces/src/share/org/apache/myfaces/renderkit RendererUtils.java
Date Sat, 22 Jan 2005 16:47:17 GMT
mmarinschek    2005/01/22 08:47:17

  Modified:    src/jsfapi/javax/faces/component UIInput.java
                        UISelectMany.java
               src/share/org/apache/myfaces/renderkit/html
                        HtmlRadioRendererBase.java HtmlRendererUtils.java
               src/share/org/apache/myfaces/renderkit RendererUtils.java
  Log:
  fixing bug with validation not called if the submitted value is empty; an empty string is
submitted instead if the component is enabled.
  
  Revision  Changes    Path
  1.15      +9 -1      incubator-myfaces/src/jsfapi/javax/faces/component/UIInput.java
  
  Index: UIInput.java
  ===================================================================
  RCS file: /home/cvs/incubator-myfaces/src/jsfapi/javax/faces/component/UIInput.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- UIInput.java	1 Jul 2004 22:00:50 -0000	1.14
  +++ UIInput.java	22 Jan 2005 16:47:17 -0000	1.15
  @@ -37,6 +37,9 @@
    * @author Manfred Geiler (latest modification by $Author$)
    * @version $Revision$ $Date$
    * $Log$
  + * Revision 1.15  2005/01/22 16:47:17  mmarinschek
  + * fixing bug with validation not called if the submitted value is empty; an empty string
is submitted instead if the component is enabled.
  + *
    * Revision 1.14  2004/07/01 22:00:50  mwessendorf
    * ASF switch
    *
  @@ -256,6 +259,11 @@
           if (context == null) throw new NullPointerException("context");
           Object submittedValue = getSubmittedValue();
           if (submittedValue == null) return;
  +
  +        if(submittedValue instanceof String && ((String) submittedValue).length()==0)
  +        {
  +            submittedValue = null;
  +        }
   
           Object convertedValue = getConvertedValue(context, submittedValue);
           if (!isValid()) return;
  
  
  
  1.14      +10 -2     incubator-myfaces/src/jsfapi/javax/faces/component/UISelectMany.java
  
  Index: UISelectMany.java
  ===================================================================
  RCS file: /home/cvs/incubator-myfaces/src/jsfapi/javax/faces/component/UISelectMany.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- UISelectMany.java	7 Dec 2004 21:33:31 -0000	1.13
  +++ UISelectMany.java	22 Jan 2005 16:47:17 -0000	1.14
  @@ -30,6 +30,9 @@
    * @author Manfred Geiler (latest modification by $Author$)
    * @version $Revision$ $Date$
    * $Log$
  + * Revision 1.14  2005/01/22 16:47:17  mmarinschek
  + * fixing bug with validation not called if the submitted value is empty; an empty string
is submitted instead if the component is enabled.
  + *
    * Revision 1.13  2004/12/07 21:33:31  matzew
    * closing MYFACES-6, thanks to  Heath Borders-Wing for patching it!
    *
  @@ -246,6 +249,11 @@
           if (context == null) throw new NullPointerException("context");
           Object submittedValue = getSubmittedValue();
           if (submittedValue == null) return;
  +
  +        if(submittedValue instanceof String && ((String) submittedValue).length()==0)
  +        {
  +            submittedValue = null;
  +        }
   
           Object convertedValue = getConvertedValue(context, submittedValue);
           if (!isValid()) return;
  
  
  
  1.14      +4 -2      incubator-myfaces/src/share/org/apache/myfaces/renderkit/html/HtmlRadioRendererBase.java
  
  Index: HtmlRadioRendererBase.java
  ===================================================================
  RCS file: /home/cvs/incubator-myfaces/src/share/org/apache/myfaces/renderkit/html/HtmlRadioRendererBase.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- HtmlRadioRendererBase.java	19 Jan 2005 13:34:12 -0000	1.13
  +++ HtmlRadioRendererBase.java	22 Jan 2005 16:47:17 -0000	1.14
  @@ -40,6 +40,9 @@
    * @author Thomas Spiegl
    * @version $Revision$ $Date$
    * $Log$
  + * Revision 1.14  2005/01/22 16:47:17  mmarinschek
  + * fixing bug with validation not called if the submitted value is empty; an empty string
is submitted instead if the component is enabled.
  + *
    * Revision 1.13  2005/01/19 13:34:12  mmarinschek
    * handle case that converter is null
    *
  @@ -137,7 +140,6 @@
           }
   
           Object currentValue = selectOne.getValue();
  -
   
           String currentValueStr = null;
   
  
  
  
  1.24      +40 -45    incubator-myfaces/src/share/org/apache/myfaces/renderkit/html/HtmlRendererUtils.java
  
  Index: HtmlRendererUtils.java
  ===================================================================
  RCS file: /home/cvs/incubator-myfaces/src/share/org/apache/myfaces/renderkit/html/HtmlRendererUtils.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- HtmlRendererUtils.java	18 Jan 2005 22:43:05 -0000	1.23
  +++ HtmlRendererUtils.java	22 Jan 2005 16:47:17 -0000	1.24
  @@ -107,10 +107,9 @@
       private static final String LINE_SEPARATOR = System.getProperty(
               "line.separator", "\r\n");
   
  -    private static final String[] EMPTY_STRING_ARRAY = new String[0];
  -
       private static final String HIDDEN_COMMANDLINK_FIELD_NAME = "_link_hidden_";
   
  +
       private HtmlRendererUtils() {
           // utility class, do not instantiate
       }
  @@ -136,9 +135,12 @@
               ((EditableValueHolder) component).setSubmittedValue(paramMap
                       .get(clientId));
           } else {
  -            //request parameter not found, nothing to decode
  -            // we must not reset the submitted value of the component
  -            // because there could be a submittedValue from former submits!
  +            //request parameter not found, nothing to decode - set submitted value to empty
  +            //if the component has not been disabled
  +            if(!isDisabledOrReadOnly(component))
  +            {
  +                ((EditableValueHolder) component).setSubmittedValue(RendererUtils.EMPTY_STRING);
  +            }
           }
       }
   
  @@ -171,27 +173,29 @@
                           .setSubmittedValue(Boolean.FALSE);
               }
           } else {
  -            //request parameter not found,
  -            // we must not reset the submitted value of the component
  -            // if there is a submittedValue from a former submit!
  -            if (((EditableValueHolder) component).getSubmittedValue() == null) {
  -                // bug #972165: for disabled components the browser does not
  -                // send a form value, so we have to
  -                // check this to avoid modification of disabled component
  -                if (component instanceof HtmlSelectBooleanCheckbox) {
  -                    if (!(((HtmlSelectBooleanCheckbox) component).isDisabled() || ((HtmlSelectBooleanCheckbox)
component)
  -                            .isReadonly())) {
  -                        ((EditableValueHolder) component)
  -                                .setSubmittedValue(Boolean.FALSE);
  -                    }
  -                } else {
  -                    ((EditableValueHolder) component)
  -                            .setSubmittedValue(Boolean.FALSE);
  -                }
  +            //request parameter not found, nothing to decode - set submitted value to empty
  +            //if the component has not been disabled
  +            if(!isDisabledOrReadOnly(component))
  +            {
  +                ((EditableValueHolder) component).setSubmittedValue(Boolean.FALSE);
               }
           }
       }
   
  +    private static boolean isDisabledOrReadOnly(UIComponent component)
  +    {
  +        return isTrue(component.getAttributes().get("disabled")) ||
  +                    isTrue(component.getAttributes().get("readOnly"));
  +    }
  +
  +    private static boolean isTrue(Object obj)
  +    {
  +        if(!(obj instanceof Boolean))
  +            return false;
  +
  +        return ((Boolean) obj).booleanValue();
  +    }
  +
       /**
        * X-CHECKED: tlddoc h:selectManyListbox
        * 
  @@ -212,24 +216,11 @@
               String[] reqValues = (String[]) paramValuesMap.get(clientId);
               ((EditableValueHolder) component).setSubmittedValue(reqValues);
           } else {
  -            //request parameter not found,
  -            // we must not reset the submitted value of the component
  -            // if there is a submittedValue from a former submit!
  -            if (((EditableValueHolder) component).getSubmittedValue() == null) {
  -                // bug #972165: for disabled components the browser does not
  -                // send a form value, so we have to
  -                // check this to avoid modification of disabled component
  -                if (component instanceof HtmlSelectManyCheckbox) {
  -                    if (!(((HtmlSelectManyCheckbox) component).isDisabled() || ((HtmlSelectManyCheckbox)
component)
  -                            .isReadonly())) {
  -                        ((EditableValueHolder) component)
  -                                .setSubmittedValue(EMPTY_STRING_ARRAY);
  -                    }
  -                } else {
  -
  -                    ((EditableValueHolder) component)
  -                            .setSubmittedValue(EMPTY_STRING_ARRAY);
  -                }
  +            //request parameter not found, nothing to decode - set submitted value to empty
  +            //if the component has not been disabled
  +            if(!isDisabledOrReadOnly(component))
  +            {
  +                ((EditableValueHolder) component).setSubmittedValue(RendererUtils.EMPTY_STRING);
               }
           }
       }
  @@ -255,9 +246,13 @@
               ((EditableValueHolder) component).setSubmittedValue(paramMap
                       .get(clientId));
           } else {
  -            //request parameter not found, nothing to decode
  -            // we must not reset the submitted value of the component
  -            // because there could be a submittedValue from former submits!
  +            //request parameter not found, nothing to decode - set submitted value to empty
  +            //if the component has not been disabled
  +
  +            if(!isDisabledOrReadOnly(component))
  +            {
  +                ((EditableValueHolder) component).setSubmittedValue(RendererUtils.EMPTY_STRING);
  +            }
           }
       }
   
  
  
  
  1.21      +10 -5     incubator-myfaces/src/share/org/apache/myfaces/renderkit/RendererUtils.java
  
  Index: RendererUtils.java
  ===================================================================
  RCS file: /home/cvs/incubator-myfaces/src/share/org/apache/myfaces/renderkit/RendererUtils.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- RendererUtils.java	18 Jan 2005 22:43:05 -0000	1.20
  +++ RendererUtils.java	22 Jan 2005 16:47:17 -0000	1.21
  @@ -37,6 +37,9 @@
    * @author Manfred Geiler (latest modification by $Author$)
    * @version $Revision$ $Date$
    * $Log$
  + * Revision 1.21  2005/01/22 16:47:17  mmarinschek
  + * fixing bug with validation not called if the submitted value is empty; an empty string
is submitted instead if the component is enabled.
  + *
    * Revision 1.20  2005/01/18 22:43:05  svieujot
    * Fix some bugs where converter wasn't used to determine selected values.
    * This caused for examples the list, checkbox and radio based components to bug when the
backing bean value type is a primitive.
  @@ -95,6 +98,7 @@
       private static final Log log = LogFactory.getLog(RendererUtils.class);
   
       public static final String SELECT_ITEM_LIST_ATTR = RendererUtils.class.getName() +
".LIST";
  +    public static final String EMPTY_STRING = new String();
   
       public static String getPathToComponent(UIComponent component)
       {
  @@ -649,7 +653,7 @@
               UIComponent component, Converter converter, UISelectMany uiSelectMany,
               Object values)
       {
  -        if (values == null)
  +        if (values == null || values == EMPTY_STRING)
           {
               return Collections.EMPTY_SET;
           }
  @@ -709,7 +713,7 @@
                                                      Object submittedValue)
           throws ConverterException
       {
  -        if (!(submittedValue instanceof String))
  +        if (submittedValue!=null && !(submittedValue instanceof String))
           {
               throw new IllegalArgumentException("Submitted value of type String for component
: "+
                       getPathToComponent(output)+"expected");
  @@ -743,7 +747,7 @@
                                                          Object submittedValue)
               throws ConverterException
       {
  -        if (!(submittedValue instanceof String[]))
  +        if (submittedValue != null && !(submittedValue instanceof String[]))
           {
               throw new ConverterException("Submitted value of type String[] for component
: "+getPathToComponent(selectMany)+
                       "expected");
  
  
  

Mime
View raw message