You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by mm...@apache.org on 2006/09/25 06:06:25 UTC

svn commit: r449566 - in /myfaces/core/trunk/api/src/main/java/javax/faces/component: UISelectMany.java UISelectOne.java _SelectItemsUtil.java

Author: mmarinschek
Date: Sun Sep 24 21:06:24 2006
New Revision: 449566

URL: http://svn.apache.org/viewvc?view=rev&rev=449566
Log:
fix for MYFACES-1328 : UISelectOne and UISelectMany fail with custom converter that returns java.lang.String from getAsObject() method. Thanks to Nikolay Petrov for tracking this down.

Modified:
    myfaces/core/trunk/api/src/main/java/javax/faces/component/UISelectMany.java
    myfaces/core/trunk/api/src/main/java/javax/faces/component/UISelectOne.java
    myfaces/core/trunk/api/src/main/java/javax/faces/component/_SelectItemsUtil.java

Modified: myfaces/core/trunk/api/src/main/java/javax/faces/component/UISelectMany.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/component/UISelectMany.java?view=diff&rev=449566&r1=449565&r2=449566
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/component/UISelectMany.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/component/UISelectMany.java Sun Sep 24 21:06:24 2006
@@ -261,26 +261,6 @@
 
         if (isValid() && hasValues)
         {
-            // all selected values must match to the values of the available options
-
-            _ValueConverter converter = new _ValueConverter()
-            {
-                public Object getConvertedValue(FacesContext context, String value)
-                {
-                    Object convertedValue = UISelectMany.this.getConvertedValue(context, new String[] {value});
-                    if(convertedValue instanceof Collection)
-                    {
-                        Iterator iter = ((Collection)convertedValue).iterator();
-                        if(iter.hasNext())
-                        {
-                            return iter.next();
-                        }
-                        return null;
-                    }
-                    return ((Object[])convertedValue)[0];
-                }
-            };
-
             Collection items = new ArrayList();
             for (Iterator iter = new _SelectItemsIterator(this); iter.hasNext();)
             {
@@ -290,8 +270,7 @@
             {
                 Object itemValue = itemValues.next();
 
-                if (!_SelectItemsUtil.matchValue(context, itemValue,
-                                                 items.iterator(), converter))
+                if (!_SelectItemsUtil.matchValue(itemValue, items.iterator()))
                 {
                     _MessageUtils.addErrorMessage(context, this,
                                     INVALID_MESSAGE_ID,

Modified: myfaces/core/trunk/api/src/main/java/javax/faces/component/UISelectOne.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/component/UISelectOne.java?view=diff&rev=449566&r1=449565&r2=449566
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/component/UISelectOne.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/component/UISelectOne.java Sun Sep 24 21:06:24 2006
@@ -50,16 +50,8 @@
             return;
         }
 
-        _ValueConverter converter = new _ValueConverter()
-        {
-            public Object getConvertedValue(FacesContext context, String value)
-            {
-                return UISelectOne.this.getConvertedValue(context, value);
-            }
-        };
-
         // selected value must match to one of the available options
-        if (!_SelectItemsUtil.matchValue(context, value, new _SelectItemsIterator(this), converter))
+        if (!_SelectItemsUtil.matchValue(value, new _SelectItemsIterator(this)))
         {
             _MessageUtils.addErrorMessage(context, this, INVALID_MESSAGE_ID,
                             new Object[] {getId()});

Modified: myfaces/core/trunk/api/src/main/java/javax/faces/component/_SelectItemsUtil.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/component/_SelectItemsUtil.java?view=diff&rev=449566&r1=449565&r2=449566
==============================================================================
--- myfaces/core/trunk/api/src/main/java/javax/faces/component/_SelectItemsUtil.java (original)
+++ myfaces/core/trunk/api/src/main/java/javax/faces/component/_SelectItemsUtil.java Sun Sep 24 21:06:24 2006
@@ -34,14 +34,12 @@
     }
     
     /**
-     * @param context the faces context
      * @param value the value to check
-     * @param converter 
-     * @param iterator contains instances of SelectItem
+     * @param selectItemsIter contains instances of SelectItem
      * @return if the value of a selectitem is equal to the given value
      */
-    public static boolean matchValue(FacesContext context, Object value,
-                    Iterator selectItemsIter, _ValueConverter converter)
+    public static boolean matchValue(Object value,
+                    Iterator selectItemsIter)
     {
         while (selectItemsIter.hasNext())
         {
@@ -52,8 +50,8 @@
                 SelectItem[] selectItems = itemgroup.getSelectItems();
                 if (selectItems != null
                                 && selectItems.length > 0
-                                && matchValue(context, value, Arrays.asList(
-                                                selectItems).iterator(), converter))
+                                && matchValue(value, Arrays.asList(
+                                                selectItems).iterator()))
                 {
                     return true;
                 }
@@ -61,10 +59,6 @@
             else
             {
                 Object itemValue = item.getValue();
-                if(converter != null && itemValue instanceof String)
-                {
-                    itemValue = converter.getConvertedValue(context, (String)itemValue);
-                }
                 if (value==itemValue || value.equals(itemValue))
                 {
                     return true;



Re: svn commit: r449566 - in /myfaces/core/trunk/api/src/main/java/javax/faces/component: UISelectMany.java UISelectOne.java _SelectItemsUtil.java

Posted by Grant Smith <wo...@gmail.com>.
Further to this, some datapoints:

1. Reverting UISelectMany.java, UISelectOne.java and _SelectItemsUtil.java
fixes the problem.
2. The value of #{globalOptions.currentDrawNumber} in my example is a
BigInteger, while #{globalOptions.drawList.selects} is a List<Selectitem>,
composed of String, String.
3. It seems a validation error is attempting to be logged, however all that
gets to the logs is something about the message resource bundle not being
available (perhaps an unrelated bug).

On 9/28/06, Grant Smith <wo...@gmail.com> wrote:
>
> Martin,
>
> This change seems to stop any commandLinks and commandButtons from firing
> that are in the same form as the UISelect. It may or may not be specific to
> a facelets environment, and it may not only be restricted to commandLinks
> and commandButtons (those are the only two I tested).  It took me quite a
> long time to isolate this, but basically everything works fine up to SVN
> revision r449566. I've included my code below to illustrate. Funnily enough,
> the commandNavigation still fires! I put that in just for test purposes..
>
> Let me know what you think...
>
> <ui:composition>
>     <h:panelGrid id="nav"
>                  columns="1">
>         <h:form>
>             <h:panelGrid columns="2" styleClass="compactTable"
> columnClasses="compactColumn">
>                 <t:commandLink id="nav_0_1" value="Project"
> action="go_projectbrowser"/>
>                 <t:outputText value="#{globalOptions.currentProject}"/>
>                 <h:outputLabel for="drawSelector" value="Draw"/>
>                 <t:selectOneMenu id="drawSelector" value="#{
> globalOptions.currentDrawNumber}" onchange=" this.form.submit();">
>                     <f:selectItems value="#{globalOptions.drawList.selects
> }"/>
>                 </t:selectOneMenu>
>                 <h:outputLabel for="from" value="From"/>
>                 <t:outputText id="from" value="#{
> globalOptions.currentDraw.startDate}">
>                     <f:convertDateTime pattern="MM/dd/yyyy"/>
>                 </t:outputText>
>                 <h:outputLabel for="to" value="To"/>
>                 <t:outputText id="to" value="#{
> globalOptions.currentDraw.endDate}">
>                     <f:convertDateTime pattern="MM/dd/yyyy"/>
>                 </t:outputText>
>                 <h:outputLabel for="dstatus" value="Schedule"/>
>                 <t:outputText id="dstatus" value="#{
> globalOptions.currentDraw.scheduleStatus }"/>
>                 <t:commandLink id="nav_0_2" value="Contract"
> action="go_contractbrowser"/>
>                 <t:outputText value="#{
> globalOptions.currentContractDescription }"/>
>                 <t:commandNavigation id="nav_0_3" value="Vendor"
> action="go_vendorbrowser"/>
>                 <t:outputText value="#{
> globalOptions.currentVendorDescription }"/>
>             </h:panelGrid>
>         </h:form>
>
> On 9/24/06, mmarinschek@apache.org <mm...@apache.org> wrote:
> >
> > Author: mmarinschek
> > Date: Sun Sep 24 21:06:24 2006
> > New Revision: 449566
> >
> > URL: http://svn.apache.org/viewvc?view=rev&rev=449566
> > Log:
> > fix for MYFACES-1328 : UISelectOne and UISelectMany fail with custom
> > converter that returns java.lang.String from getAsObject() method.
> > Thanks to Nikolay Petrov for tracking this down.
> >
> > Modified:
> >     myfaces/core/trunk/api/src/main/java/javax/faces/component/UISelectMany.java
> >
> >
> >     myfaces/core/trunk/api/src/main/java/javax/faces/component/UISelectOne.java
> >
> >     myfaces/core/trunk/api/src/main/java/javax/faces/component/_SelectItemsUtil.java
> >
> > Modified:
> > myfaces/core/trunk/api/src/main/java/javax/faces/component/UISelectMany.java
> >
> > URL: http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/component/UISelectMany.java?view=diff&rev=449566&r1=449565&r2=449566
> >
> >
> > ==============================================================================
> > ---
> > myfaces/core/trunk/api/src/main/java/javax/faces/component/UISelectMany.java
> > (original)
> > +++
> > myfaces/core/trunk/api/src/main/java/javax/faces/component/UISelectMany.java
> > Sun Sep 24 21:06:24 2006
> > @@ -261,26 +261,6 @@
> >
> >          if (isValid() && hasValues)
> >          {
> > -            // all selected values must match to the values of the
> > available options
> > -
> > -            _ValueConverter converter = new _ValueConverter()
> > -            {
> > -                public Object getConvertedValue(FacesContext context,
> > String value)
> > -                {
> > -                    Object convertedValue =
> > UISelectMany.this.getConvertedValue(context, new String[] {value});
> > -                    if(convertedValue instanceof Collection)
> > -                    {
> > -                        Iterator iter =
> > ((Collection)convertedValue).iterator();
> > -                        if(iter.hasNext())
> > -                        {
> > -                            return iter.next();
> > -                        }
> > -                        return null;
> > -                    }
> > -                    return ((Object[])convertedValue)[0];
> > -                }
> > -            };
> > -
> >              Collection items = new ArrayList();
> >              for (Iterator iter = new _SelectItemsIterator(this);
> > iter.hasNext();)
> >              {
> > @@ -290,8 +270,7 @@
> >              {
> >                  Object itemValue = itemValues.next();
> >
> > -                if (!_SelectItemsUtil.matchValue(context, itemValue,
> > -                                                 items.iterator (),
> > converter))
> > +                if (!_SelectItemsUtil.matchValue(itemValue,
> > items.iterator()))
> >                  {
> >                      _MessageUtils.addErrorMessage(context, this,
> >                                      INVALID_MESSAGE_ID,
> >
> > Modified:
> > myfaces/core/trunk/api/src/main/java/javax/faces/component/UISelectOne.java
> > URL:
> > http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/component/UISelectOne.java?view=diff&rev=449566&r1=449565&r2=449566
> > ==============================================================================
> >
> > ---
> > myfaces/core/trunk/api/src/main/java/javax/faces/component/UISelectOne.java
> > (original)
> > +++
> > myfaces/core/trunk/api/src/main/java/javax/faces/component/UISelectOne.java
> > Sun Sep 24 21:06:24 2006
> > @@ -50,16 +50,8 @@
> >              return;
> >          }
> >
> > -        _ValueConverter converter = new _ValueConverter()
> > -        {
> > -            public Object getConvertedValue(FacesContext context,
> > String value)
> > -            {
> > -                return UISelectOne.this.getConvertedValue(context,
> > value);
> > -            }
> > -        };
> > -
> >          // selected value must match to one of the available options
> > -        if (!_SelectItemsUtil.matchValue(context, value, new
> > _SelectItemsIterator(this), converter))
> > +        if (!_SelectItemsUtil.matchValue(value, new
> > _SelectItemsIterator(this)))
> >          {
> >              _MessageUtils.addErrorMessage(context, this,
> > INVALID_MESSAGE_ID,
> >                              new Object[] {getId()});
> >
> > Modified:
> > myfaces/core/trunk/api/src/main/java/javax/faces/component/_SelectItemsUtil.java
> > URL:
> > http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/component/_SelectItemsUtil.java?view=diff&rev=449566&r1=449565&r2=449566
> > ==============================================================================
> >
> > ---
> > myfaces/core/trunk/api/src/main/java/javax/faces/component/_SelectItemsUtil.java
> > (original)
> > +++
> > myfaces/core/trunk/api/src/main/java/javax/faces/component/_SelectItemsUtil.java
> > Sun Sep 24 21:06:24 2006
> > @@ -34,14 +34,12 @@
> >      }
> >
> >      /**
> > -     * @param context the faces context
> >       * @param value the value to check
> > -     * @param converter
> > -     * @param iterator contains instances of SelectItem
> > +     * @param selectItemsIter contains instances of SelectItem
> >       * @return if the value of a selectitem is equal to the given value
> >       */
> > -    public static boolean matchValue(FacesContext context, Object
> > value,
> > -                    Iterator selectItemsIter, _ValueConverter
> > converter)
> > +    public static boolean matchValue(Object value,
> > +                    Iterator selectItemsIter)
> >      {
> >          while (selectItemsIter.hasNext())
> >          {
> > @@ -52,8 +50,8 @@
> >                  SelectItem[] selectItems = itemgroup.getSelectItems();
> >                  if (selectItems != null
> >                                  && selectItems.length > 0
> > -                                && matchValue(context, value,
> > Arrays.asList (
> > -                                                selectItems).iterator(),
> > converter))
> > +                                && matchValue(value, Arrays.asList(
> > +                                                selectItems).iterator()))
> >
> >                  {
> >                      return true;
> >                  }
> > @@ -61,10 +59,6 @@
> >              else
> >              {
> >                  Object itemValue = item.getValue();
> > -                if(converter != null && itemValue instanceof String)
> > -                {
> > -                    itemValue = converter.getConvertedValue(context,
> > (String)itemValue);
> > -                }
> >                  if (value==itemValue || value.equals(itemValue))
> >                  {
> >                      return true;
> >
> >
> >
>
>
> --
> Grant Smith
>



-- 
Grant Smith

Re: svn commit: r449566 - in /myfaces/core/trunk/api/src/main/java/javax/faces/component: UISelectMany.java UISelectOne.java _SelectItemsUtil.java

Posted by Grant Smith <wo...@gmail.com>.
Martin,

This change seems to stop any commandLinks and commandButtons from firing
that are in the same form as the UISelect. It may or may not be specific to
a facelets environment, and it may not only be restricted to commandLinks
and commandButtons (those are the only two I tested).  It took me quite a
long time to isolate this, but basically everything works fine up to SVN
revision r449566. I've included my code below to illustrate. Funnily enough,
the commandNavigation still fires! I put that in just for test purposes..

Let me know what you think...

<ui:composition>
    <h:panelGrid id="nav"
                 columns="1">
        <h:form>
            <h:panelGrid columns="2" styleClass="compactTable"
columnClasses="compactColumn">
                <t:commandLink id="nav_0_1" value="Project"
action="go_projectbrowser"/>
                <t:outputText value="#{globalOptions.currentProject}"/>
                <h:outputLabel for="drawSelector" value="Draw"/>
                <t:selectOneMenu id="drawSelector" value="#{
globalOptions.currentDrawNumber}" onchange="this.form.submit();">
                    <f:selectItems value="#{globalOptions.drawList.selects
}"/>
                </t:selectOneMenu>
                <h:outputLabel for="from" value="From"/>
                <t:outputText id="from" value="#{
globalOptions.currentDraw.startDate}">
                    <f:convertDateTime pattern="MM/dd/yyyy"/>
                </t:outputText>
                <h:outputLabel for="to" value="To"/>
                <t:outputText id="to" value="#{
globalOptions.currentDraw.endDate}">
                    <f:convertDateTime pattern="MM/dd/yyyy"/>
                </t:outputText>
                <h:outputLabel for="dstatus" value="Schedule"/>
                <t:outputText id="dstatus" value="#{
globalOptions.currentDraw.scheduleStatus}"/>
                <t:commandLink id="nav_0_2" value="Contract"
action="go_contractbrowser"/>
                <t:outputText value="#{
globalOptions.currentContractDescription}"/>
                <t:commandNavigation id="nav_0_3" value="Vendor"
action="go_vendorbrowser"/>
                <t:outputText value="#{
globalOptions.currentVendorDescription}"/>
            </h:panelGrid>
        </h:form>

