myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From svieu...@apache.org
Subject cvs commit: incubator-myfaces/src/components/org/apache/myfaces/custom/tree/renderkit/html HtmlTreeCheckboxRenderer.java
Date Tue, 18 Jan 2005 22:43:06 GMT
svieujot    2005/01/18 14:43:06

  Modified:    src/components/org/apache/myfaces/renderkit/html/ext
                        HtmlCheckboxRenderer.java
               src/share/org/apache/myfaces/renderkit RendererUtils.java
               src/share/org/apache/myfaces/renderkit/html
                        HtmlRadioRendererBase.java
                        HtmlCheckboxRendererBase.java
                        HtmlRendererUtils.java
               src/components/org/apache/myfaces/custom/tree/renderkit/html
                        HtmlTreeCheckboxRenderer.java
  Log:
  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.
  
  Revision  Changes    Path
  1.8       +7 -4      incubator-myfaces/src/components/org/apache/myfaces/renderkit/html/ext/HtmlCheckboxRenderer.java
  
  Index: HtmlCheckboxRenderer.java
  ===================================================================
  RCS file: /home/cvs/incubator-myfaces/src/components/org/apache/myfaces/renderkit/html/ext/HtmlCheckboxRenderer.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- HtmlCheckboxRenderer.java	13 Oct 2004 11:50:59 -0000	1.7
  +++ HtmlCheckboxRenderer.java	18 Jan 2005 22:43:05 -0000	1.8
  @@ -35,6 +35,10 @@
    * @author Manfred Geiler (latest modification by $Author$)
    * @version $Revision$ $Date$
    * $Log$
  + * Revision 1.8  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.
  + *
    * Revision 1.7  2004/10/13 11:50:59  matze
    * renamed packages to org.apache
    *
  @@ -145,13 +149,13 @@
           }
   
           //TODO: we must cache this Set!
  -        Set lookupSet = RendererUtils.getSelectedValuesAsSet(uiSelectMany);
  +        Set lookupSet = RendererUtils.getSelectedValuesAsSet(facesContext, uiComponent,
converter, uiSelectMany);
   
           renderCheckbox(facesContext,
                          uiSelectMany,
                          itemStrValue,
                          selectItem.getLabel(),
  -                       lookupSet.contains(itemValue), true);
  +                       lookupSet.contains(itemStrValue), true);
       }
   
   
  
  
  
  1.20      +57 -39    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.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- RendererUtils.java	9 Jan 2005 18:15:12 -0000	1.19
  +++ RendererUtils.java	18 Jan 2005 22:43:05 -0000	1.20
  @@ -37,6 +37,10 @@
    * @author Manfred Geiler (latest modification by $Author$)
    * @version $Revision$ $Date$
    * $Log$
  + * 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.
  + *
    * Revision 1.19  2005/01/09 18:15:12  mmarinschek
    * small changes - better error handling, label renderer supports more hooks for sub-classes
    *
  @@ -577,24 +581,15 @@
        * @param uiSelectMany
        * @return Set containing all currently selected values
        */
  -    public static Set getSubmittedValuesAsSet(UISelectMany uiSelectMany)
  +    public static Set getSubmittedValuesAsSet(FacesContext context, UIComponent component,
Converter converter, UISelectMany uiSelectMany)
       {
           Object submittedValues = uiSelectMany.getSubmittedValue();
           if (submittedValues == null)
           {
               return null;
           }
  -        else
  -        {
  -            try
  -            {
  -                return internalSubmittedOrSelectedValuesAsSet(uiSelectMany, submittedValues);
  -            }
  -            catch (IllegalArgumentException e)
  -            {
  -                throw new IllegalArgumentException("Submitted value of UISelectMany component
with path : " + getPathToComponent(uiSelectMany) + " is not of type Array or List");
  -            }
  -        }
  +
  +        return internalSubmittedOrSelectedValuesAsSet(context, component, converter, uiSelectMany,
submittedValues);
       }
   
   
  @@ -607,28 +602,52 @@
        * @param uiSelectMany
        * @return Set containing all currently selected values
        */
  -    public static Set getSelectedValuesAsSet(UISelectMany uiSelectMany)
  +    public static Set getSelectedValuesAsSet(FacesContext context, UIComponent component,
Converter converter, UISelectMany uiSelectMany)
       {
           Object selectedValues = uiSelectMany.getValue();
  -        if (selectedValues == null)
  -        {
  -            return Collections.EMPTY_SET;
  -        }
  -        else
  -        {
  -            try
  -            {
  -                return internalSubmittedOrSelectedValuesAsSet(uiSelectMany, selectedValues);
  -            }
  -            catch (IllegalArgumentException e)
  -            {
  -                throw new IllegalArgumentException("Value of UISelectMany component with
path : " + getPathToComponent(uiSelectMany) + " is not of type Array or List");
  +
  +        return internalSubmittedOrSelectedValuesAsSet(context, component, converter, uiSelectMany,
selectedValues);
  +    }
  +    
  +    
  +    /**
  +     * Convenient utility method that returns the currently given value as String,
  +     * using the given converter.
  +     * Especially usefull for dealing with primitive types.
  +     */
  +    public static String getConvertedStringValue(FacesContext context,
  +            UIComponent component, Converter converter, Object value) {
  +        if (converter == null) {
  +            if (value == null) {
  +                return "";
  +            } else if (value instanceof String) {
  +                return (String) value;
  +            } else {
  +                throw new IllegalArgumentException(
  +                        "Value is no String and component "
  +                                + component.getClientId(context)
  +                                + " does not have a Converter");
               }
           }
  +
  +        return converter.getAsString(context, component, value);
  +    }
  +    
  +    
  +    /**
  +     * Convenient utility method that returns the currently given SelectItem value
  +     * as String, using the given converter.
  +     * Especially usefull for dealing with primitive types.
  +     */
  +    public static String getConvertedStringValue(FacesContext context,
  +            UIComponent component, Converter converter, SelectItem selectItem) {
  +        return getConvertedStringValue(context, component, converter, selectItem.getValue());
       }
   
  -    private static Set internalSubmittedOrSelectedValuesAsSet(UISelectMany uiSelectMany,
  -                                                              Object values)
  +    
  +    private static Set internalSubmittedOrSelectedValuesAsSet(FacesContext context,
  +            UIComponent component, Converter converter, UISelectMany uiSelectMany,
  +            Object values)
       {
           if (values == null)
           {
  @@ -642,15 +661,13 @@
               {
                   return Collections.EMPTY_SET;
               }
  -            else
  +
  +            HashSet set = new HashSet(HashMapUtils.calcCapacity(ar.length));
  +            for (int i = 0; i < ar.length; i++)
               {
  -                HashSet set = new HashSet(HashMapUtils.calcCapacity(ar.length));
  -                for (int i = 0; i < ar.length; i++)
  -                {
  -                    set.add(ar[i]);
  -                }
  -                return set;
  +                set.add( getConvertedStringValue(context, component, converter, ar[i])
);
               }
  +            return set;
           }
           else if (values.getClass().isArray())
           {
  @@ -659,7 +676,7 @@
               HashSet set = new HashSet(HashMapUtils.calcCapacity(len));
               for (int i = 0; i < len; i++)
               {
  -                set.add(Array.get(values, i));
  +                set.add( getConvertedStringValue(context, component, converter, Array.get(values,i))
);
               }
               return set;
           }
  @@ -673,7 +690,9 @@
               else
               {
                   HashSet set = new HashSet(HashMapUtils.calcCapacity(lst.size()));
  -                set.addAll(lst);
  +                for(Iterator i =lst.iterator(); i.hasNext(); )
  +                    set.add( getConvertedStringValue(context, component, converter, i.next())
);
  +                
                   return set;
               }
           }
  
  
  
  1.11      +7 -3      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.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- HtmlRadioRendererBase.java	18 Jan 2005 20:49:48 -0000	1.10
  +++ HtmlRadioRendererBase.java	18 Jan 2005 22:43:05 -0000	1.11
  @@ -40,6 +40,10 @@
    * @author Thomas Spiegl
    * @version $Revision$ $Date$
    * $Log$
  + * Revision 1.11  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.
  + *
    * Revision 1.10  2005/01/18 20:49:48  svieujot
    * Set default layout to lineDirection, according to Spec.
    *
  @@ -127,6 +131,7 @@
           }
   
           Object currentValue = selectOne.getValue();
  +        String currentValueStr = currentValue==null ? null : converter.getAsString(facesContext,
selectOne, currentValue);
   
           for (Iterator it = selectItemList.iterator(); it.hasNext(); )
           {
  @@ -151,7 +156,7 @@
                           itemStrValue,
                           selectItem.getLabel(),
                           currentValue == null && itemValue == null ||
  -                        currentValue != null && currentValue.equals(itemValue),
  +                        currentValueStr != null && currentValueStr.equals(itemStrValue),
                           false);
               writer.endElement(HTML.LABEL_ELEM);
               writer.endElement(HTML.TD_ELEM);
  
  
  
  1.14      +7 -4      incubator-myfaces/src/share/org/apache/myfaces/renderkit/html/HtmlCheckboxRendererBase.java
  
  Index: HtmlCheckboxRendererBase.java
  ===================================================================
  RCS file: /home/cvs/incubator-myfaces/src/share/org/apache/myfaces/renderkit/html/HtmlCheckboxRendererBase.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- HtmlCheckboxRendererBase.java	7 Jan 2005 01:54:36 -0000	1.13
  +++ HtmlCheckboxRendererBase.java	18 Jan 2005 22:43:05 -0000	1.14
  @@ -41,6 +41,10 @@
    * @author Anton Koinov
    * @version $Revision$ $Date$
    * $Log$
  + * Revision 1.14  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.
  + *
    * Revision 1.13  2005/01/07 01:54:36  svieujot
    * radioRenderer wasn't looking at the submitted value.
    *
  @@ -129,11 +133,11 @@
               converter = null;
           }
   
  -        Set lookupSet = RendererUtils.getSubmittedValuesAsSet(selectMany);
  +        Set lookupSet = RendererUtils.getSubmittedValuesAsSet(facesContext, selectMany,
converter, selectMany);
           boolean useSubmittedValues = lookupSet != null;
   
           if (!useSubmittedValues) {
  -            lookupSet = RendererUtils.getSelectedValuesAsSet(selectMany);
  +            lookupSet = RendererUtils.getSelectedValuesAsSet(facesContext, selectMany,
converter, selectMany);
           }
   
           for (Iterator it = RendererUtils.getSelectItemList(selectMany)
  
  
  
  1.23      +8 -27     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.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- HtmlRendererUtils.java	23 Dec 2004 13:03:09 -0000	1.22
  +++ HtmlRendererUtils.java	18 Jan 2005 22:43:05 -0000	1.23
  @@ -365,11 +365,11 @@
           boolean useSubmittedValue;
           if (selectMany) {
               UISelectMany uiSelectMany = (UISelectMany) uiComponent;
  -            lookupSet = RendererUtils.getSubmittedValuesAsSet(uiSelectMany);
  +            lookupSet = RendererUtils.getSubmittedValuesAsSet(facesContext, uiComponent,
converter, uiSelectMany);
               useSubmittedValue = lookupSet != null;
   
               if (!useSubmittedValue) {
  -                lookupSet = RendererUtils.getSelectedValuesAsSet(uiSelectMany);
  +                lookupSet = RendererUtils.getSelectedValuesAsSet(facesContext, uiComponent,
converter, uiSelectMany);
               }
           } else {
               UISelectOne uiSelectOne = (UISelectOne) uiComponent;
  @@ -379,8 +379,10 @@
               if (!useSubmittedValue) {
                   lookup = uiSelectOne.getValue();
               }
  +            
  +            String lookupString = RendererUtils.getConvertedStringValue(facesContext, uiComponent,
converter, lookup);
   
  -            lookupSet = Collections.singleton(lookup);
  +            lookupSet = Collections.singleton(lookupString);
           }
   
           renderSelectOptions(facesContext, uiComponent, converter, lookupSet,
  @@ -429,7 +431,7 @@
                   writer.endElement(HTML.OPTGROUP_ELEM);
               } else {
                   Object itemValue = selectItem.getValue();
  -                String itemStrValue = getItemStringValue(context, component,
  +                String itemStrValue = RendererUtils.getConvertedStringValue(context, component,
                           converter, selectItem);
   
                   writer.write("\t\t");
  @@ -453,27 +455,6 @@
   
                   writer.endElement(HTML.OPTION_ELEM);
               }
  -        }
  -    }
  -
  -    private static String getItemStringValue(FacesContext context,
  -            UIComponent component, Converter converter, SelectItem selectItem) {
  -        Object itemValue = selectItem.getValue();
  -        if (converter == null) {
  -            if (itemValue == null) {
  -                return "";
  -            } else if (itemValue instanceof String) {
  -                return (String) itemValue;
  -            } else {
  -                throw new IllegalArgumentException(
  -                        "Item value of SelectItem with label "
  -                                + selectItem.getLabel()
  -                                + " is no String and parent component "
  -                                + component.getClientId(context)
  -                                + " does not have a Converter");
  -            }
  -        } else {
  -            return converter.getAsString(context, component, itemValue);
           }
       }
   
  
  
  
  1.2       +3 -2      incubator-myfaces/src/components/org/apache/myfaces/custom/tree/renderkit/html/HtmlTreeCheckboxRenderer.java
  
  Index: HtmlTreeCheckboxRenderer.java
  ===================================================================
  RCS file: /home/cvs/incubator-myfaces/src/components/org/apache/myfaces/custom/tree/renderkit/html/HtmlTreeCheckboxRenderer.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- HtmlTreeCheckboxRenderer.java	22 Dec 2004 17:52:54 -0000	1.1
  +++ HtmlTreeCheckboxRenderer.java	18 Jan 2005 22:43:06 -0000	1.2
  @@ -60,7 +60,6 @@
           }
   
           UISelectMany uiSelectMany = (UISelectMany) uiComponent;
  -        Set lookupSet = RendererUtils.getSelectedValuesAsSet(uiSelectMany);
   
           Converter converter;
           try
  @@ -71,6 +70,8 @@
           {
               converter = null;
           }
  +        
  +        Set lookupSet = RendererUtils.getSelectedValuesAsSet(context, component, converter,
uiSelectMany);
   
           Object itemValue = checkbox.getItemValue();
           String itemStrValue = null;
  @@ -86,7 +87,7 @@
               itemStrValue = converter.getAsString(context, uiSelectMany, itemValue);
           }
   
  -        renderCheckbox(context, uiSelectMany, itemStrValue, checkbox.getItemLabel(), lookupSet.contains(itemValue),
  +        renderCheckbox(context, uiSelectMany, itemStrValue, checkbox.getItemLabel(), lookupSet.contains(itemStrValue),
                   true);
       }
   
  
  
  

Mime
View raw message