[ 
https://issues.apache.org/jira/browse/TRINIDAD-2533?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15262023#comment-15262023
 ] 

Falco Wockenfuß edited comment on TRINIDAD-2533 at 4/28/16 11:58 AM:
---------------------------------------------------------------------

Unified Diff:

{code}
Index: trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/NumberFormat.js
===================================================================
--- trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/NumberFormat.js       
(revision 1741413)
+++ trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/NumberFormat.js       
(working copy)
@@ -486,49 +486,56 @@
  */
 TrNumberFormat.prototype.removePrefixAndSuffix = function(numberString)
 {
-  //is the string negative ?
-  var retArr = [];
-  var negP = numberString.indexOf(this._nPrefix);
-  var nSufNoSpace = this._nSuffix;
+  var positive = true;
   
-  if (nSufNoSpace && (nSufNoSpace.charAt(0) == ' ' || nSufNoSpace.charAt(0) == 
'\xa0'))
+  // remove prefix if it exists
+  if ( this._nPrefix && this._nPrefix != "" && inputText.indexOf( 
this._nPrefix ) == 0 )
   {
-    nSufNoSpace = nSufNoSpace.substring(1);
+       inputText = inputText.substr( this._nPrefix.length );
+       
+       // Only if the negative prefix is different from the positive prefix
+       if ( this._nPrefix != this._pPrefix )
+       {
+         positive = false;
+       }
   }
+  else if ( this._pPrefix && this._pPrefix != "" && inputText.indexOf( 
this._pPrefix ) == 0 )
+  {
+       inputText = inputText.substr( this._pPrefix.length );
+  }
   
-  var negS = numberString.indexOf(nSufNoSpace);
-
-  // TRINIDAD-1958: In Arabic the values for negPrefix and posPrefix are the 
same, so it is insufficient to test for
-  // the presence of (only) negPrefix to determine if the number is negative.
-  if(negP != -1 && negS != -1)
+  // trim suffix of leading spaces
+  var nSuffix = this._nSuffix;
+  if( nSuffix && ( nSuffix.charAt( 0 ) == ' ' || nSuffix.charAt( 0 ) == '\xa0' 
) )
   {
-    retArr.push(numberString.substr(this._nPrefix.length, numberString.length 
- (this._nPrefix.length + nSufNoSpace.length)));
-    retArr.push(false);
-    return retArr;
+       nSuffix = nSuffix.substring( 1 );
   }
-  else
+  
+  var pSuffix = this._pSuffix;
+  if( pSuffix && ( pSuffix.charAt( 0 ) == ' ' || pSuffix.charAt( 0 ) == '\xa0' 
) )
   {
-    var posP = numberString.indexOf(this._pPrefix);
-    var pSufNoSpace = this._pSuffix;
-   
-    if (pSufNoSpace && (pSufNoSpace.charAt(0) == ' ' || pSufNoSpace.charAt(0) 
== '\xa0'))
-    {
-      pSufNoSpace = pSufNoSpace.substring(1);
-    }
-    
-    var posS = numberString.indexOf(pSufNoSpace);
-
-    if(posP != -1 && posS != -1)
-    {
-      retArr.push(numberString.substr(this._pPrefix.length, 
numberString.length - (this._pPrefix.length + pSufNoSpace.length)));
-      retArr.push(true);
-      return retArr;
-    }
-    else
-    {
-       throw new TrParseException("not able to parse number");
-    }//end-if we could not find a positive or negative prefix/suffix pair
-  }//end-if not negative
+       pSuffix = pSuffix.substring( 1 );
+  }
+  
+  // remove suffix if it exists
+  if ( nSuffix && nSuffix != "" && inputText.indexOf( nSuffix ) > 0 )
+  {
+       inputText = inputText.substr( 0, inputText.indexOf( nSuffix ) );
+       
+       if ( nSuffix != pSuffix )
+       {
+         positive = false;
+       }
+  }
+  else if ( pSuffix && pSuffix != "" && inputText.indexOf( pSuffix ) > 0 )
+  {
+       inputText = inputText.substr( 0, inputText.indexOf( pSuffix ) );
+  }
+  
+  var result = new Array( 2 );
+  result[ 0 ] = inputText;
+  result[ 1 ] = positive;
+  return result;
 }
 
 /**
{code}


was (Author: falco):
Unified Diff:

    Index: trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/NumberFormat.js
    ===================================================================
    --- trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/NumberFormat.js   
(revision 1741413)
    +++ trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/NumberFormat.js   
(working copy)
    @@ -486,49 +486,56 @@
      */
     TrNumberFormat.prototype.removePrefixAndSuffix = function(numberString)
     {
    -  //is the string negative ?
    -  var retArr = [];
    -  var negP = numberString.indexOf(this._nPrefix);
    -  var nSufNoSpace = this._nSuffix;
    +  var positive = true;
       
    -  if (nSufNoSpace && (nSufNoSpace.charAt(0) == ' ' || 
nSufNoSpace.charAt(0) == '\xa0'))
    +  // remove prefix if it exists
    +  if ( this._nPrefix && this._nPrefix != "" && inputText.indexOf( 
this._nPrefix ) == 0 )
       {
    -    nSufNoSpace = nSufNoSpace.substring(1);
    +   inputText = inputText.substr( this._nPrefix.length );
    +   
    +   // Only if the negative prefix is different from the positive prefix
    +   if ( this._nPrefix != this._pPrefix )
    +   {
    +     positive = false;
    +   }
       }
    +  else if ( this._pPrefix && this._pPrefix != "" && inputText.indexOf( 
this._pPrefix ) == 0 )
    +  {
    +   inputText = inputText.substr( this._pPrefix.length );
    +  }
       
    -  var negS = numberString.indexOf(nSufNoSpace);
    -
    -  // TRINIDAD-1958: In Arabic the values for negPrefix and posPrefix are 
the same, so it is insufficient to test for
    -  // the presence of (only) negPrefix to determine if the number is 
negative.
    -  if(negP != -1 && negS != -1)
    +  // trim suffix of leading spaces
    +  var nSuffix = this._nSuffix;
    +  if( nSuffix && ( nSuffix.charAt( 0 ) == ' ' || nSuffix.charAt( 0 ) == 
'\xa0' ) )
       {
    -    retArr.push(numberString.substr(this._nPrefix.length, 
numberString.length - (this._nPrefix.length + nSufNoSpace.length)));
    -    retArr.push(false);
    -    return retArr;
    +   nSuffix = nSuffix.substring( 1 );
       }
    -  else
    +  
    +  var pSuffix = this._pSuffix;
    +  if( pSuffix && ( pSuffix.charAt( 0 ) == ' ' || pSuffix.charAt( 0 ) == 
'\xa0' ) )
       {
    -    var posP = numberString.indexOf(this._pPrefix);
    -    var pSufNoSpace = this._pSuffix;
    -   
    -    if (pSufNoSpace && (pSufNoSpace.charAt(0) == ' ' || 
pSufNoSpace.charAt(0) == '\xa0'))
    -    {
    -      pSufNoSpace = pSufNoSpace.substring(1);
    -    }
    -    
    -    var posS = numberString.indexOf(pSufNoSpace);
    -
    -    if(posP != -1 && posS != -1)
    -    {
    -      retArr.push(numberString.substr(this._pPrefix.length, 
numberString.length - (this._pPrefix.length + pSufNoSpace.length)));
    -      retArr.push(true);
    -      return retArr;
    -    }
    -    else
    -    {
    -       throw new TrParseException("not able to parse number");
    -    }//end-if we could not find a positive or negative prefix/suffix pair
    -  }//end-if not negative
    +   pSuffix = pSuffix.substring( 1 );
    +  }
    +  
    +  // remove suffix if it exists
    +  if ( nSuffix && nSuffix != "" && inputText.indexOf( nSuffix ) > 0 )
    +  {
    +   inputText = inputText.substr( 0, inputText.indexOf( nSuffix ) );
    +   
    +   if ( nSuffix != pSuffix )
    +   {
    +     positive = false;
    +   }
    +  }
    +  else if ( pSuffix && pSuffix != "" && inputText.indexOf( pSuffix ) > 0 )
    +  {
    +   inputText = inputText.substr( 0, inputText.indexOf( pSuffix ) );
    +  }
    +  
    +  var result = new Array( 2 );
    +  result[ 0 ] = inputText;
    +  result[ 1 ] = positive;
    +  return result;
     }
     
     /**
    

> TrNumberFormat doesn't parse native Numbers without Currency
> ------------------------------------------------------------
>
>                 Key: TRINIDAD-2533
>                 URL: https://issues.apache.org/jira/browse/TRINIDAD-2533
>             Project: MyFaces Trinidad
>          Issue Type: Bug
>    Affects Versions: 2.0.0-beta-2
>         Environment: Oracle ADF
>            Reporter: Falco Wockenfuß
>
> If you enter a Number in a Currency-Field with a decimal separator (other 
> than ".") and without trailing currency symbol you get a parse Error.
> Test Case - Type in JS Console:
> var tr = new TrNumberConverter( null, "currency", "de_DE" );
> tr.getAsObject( "20,50" ); // Parse Error
> tr.getAsObject( "20,50 €" ); // Working
> tr.getAsObject( "20" ); // Working
> Cause:
> The Method TrNumberFormat.prototype.removePrefixAndSuffix will fail, if not 
> both matching Prefix and Suffix for Positive or Negative are present. If only 
> one of both is present an exception is thrown and parsing fails.
> Since the Prefix for positive Currency is "" (the empty string) it will 
> always match and try to find the matching suffix "€" or fail.
> In the case of an exception the default parseFloat is used as a fallback, 
> which works for default english notation, so plain Numbers and using the dot 
> as a decimal separator will work.
> Expected Behaviour and proposed Fix:
> Entering a locale Numberformat without Currency Symbol should be parsed 
> without giving an error. The removePrefixAndSuffix Method should be more 
> lenient and also accept input without currency suffix.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to