On 9/24/06, mmarinschek@apache.org <mm...@apache.org> wrote:
>
> Author: mmarinschek
> Date: Sun Sep 24 21:06:24 2006
> New Revision: 449566
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=449566
> Log:
> fix for MYFACES-1328 : UISelectOne and UISelectMany fail with custom
> converter that returns java.lang.String from getAsObject() method. Thanks
> to Nikolay Petrov for tracking this down.
>
> Modified:
>
>     myfaces/core/trunk/api/src/main/java/javax/faces/component/UISelectMany.java
>
>     myfaces/core/trunk/api/src/main/java/javax/faces/component/UISelectOne.java
>
>     myfaces/core/trunk/api/src/main/java/javax/faces/component/_SelectItemsUtil.java
>
> Modified:
> myfaces/core/trunk/api/src/main/java/javax/faces/component/UISelectMany.java
> URL:
> http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/component/UISelectMany.java?view=diff&rev=449566&r1=449565&r2=449566
>
> ==============================================================================
> ---
> myfaces/core/trunk/api/src/main/java/javax/faces/component/UISelectMany.java
> (original)
> +++
> myfaces/core/trunk/api/src/main/java/javax/faces/component/UISelectMany.java
> Sun Sep 24 21:06:24 2006
> @@ -261,26 +261,6 @@
>
>          if (isValid() && hasValues)
>          {
> -            // all selected values must match to the values of the
> available options
> -
> -            _ValueConverter converter = new _ValueConverter()
> -            {
> -                public Object getConvertedValue(FacesContext context,
> String value)
> -                {
> -                    Object convertedValue =
> UISelectMany.this.getConvertedValue(context, new String[] {value});
> -                    if(convertedValue instanceof Collection)
> -                    {
> -                        Iterator iter =
> ((Collection)convertedValue).iterator();
> -                        if(iter.hasNext())
> -                        {
> -                            return iter.next();
> -                        }
> -                        return null;
> -                    }
> -                    return ((Object[])convertedValue)[0];
> -                }
> -            };
> -
>              Collection items = new ArrayList();
>              for (Iterator iter = new _SelectItemsIterator(this);
> iter.hasNext();)
>              {
> @@ -290,8 +270,7 @@
>              {
>                  Object itemValue = itemValues.next();
>
> -                if (!_SelectItemsUtil.matchValue(context, itemValue,
> -                                                 items.iterator(),
> converter))
> +                if (!_SelectItemsUtil.matchValue(itemValue,
> items.iterator()))
>                  {
>                      _MessageUtils.addErrorMessage(context, this,
>                                      INVALID_MESSAGE_ID,
>
> Modified:
> myfaces/core/trunk/api/src/main/java/javax/faces/component/UISelectOne.java
> URL:
> http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/component/UISelectOne.java?view=diff&rev=449566&r1=449565&r2=449566
>
> ==============================================================================
> ---
> myfaces/core/trunk/api/src/main/java/javax/faces/component/UISelectOne.java
> (original)
> +++
> myfaces/core/trunk/api/src/main/java/javax/faces/component/UISelectOne.java
> Sun Sep 24 21:06:24 2006
> @@ -50,16 +50,8 @@
>              return;
>          }
>
> -        _ValueConverter converter = new _ValueConverter()
> -        {
> -            public Object getConvertedValue(FacesContext context, String
> value)
> -            {
> -                return UISelectOne.this.getConvertedValue(context,
> value);
> -            }
> -        };
> -
>          // selected value must match to one of the available options
> -        if (!_SelectItemsUtil.matchValue(context, value, new
> _SelectItemsIterator(this), converter))
> +        if (!_SelectItemsUtil.matchValue(value, new
> _SelectItemsIterator(this)))
>          {
>              _MessageUtils.addErrorMessage(context, this,
> INVALID_MESSAGE_ID,
>                              new Object[] {getId()});
>
> Modified:
> myfaces/core/trunk/api/src/main/java/javax/faces/component/_SelectItemsUtil.java
> URL:
> http://svn.apache.org/viewvc/myfaces/core/trunk/api/src/main/java/javax/faces/component/_SelectItemsUtil.java?view=diff&rev=449566&r1=449565&r2=449566
>
> ==============================================================================
> ---
> myfaces/core/trunk/api/src/main/java/javax/faces/component/_SelectItemsUtil.java
> (original)
> +++
> myfaces/core/trunk/api/src/main/java/javax/faces/component/_SelectItemsUtil.java
> Sun Sep 24 21:06:24 2006
> @@ -34,14 +34,12 @@
>      }
>
>      /**
> -     * @param context the faces context
>       * @param value the value to check
> -     * @param converter
> -     * @param iterator contains instances of SelectItem
> +     * @param selectItemsIter contains instances of SelectItem
>       * @return if the value of a selectitem is equal to the given value
>       */
> -    public static boolean matchValue(FacesContext context, Object value,
> -                    Iterator selectItemsIter, _ValueConverter converter)
> +    public static boolean matchValue(Object value,
> +                    Iterator selectItemsIter)
>      {
>          while (selectItemsIter.hasNext())
>          {
> @@ -52,8 +50,8 @@
>                  SelectItem[] selectItems = itemgroup.getSelectItems();
>                  if (selectItems != null
>                                  && selectItems.length > 0
> -                                && matchValue(context, value,
> Arrays.asList(
> -                                                selectItems).iterator(),
> converter))
> +                                && matchValue(value, Arrays.asList(
> +                                                selectItems).iterator()))
>                  {
>                      return true;
>                  }
> @@ -61,10 +59,6 @@
>              else
>              {
>                  Object itemValue = item.getValue();
> -                if(converter != null && itemValue instanceof String)
> -                {
> -                    itemValue = converter.getConvertedValue(context,
> (String)itemValue);
> -                }
>                  if (value==itemValue || value.equals(itemValue))
>                  {
>                      return true;
>
>
>


-- 
Grant Smith