You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ma...@apache.org on 2007/08/02 11:40:18 UTC

svn commit: r562055 - in /myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main: java/org/apache/myfaces/trinidadinternal/convert/ java/org/apache/myfaces/trinidadinternal/resource/ javascript/META-INF/adf/jsLibs/

Author: matzew
Date: Thu Aug  2 02:40:17 2007
New Revision: 562055

URL: http://svn.apache.org/viewvc?view=rev&rev=562055
Log:
https://issues.apache.org/jira/browse/TRINIDAD-137
-added accessors
-send down integerOnly/grouping used
-moved TrNumberConverter into a separate file (NumberConverter.js)

Added:
    myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/NumberConverter.js
Modified:
    myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/convert/NumberConverter.java
    myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/resource/CoreCommonScriptsResourceLoader.java
    myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js

Modified: myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/convert/NumberConverter.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/convert/NumberConverter.java?view=diff&rev=562055&r1=562054&r2=562055
==============================================================================
--- myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/convert/NumberConverter.java (original)
+++ myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/convert/NumberConverter.java Thu Aug  2 02:40:17 2007
@@ -124,7 +124,7 @@
     boolean formating = _formatingAttributesSet();
 
     if(formating)
-      params = new Object[10];
+      params = new Object[12];
     else
       params = new Object[4];
     params[0] = this.getPattern();
@@ -136,12 +136,14 @@
     //only if specified.
     if(formating)
     {
-      params[4] = this.getCurrencyCode();
-      params[5] = this.getCurrencySymbol();
-      params[6] = this.isMaximumFractionDigitsSet() ? this.getMaxFractionDigits() : null;
-      params[7] = this.isMaximumIntegerDigitsSet() ? this.getMaxIntegerDigits() : null;
-      params[8] = this.isMinimumFractionDigitsSet() ? this.getMinFractionDigits() : null;
-      params[9] = this.isMinimumIntegerDigitsSet() ? this.getMinIntegerDigits() : null;
+      params[4] = this.isIntegerOnly();
+      params[5] = this.isGroupingUsed();
+      params[6] = this.getCurrencyCode();
+      params[7] = this.getCurrencySymbol();
+      params[8] = this.isMaximumFractionDigitsSet() ? this.getMaxFractionDigits() : null;
+      params[9] = this.isMaximumIntegerDigitsSet() ? this.getMaxIntegerDigits() : null;
+      params[10] = this.isMinimumFractionDigitsSet() ? this.getMinFractionDigits() : null;
+      params[11] = this.isMinimumIntegerDigitsSet() ? this.getMinIntegerDigits() : null;
     }
 
     return params;
