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

svn commit: r788207 - in /myfaces/trinidad/trunk: trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/ trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/ trinidad-examples/trinidad-demo/src/main/java/org/apache/myfa...

Author: gcrawford
Date: Wed Jun 24 23:19:29 2009
New Revision: 788207

URL: http://svn.apache.org/viewvc?rev=788207&view=rev
Log:
TRINIDAD-1489 get a valueChangeEvent for bigDecimal even though user didn't make a change

Modified:
    myfaces/trinidad/trunk/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXEditableValueTemplate.java
    myfaces/trinidad/trunk/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/LoggerBundle.xrts
    myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/ConverterValidatorBean.java
    myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/webapp/convertValidate/convertValidate.jspx

Modified: myfaces/trinidad/trunk/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXEditableValueTemplate.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXEditableValueTemplate.java?rev=788207&r1=788206&r2=788207&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXEditableValueTemplate.java (original)
+++ myfaces/trinidad/trunk/trinidad-api/src/main/java-templates/org/apache/myfaces/trinidad/component/UIXEditableValueTemplate.java Wed Jun 24 23:19:29 2009
@@ -6,9 +6,9 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- * 
+ *
  *  http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -411,7 +411,7 @@
     return newValue;
   }
 
-  /**
+ /**
    * <p>Return <code>true</code> if the new value is different from the
    * previous value.</p>
    *
@@ -420,10 +420,37 @@
    */
   protected boolean compareValues(Object previous, Object value)
   {
+    // handle cases where previous value was empty
     if (isEmpty(previous)) // bug 4268807
       return !isEmpty(value);
 
-    return !previous.equals(value);
+    boolean isNotEqual = !previous.equals(value);
+
+    // Handle objects whose comparable() implementation is inconsistent with equals().
+    // if not equal we will also check compareTo if the data implements Comparable.
+    // An example of why we need this is for a case where the data is bigdecimal,
+    // because bigdecimal remembers formatting information like scale. So 2.0 is not equal to 2.00
+    // in bigdecimal, but when you use compareTo 2.0 and 2.00 are equal.
+    // See Issue TRINIDAD-1489 for test case
+    if (isNotEqual && previous instanceof Comparable && value instanceof Comparable)
+    {
+      try
+      {
+        int compareTo = ((Comparable)previous).compareTo(value);
+        isNotEqual = (compareTo != 0);
+      }
+      catch (ClassCastException cce)
+      {
+        if (_LOG.isWarning())
+        {
+          // There's a type mismatch between previous and value, in theory this shouldn't happen
+          _LOG.warning("COMPARETO_TYPE_MISMATCH", new Object[]{previous, value});
+          _LOG.warning(cce);
+        }
+      }
+    }
+
+    return isNotEqual;
   }
 
   /**

Modified: myfaces/trinidad/trunk/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/LoggerBundle.xrts
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/LoggerBundle.xrts?rev=788207&r1=788206&r2=788207&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/LoggerBundle.xrts (original)
+++ myfaces/trinidad/trunk/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/LoggerBundle.xrts Wed Jun 24 23:19:29 2009
@@ -16,7 +16,7 @@
     KIND, either express or implied.  See the License for the
     specific language governing permissions and limitations
     under the License.
-	   
+     
 -->
 <!DOCTYPE resources SYSTEM "rts.dtd">
 <resources xmlns="http://myfaces.apache.org/trinidad/rts" package="org.apache.myfaces.trinidad.resource">
@@ -450,4 +450,7 @@
 <!-- UNABLE_TO_SET_RENDER_PARAMETERS -->
 <resource key="UNABLE_TO_SET_RENDER_PARAMETERS">Unable ro set portlet render parameters due to failed reflection</resource>
 
+<!-- COMPARETO_TYPE_MISMATCH -->
+<resource key="COMPARETO_TYPE_MISMATCH">The type for "{0}" prevents it from being compared to "{1}".</resource>
+
 </resources>

Modified: myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/ConverterValidatorBean.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/ConverterValidatorBean.java?rev=788207&r1=788206&r2=788207&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/ConverterValidatorBean.java (original)
+++ myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/java/org/apache/myfaces/trinidaddemo/ConverterValidatorBean.java Wed Jun 24 23:19:29 2009
@@ -6,9 +6,9 @@
  *  to you under the Apache License, Version 2.0 (the
  *  "License"); you may not use this file except in compliance
  *  with the License.  You may obtain a copy of the License at
- * 
+ *
  *  http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -20,57 +20,81 @@
 
 import java.io.Serializable;
 
+import java.math.BigDecimal;
+
+import javax.faces.event.ValueChangeEvent;
+
 public class ConverterValidatorBean implements Serializable
 {
   public ConverterValidatorBean()
-  {    
+  {
   }
-  
+
   public Number getCurrencyValue()
   {
     return _currencyValue;
   }
-  
+
   public void setCurrencyValue(Number value)
   {
     _currencyValue = value;
   }
-  
+
   public Number getIntegerOnlyValue()
   {
     return _intOnlyValue;
   }
-    
+
   public void setIntegerOnlyValue(Number value)
   {
     _intOnlyValue =  value;
   }
-  
+
   public void setPercentValue(Number value)
   {
     _percentValue = value;
   }
-  
+
   public Number getPercentValue()
   {
     return _percentValue;
   }
-  
+
   public Number getGroupValue()
   {
     return _groupValue;
   }
-  
+
   public void setGroupValue(Number value)
   {
     _groupValue = value;
   }
   
+  public void setBigDecimalValue(BigDecimal bigDecimalValue)
+  {
+    _bigDecimalValue = bigDecimalValue;
+  }
+
+  public BigDecimal getBigDecimalValue()
+  {
+    return _bigDecimalValue;
+  }
+
+  public void valueChanged(ValueChangeEvent vce)
+  {
+    System.out.println("valueChangeListener called.");
+    System.out.println("   Old value = " + vce.getOldValue());
+    System.out.println("   New value = " + vce.getNewValue());
+  }
+
   private Number _currencyValue = new Double(78.57);
-  
+
   private Number _intOnlyValue = new Double(99.99);
-  
+
   private Number _percentValue = new Double(0.55);
-  
+
   private Number _groupValue   = new Double(77777.89);
+
+  private BigDecimal _bigDecimalValue   = new BigDecimal(2.00);
+
 }

Modified: myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/webapp/convertValidate/convertValidate.jspx
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/webapp/convertValidate/convertValidate.jspx?rev=788207&r1=788206&r2=788207&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/webapp/convertValidate/convertValidate.jspx (original)
+++ myfaces/trinidad/trunk/trinidad-examples/trinidad-demo/src/main/webapp/convertValidate/convertValidate.jspx Wed Jun 24 23:19:29 2009
@@ -16,7 +16,7 @@
     KIND, either express or implied.  See the License for the
     specific language governing permissions and limitations
     under the License.
-	   
+     
 -->
 <jsp:root version="1.2" xmlns:tr="http://myfaces.apache.org/trinidad"
           xmlns:f="http://java.sun.com/jsf/core"
@@ -43,8 +43,15 @@
                 </f:facet>
                 <f:convertNumber type="number" integerOnly="true"/>
               </tr:inputText>
+              <tr:inputText valueChangeListener="#{converterValidator.valueChanged}" value="#{converterValidator.bigDecimalValue}" label="number converter2">
+                <f:facet name="help">
+                  <tr:outputText value="value is bigDecimal"/>
+                </f:facet>
+                <f:convertNumber groupingUsed="false"
+                                  pattern="#,##0.00"/>
+              </tr:inputText>
               <tr:inputText value="#{converterValidator.currencyValue}"
-                            label="number converter2" readOnly="true">
+                            label="number converter3" readOnly="true">
                 <f:facet name="help">
                   <tr:outputText value="type='currency' locale='en_US' currencyCode='EUR' - This results in EUR prefix before value"/>
                 </f:facet>
@@ -52,21 +59,21 @@
                                  currencyCode="EUR"/>
               </tr:inputText>
               <tr:inputText value="#{converterValidator.percentValue}"
-                            label="number converter3">
+                            label="number converter4">
                 <f:facet name="help">
                   <tr:outputText value="type='percent' locale='en_US' - This results in fraction displayed as integer value with % symbol"/>
                 </f:facet>
                 <f:convertNumber type="percent" locale="en_US"/>
               </tr:inputText>
               <tr:inputText value="#{converterValidator.groupValue}"
-                            label="number converter4">
+                            label="number converter5">
                 <f:facet name="help">
                   <tr:outputText value="type='number' locale='en_US'"/>
                 </f:facet>
                 <f:convertNumber type="number" locale="en_US"/>
               </tr:inputText>
               <tr:inputText value="#{converterValidator.currencyValue}"
-                            label="number converter5" readOnly="true">
+                            label="number converter6" readOnly="true">
                 <f:facet name="help">
                   <tr:outputText value="type='currency' locale='en_US' currencySymbol='#' - This results in # as prefix for value"/>
                 </f:facet>