@@ -155,6 +157,8 @@
   {
     return (this.getCurrencyCode()!=null ||
       this.getCurrencySymbol() != null ||
+      this.isGroupingUsed() != true ||
+      this.isIntegerOnly() != false ||
       this.isMaximumFractionDigitsSet() ||
       this.isMaximumIntegerDigitsSet() ||
       this.isMinimumFractionDigitsSet() ||
@@ -166,10 +170,9 @@
       UIComponent  component,
       Map<?, ?>    messages)
     {
-  
       StringBuilder outBuffer = new StringBuilder(250);
       
-      if(this.isIntegerOnly() && this.getPattern() == null)
+      if(this.isIntegerOnly() && this.getPattern() == null && "number".equals(this.getType()))
       {
         outBuffer.append("new TrIntegerConverter(");
         outBuffer.append("null,null,0,");

Modified: myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/resource/CoreCommonScriptsResourceLoader.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/resource/CoreCommonScriptsResourceLoader.java?view=diff&rev=562055&r1=562054&r2=562055
==============================================================================
--- myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/resource/CoreCommonScriptsResourceLoader.java (original)
+++ myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/resource/CoreCommonScriptsResourceLoader.java Thu Aug  2 02:40:17 2007
@@ -55,6 +55,7 @@
   {
     "META-INF/adf/jsLibs/CharSets.js",
     "META-INF/adf/jsLibs/NumberFormat.js",
+    "META-INF/adf/jsLibs/NumberConverter.js",
     "META-INF/adf/jsLibs/CoreFormat.js",
     "META-INF/adf/jsLibs/TrCollections.js",
     "META-INF/adf/jsLibs/DateField.js",
@@ -88,6 +89,7 @@
   {
     "META-INF/adf/jsLibsDebug/CharSets.js",
     "META-INF/adf/jsLibsDebug/NumberFormat.js",
+    "META-INF/adf/jsLibsDebug/NumberConverter.js",
     "META-INF/adf/jsLibsDebug/TrCollections.js",
     "META-INF/adf/jsLibsDebug/CoreFormat.js",
     "META-INF/adf/jsLibsDebug/DateField.js",

Modified: myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js?view=diff&rev=562055&r1=562054&r2=562055
==============================================================================
--- myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js (original)
+++ myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js Thu Aug  2 02:40:17 2007
@@ -16,194 +16,6 @@
  *  specific language governing permissions and limitations
  *  under the License.
  */
- 
-/**
- * constructor of client side NumberConverter class
- */ 
-function TrNumberConverter(
-  pattern,  
-  type,
-  locale,
-  messages,
-  currencyCode,
-  currencySymbol,
-  maxFractionDigits,
-  maxIntegerDigits,
-  minFractionDigits,
-  minIntegerDigits)
-{
-  this._pattern = pattern;
-  this._type = type;
-  this._locale = locale;
-  this._messages = messages;
-  this._currencyCode = currencyCode;
-  this._currencySymbol = currencySymbol;
-  this._maxFractionDigits = maxFractionDigits;
-  this._maxIntegerDigits = maxIntegerDigits;
-  this._minFractionDigits = minFractionDigits;
-  this._minIntegerDigits = minIntegerDigits;
-  
-  // for debugging
-  this._class = "TrNumberConverter";
-  
-  if(this._type=="percent")
-  {
-    this._example = 0.3423;
-    this._numberFormat = TrNumberFormat.getPercentInstance();
-  }
-  else if(this._type=="currency")
-  {
-    this._example = 10250;
-    this._numberFormat = TrNumberFormat.getCurrencyInstance();
-  }
-}
-
-TrNumberConverter.prototype = new TrConverter();
-
-/**
- * Checks if this converter can convert the value, which
- * is only true, if no pattern is set and the type is a number
- */
-TrNumberConverter.prototype._isConvertible = function()
-{
-  if((this._pattern == null) && (this._locale == null))
-  {
-    return true;
-  }
-  else
-  {
-    return false;
-  }
-}
-TrNumberConverter.prototype.getFormatHint = function()
-{
-  if(this._messages && this._messages["hintPattern"])
-  {
-    return TrMessageFactory.createCustomMessage(
-      this._messages["hintPattern"],
-      this._pattern);
-  }
-  else
-  {
-    if(this._pattern)
-    {
-      return TrMessageFactory.createMessage(
-      "org.apache.myfaces.trinidad.convert.NumberConverter.FORMAT_HINT",
-      this._pattern);
-    }
-    else
-    {
-      return null;
-    }
-  }
-}
-
-/**
- * Returns the number value as string or undefined (see also _isConvertible).
- */
-TrNumberConverter.prototype.getAsString = function(
-  number,
-  label
-  )
-{
-  if(this._isConvertible())
-  {
-    if(this._type=="percent" || this._type=="currency")
-    {
-      var string = this._numberFormat.format(number);
-      if(this._type=="currency")
-      {
-        //In Trinidad the currencyCode gets preference over currencySymbol
-        //this is similar on the server-side
-        if(this._currencyCode)
-        {
-          string = string.replace(getLocaleSymbols().getCurrencyCode(), this._currencyCode);
-        }
-        else if(this._currencySymbol)
-        {
-          string = string.replace(getLocaleSymbols().getCurrencySymbol(), this._currencySymbol);
-        }
-      }
-      return string;
-    }
-    else
-    {
-      this._numberFormat = TrNumberFormat.getNumberInstance();
-      this._numberFormat.setMaximumFractionDigits(this._maxFractionDigits);
-      this._numberFormat.setMaximumIntegerDigits(this._maxIntegerDigits);
-      this._numberFormat.setMinimumFractionDigits( this._minFractionDigits);
-      this._numberFormat.setMinimumIntegerDigits( this._minIntegerDigits);
-      return this._numberFormat.format(number);
-  
-      //return "" + number;
-    }
-  }
-  else
-  {
-    return undefined;
-  }
-}
-
-/**
- * Returns the number value for the submitted string or undefined (see also _isConvertible).
- */
-TrNumberConverter.prototype.getAsObject = function(
-  numberString,
-  label
-  )
-{
-  if(this._isConvertible())
-  {
-    var parsedValue;
-    if(this._type=="percent" || this._type=="currency")
-    {
-      try
-      {
-        numberString = this._numberFormat.parse(numberString)+"";
-      }
-      catch(e)
-      {
-        var facesMessage;
-        var example = this._numberFormat.format(this._example);
-        var key = "org.apache.myfaces.trinidad.convert.NumberConverter.CONVERT_" + this._type.toUpperCase();
-        if(this._messages && this._messages[this._type])
-        {
-          facesMessage = _createCustomFacesMessage(TrMessageFactory.getSummaryString(key),
-                                                  this._messages[this._type],
-                                                  label,
-                                                  numberString,
-                                                  example);
-        }
-        else
-        {
-          facesMessage = _createFacesMessage(key,
-                                            label,
-                                            numberString,
-                                            example);
-        }
-          throw new TrConverterException(facesMessage);
-      }
-    }
-    parsedValue = _decimalParse(numberString, 
-                         this._messages,
-                         "org.apache.myfaces.trinidad.convert.NumberConverter",
-                         null,
-                         null,
-                         null,
-                         null,
-                         label,
-                         true);
-    if(this._type=="percent")
-    {
-      parsedValue = parsedValue / 100;
-    }
-    return parsedValue;
-  }
-  else
-  {
-    return undefined;
-  }
-}
 
 function TrIntegerConverter(
   message,

Added: myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/NumberConverter.js
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/NumberConverter.js?view=auto&rev=562055
==============================================================================
--- myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/NumberConverter.js (added)
+++ myfaces/trinidad/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/NumberConverter.js Thu Aug  2 02:40:17 2007
@@ -0,0 +1,313 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  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
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+/**
+ * constructor of client side NumberConverter class
+ */ 
+function TrNumberConverter(
+  pattern,  
+  type,
+  locale,
+  messages,
+  integerOnly,
+  groupingUsed,
+  currencyCode,
+  currencySymbol,
+  maxFractionDigits,
+  maxIntegerDigits,
+  minFractionDigits,
+  minIntegerDigits)
+{
+  this._pattern = pattern;
+  this._type = type;
+  this._locale = locale;
+  this._messages = messages;
+  this._currencyCode = currencyCode;
+  this._currencySymbol = currencySymbol;
+  this._maxFractionDigits = maxFractionDigits;
+  this._maxIntegerDigits = maxIntegerDigits;
+  this._minFractionDigits = minFractionDigits;
+  this._minIntegerDigits = minIntegerDigits;
+  
+  //set the integerOnly value
+  if(integerOnly)
+    this._integerOnly = integerOnly;
+  else
+    this._integerOnly = false;
+    
+  //set the groupingUsed value
+  if(groupingUsed)
+    this._groupingUsed = groupingUsed;
+  else
+    this._groupingUsed = true;
+    
+  //init the TrNumberFormat
+  this._initNumberFormat();
+  
+  // for debugging
+  this._class = "TrNumberConverter";
+
+}
+
+TrNumberConverter.prototype = new TrConverter();
+
+//***********************
+// PUBLIC
+//***********************
+
+TrNumberConverter.prototype.setCurrencyCode = function(currencyCode)
+{
+  this._currencyCode = currencyCode;
+}
+TrNumberConverter.prototype.getCurrencyCode = function()
+{
+  return this._currencyCode;
+}
+TrNumberConverter.prototype.setCurrencySymbol = function(currencySymbol)
+{
+  this._currencySymbol = currencySymbol;
+}
+TrNumberConverter.prototype.getCurrencySymbol = function()
+{
+  return this._currencySymbol;
+}
+
+TrNumberConverter.prototype.setMaxFractionDigits = function(maxFractionDigits)
+{
+  this._maxFractionDigits = maxFractionDigits;
+}
+TrNumberConverter.prototype.getMaxFractionDigits = function()
+{
+  return this._maxFractionDigits;
+}
+
+TrNumberConverter.prototype.setMaxIntegerDigits = function(maxIntegerDigits)
+{
+  this._maxIntegerDigits = maxIntegerDigits;
+}
+TrNumberConverter.prototype.getMaxIntegerDigits = function()
+{
+  return this._maxIntegerDigits ;
+}
+
+TrNumberConverter.prototype.setMinFractionDigits = function(minFractionDigits)
+{
+  this._minFractionDigits = minFractionDigits;
+}
+TrNumberConverter.prototype.getMinFractionDigits = function()
+{
+  return this._minFractionDigits;
+}
+
+TrNumberConverter.prototype.setMinIntegerDigits = function(minIntegerDigits)
+{
+  this._minIntegerDigits = minIntegerDigits;
+}
+TrNumberConverter.prototype.getMinIntegerDigits = function()
+{
+  return this._minIntegerDigits;
+}
+
+TrNumberConverter.prototype.setGroupingUsed = function(groupingUsed)
+{
+  this._groupingUsed = groupingUsed;
+}
+TrNumberConverter.prototype.isGroupingUsed = function()
+{
+  return this._groupingUsed;
+}
+
+TrNumberConverter.prototype.setIntegerOnly = function(integerOnly)
+{
+  this._integerOnly = integerOnly;
+}
+TrNumberConverter.prototype.isIntegerOnly = function()
+{
+  return this._integerOnly;
+}
+
+TrNumberConverter.prototype.getFormatHint = function()
+{
+  if(this._messages && this._messages["hintPattern"])
+  {
+    return TrMessageFactory.createCustomMessage(
+      this._messages["hintPattern"],
+      this._pattern);
+  }
+  else
+  {
+    if(this._pattern)
+    {
+      return TrMessageFactory.createMessage(
+      "org.apache.myfaces.trinidad.convert.NumberConverter.FORMAT_HINT",
+      this._pattern);
+    }
+    else
+    {
+      return null;
+    }
+  }
+}
+
+/**
+ * Returns the number value as string or undefined (see also _isConvertible).
+ */
+TrNumberConverter.prototype.getAsString = function(
+  number,
+  label
+  )
+{
+  if(this._isConvertible())
+  {
+    if(this._type=="percent" || this._type=="currency")
+    {
+      var string = this._numberFormat.format(number);
+      if(this._type=="currency")
+      {
+        //In Trinidad the currencyCode gets preference over currencySymbol
+        //this is similar on the server-side
+        if(this._currencyCode)
+        {
+          string = string.replace(getLocaleSymbols().getCurrencyCode(), this._currencyCode);
+        }
+        else if(this._currencySymbol)
+        {
+          string = string.replace(getLocaleSymbols().getCurrencySymbol(), this._currencySymbol);
+        }
+      }
+      return string;
+    }
+    else
+    {
+      return this._numberFormat.format(number);
+    }
+  }
+  else
+  {
+    return undefined;
+  }
+}
+
+/**
+ * Returns the number value for the submitted string or undefined (see also _isConvertible).
+ */
+TrNumberConverter.prototype.getAsObject = function(
+  numberString,
+  label
+  )
+{
+  if(this._isConvertible())
+  {
+    var parsedValue;
+    if(this._type=="percent" || this._type=="currency")
+    {
+      try
+      {
+        numberString = this._numberFormat.parse(numberString)+"";
+      }
+      catch(e)
+      {
+        var facesMessage;
+        var example = this._numberFormat.format(this._example);
+        var key = "org.apache.myfaces.trinidad.convert.NumberConverter.CONVERT_" + this._type.toUpperCase();
+        if(this._messages && this._messages[this._type])
+        {
+          facesMessage = _createCustomFacesMessage(TrMessageFactory.getSummaryString(key),
+                                                  this._messages[this._type],
+                                                  label,
+                                                  numberString,
+                                                  example);
+        }
+        else
+        {
+          facesMessage = _createFacesMessage(key,
+                                            label,
+                                            numberString,
+                                            example);
+        }
+          throw new TrConverterException(facesMessage);
+      }
+    }
+    parsedValue = _decimalParse(numberString, 
+                         this._messages,
+                         "org.apache.myfaces.trinidad.convert.NumberConverter",
+                         null,
+                         null,
+                         null,
+                         null,
+                         label,
+                         !this.isIntegerOnly());
+    if(this._type=="percent")
+    {
+      parsedValue = parsedValue / 100;
+    }
+    return parsedValue;
+  }
+  else
+  {
+    return undefined;
+  }
+}
+
+//***********************
+// PRIVATE
+//***********************
+
+/**
+ * Checks if this converter can convert the value, which
+ * is only true, if no pattern is set and the type is a number
+ */
+TrNumberConverter.prototype._isConvertible = function()
+{
+  if((this._pattern == null) && (this._locale == null))
+  {
+    return true;
+  }
+  else
+  {
+    return false;
+  }
+}
+
+/**
+ * runs the creation of the used TrNumberFormat class
+ */
+TrNumberConverter.prototype._initNumberFormat = function()
+{
+  if(this._type=="percent")
+  {
+    this._example = 0.3423;
+    this._numberFormat = TrNumberFormat.getPercentInstance();
+  }
+  else if(this._type=="currency")
+  {
+    this._example = 10250;
+    this._numberFormat = TrNumberFormat.getCurrencyInstance();
+  }
+  else if(this._type=="number")
+  {
+  	this._numberFormat = TrNumberFormat.getNumberInstance();
+  }
+
+  this._numberFormat.setGroupingUsed(this.isGroupingUsed());
+  this._numberFormat.setMaximumFractionDigits(this.getMaxFractionDigits());
+  this._numberFormat.setMaximumIntegerDigits(this.getMaxIntegerDigits());
+  this._numberFormat.setMinimumFractionDigits(this.getMinFractionDigits());
+  this._numberFormat.setMinimumIntegerDigits(this.getMinIntegerDigits());
+}
\ No newline at end of file