You are viewing a plain text version of this content. The canonical link for it is here.
Posted to adffaces-commits@incubator.apache.org by ma...@apache.org on 2006/08/30 21:32:48 UTC

svn commit: r438638 - in /incubator/adffaces/trunk/trinidad: src/site/xdoc/devguide/ trinidad-demo/src/main/webapp/convertValidate/ trinidad-demo/src/main/webapp/jsLibs/ trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xht...

Author: matzew
Date: Wed Aug 30 14:32:47 2006
New Revision: 438638

URL: http://svn.apache.org/viewvc?rev=438638&view=rev
Log:
client side validation: make converters and validators responsible for formatting detail string (ADFFACES-144). thx to Gabrielle Crawford

Modified:
    incubator/adffaces/trunk/trinidad/src/site/xdoc/devguide/clientValidation.xml
    incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/convertValidate/convertValidate.jspx
    incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/jsLibs/passwordValidator.js
    incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/jsLibs/ssnConverter.js
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/jsLibs/XhtmlScriptletFactory.java
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CharSets.js
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/ColorFormat.js
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Core.js
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/DateFormat.js
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Locale.js

Modified: incubator/adffaces/trunk/trinidad/src/site/xdoc/devguide/clientValidation.xml
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/src/site/xdoc/devguide/clientValidation.xml?rev=438638&r1=438637&r2=438638&view=diff
==============================================================================
--- incubator/adffaces/trunk/trinidad/src/site/xdoc/devguide/clientValidation.xml (original)
+++ incubator/adffaces/trunk/trinidad/src/site/xdoc/devguide/clientValidation.xml Wed Aug 30 14:32:47 2006
@@ -23,14 +23,11 @@
       <p>
       The basic idea of Apache Trinidad client conversion and validation is that it works on the client in a very similar way to how it works on the server, except the language on the client is javascript instead of java. There are javascript Converter objects that support the methods getAsString() and getAsObject(). A Converter can throw a ConverterException. There are javascript Validator objects that support the validate() method. A Validator can throw a ValidatorException. 
       </p>
-      <p>
-      <b>Note:</b> this chapter describes a preliminary implementation which may change in future releases of Apache Trinidad.
-      </p>
     </section>
 
     <section name="Client-side Converters">
     <p>
-      Let's say you've written a javax.faces.convert.Converter implementation and now you want to add client-side conversion. The first thing to do is write a version of the converter in javascript. Here is the javascript code for the converter "interface".
+      Let's say you've written a javax.faces.convert.Converter implementation and now you want to add client-side conversion. The first thing to do is write a version of the converter in javascript. The main difference between converters on the client and server is that on the client there is no access to a component. The label of the field is therefore passed to the converter for use in formatting the error string. Here is the javascript code for the converter "interface".
     </p>
       <p>
  <source>
@@ -44,29 +41,97 @@
 {
 }
 
+
 /**
  * Convert the specified model object value, into a String for display
  *
  * @param value Model object value to be converted 
+ * @param label label to identify the editableValueHolder to the user 
  */
-Converter.prototype.getAsString = function(value){}
+Converter.prototype.getAsString = function(value, label){}
 
 /**
  * Convert the specified string value into a model data object 
  * which can be passed to validators
  *
  * @param value String value to be converted 
+ * @param label label to identify the editableValueHolder to the user 
+ */
+Converter.prototype.getAsObject = function(value, label){}
+
+</source>
+Converters can throw a ConverterException, which should contain a facesMessage. Here is the signature for FacesMessage:
+<source>
+/**
+ * Message similar to javax.faces.application.FacesMessage
+ *
+ * @param summary - Localized summary message text
+ * @param detail - Localized detail message text 
+ * @param severity - An optional severity for this message.  Use constants
+ *                   SEVERITY_INFO, SEVERITY_WARN, SEVERITY_ERROR, and
+ *                   SEVERITY_FATAL from the FacesMessage class.  Default is
+ *                   SEVERITY_INFO
+ */
+function FacesMessage(
+  summary,
+  detail,
+  severity
+  )
+</source>
+Here is the signature for ConverterException:
+<source>
+/** 
+ * ConverterException is an exception thrown by the getAsObject() or getAsString() 
+ * method of a Converter, to indicate that the requested conversion cannot be performed.
+ *
+ * @param facesMessage the FacesMessage associated with this exception
+ * @param summary Localized summary message text, used to create only if facesMessage is null
+ * @param detail Localized detail message text, used only if facesMessage is null
+ */
+function ConverterException(
+  facesMessage, 
+  summary,
+  detail
+  )
+  
+</source>
+
+Another useful API can be used to format messages. 
+
+<source>
+/**
+ * FastMessageFormatUtils is a greatly reduced version
+ * of the java.text.MessageFormat class, but delivered as a utility. 
+ * &lt;p&gt;
+ * The only syntax supported by this class is simple index-based
+ * replacement, namely:
+ * &lt;pre&gt;
+ *     some{1}text{0}here{2}andthere
+ * &lt;/pre&gt;
+ * as well as escaping using single quotes.  Like MessageFormat,
+ * a single quote must be represented using two consecutive single
+ * quotes, but the contents of any text between single quotes
+ * will not be interpreted.  So, the following pattern could
+ * be used to include a left bracket:
+ * &lt;pre&gt;
+ *     some'{'text{0}
+ * &lt;/pre&gt;
  */
-Converter.prototype.getAsObject = function(value){}
+function FastMessageFormatUtils()
+
+ /**
+  * Formats the given array of strings based on the initial
+  * pattern.   It is legal for this array to be shorter
+  * than that indicated by the pattern, or to have null
+  * entries - these will simply be ignored.
+  * @param formatString an array of strings
+  * @param params an array of strings
+  */
+FastMessageFormatUtils.format = function(
+  formatString, // error format string with embedded indexes to be replaced
+  params        // array of objects to replace indexes
+  )
 </source>
-Converters can throw a ConverterException, here is the signature:
-<ul>
-<li>ConverterException(detail) 
-  <ul>
-    <li>detail - Localized detail message text</li>
-  </ul> 
-</li>
-</ul>
       </p>
       <p>
       Let's say we have implemented a social security number converter which converts a String to/from an Integer. To get a version of this working on the client we would need two things, a javascript implementation of the converter and a javascript constructor for each instance of the converter on the page. 
@@ -74,18 +139,14 @@
       <p>
       Let's take a look at an example of a javascript converter implementation for our social security number converter:
       <source>
-      function ssnGetAsString(value)
+      function ssnGetAsString(value, label)
       {
-        return value.substring(0,3) + '-' + 
-               value.substring(3,5) + '-' + 
-               value.substring(5);
+        return value.substring(0,3) + '-' + value.substring(3,5) + '-' + value.substring(5);
       }
       
-      function ssnGetAsObject(value)
-      {
-        if (!value)
-          return (void 0);
-          
+      function ssnGetAsObject(value, label)
+      { 
+        if (!value)return null;
         var len=value.length;
         var messageKey = SSNConverter.NOT;
         if (len &lt; 9 )
@@ -93,52 +154,58 @@
         else if (len &gt; 11)
           messageKey = SSNConverter.LONG;
         else if (len == 9)
-        { 
-          if (!isNaN(value))
+        { if (!isNaN(value))
             return value;
         }
-        else if (len == 11 &amp;&amp; value.charAt(3) == '-' &amp;&amp; value.charAt(6) == '-')
+        else if (len == 11 &amp;&amp; value.charAt(3) == '-' &amp;&amp; 
+                  value.charAt(6) == '-')
         {
-          var result = value.substring(0,3) + 
-                       value.substring(4,6) + 
-                       value.substring(7);
-          
+          var result = value.substring(0,3) + value.substring(4,6) + 
+                      value.substring(7);
           if (!isNaN(result))
             return result;
         }
+        if (messageKey!=null &amp;&amp; this._messages!=null)
+        { 
+          // format the detail error string
+          var detail = this._messages[messageKey];
+          if (detail != null)
+          {
+            var patternArray = new Array();
+            patternArray[0] = label;
+            patternArray[1] = value;
+            detail = FastMessageFormatUtils.format(detail, patternArray);
+          }
         
-        if (messageKey!=void(0) &amp;&amp; this._messages!=void(0))
-          return new ConverterException(this._messages[messageKey]);
-          
-        return (void 0);
+          var facesMessage = new FacesMessage(
+                              this._messages[SSNConverter.SUMMARY],
+                              detail,
+                              FacesMessage.SEVERITY_ERROR)
+         throw new ConverterException(facesMessage);
+       }
+       return null;
       }
-      
       function SSNConverter(messages)
-      {
-        this._messages = messages;
-      }
-      
+        {this._messages = messages;}
       SSNConverter.prototype = new Converter();
       SSNConverter.prototype.getAsString = ssnGetAsString;
       SSNConverter.prototype.getAsObject = ssnGetAsObject;
-      
+      SSNConverter.SUMMARY = 'SUM';
       SSNConverter.SHORT = 'S';
       SSNConverter.LONG  = 'L';
       SSNConverter.NOT   = 'N';
+
       </source>
       </p>
       <p>
       And here's an example of a javascript constructor to get an instance of the javascript converter defined above:
       <source>
-       new SSNConverter({S:\'Value "{1}" is too short.\',
-                         L:\'Value "{1}" is too long.\',
-                         N:\'Value "{1}" is not a valid social security number.\'})
-            );
+           new SSNConverter({SUM:\'Invalid social security number.\',
+                             S:\'Value "{1}" is too short.\',
+                             L:\'Value "{1}" is too long.\',
+                             N:\'Value "{1}" is not a valid social security number.\'})
       </source>
-      </p>
-      <p>
-       If there is a ConverterException Apache Trinidad gets the detail string out of the exception and replaces '{0}' with the label of the field and '{1}' with the  value entered by the user. It is not necessary to use the label in the detail though because the detail is passed to another string before it is displayed. The value of the translation af_messages.GLOBAL_MESSAGE_FORMAT is also sent to the client. An example of this string is "{0} - {1}", where {0} will be replaced with the label and {1} will be replaced with the detail provided by the converterException. So if the label was 'ssn number' and the value the user entered was '1111', the message shown would look like 'ssn number - Value "1111" is too short'.
-      </p>
+      </p>      
       <p>
        At this point we have the javascript to use on the client, but we need a way to provide it from our Java Converter object. This is achieved by implementing the interface <code>org.apache.myfaces.trinidad.converter.ClientConverter</code>, which has four methods. The first method is <code>getClientLibrarySource()</code>, which is expected to return a library that includes an implementation of the javascript Converter object. The second method is <code>getClientConversion()</code>, which is expected to return a  javascript constructor which will be used to instantiate an instance of the converter. Also provided are <code>getClientScript()</code> which can be used to write out inline javascript, and <code>getClientImportNames()</code> which is used to import the built-in scripts provided by Apache Trinidad.</p>
       <p>
@@ -199,6 +266,7 @@
  
            // in a real app the messages would be translated
            return ("new SSNConverter({"
+                   + "SUM:'Invalid social security number.',"
                    + "S:'Value \"{1}\" is too short.',"
                    + "L:'Value \"{1}\" is too long.',"
                    + "N:'Value \"{1}\" is not a valid social security number.'})"
@@ -240,23 +308,33 @@
  *
  */
 function Validator()
-{
-}
 
 /**
  * Perform the correctness checks implemented by this Validator. 
  * If any violations are found, a ValidatorException will be thrown 
+ * containing the FacesMessage describing the failure. 
+ * @param value value to be validated 
+ * @param label label to identify the editableValueHolder to the user
  */
-Validator.prototype.validate = function(value){}
+Validator.prototype.validate = function(value, label){}
       </source>
+      
       The validator can throw javascript ValidatorException objects:
-<ul>
-<li>ValidatorException(detail) 
-  <ul>
-    <li>detail - Localized detail message text</li>
-  </ul> 
-</li>
-</ul>
+<source>      
+/**
+ * A ValidatorException is an exception thrown by the validate() method of 
+ * a Validator to indicate that validation failed.
+ *
+ * @param facesMessage the FacesMessage associated with this exception
+ * @param summary Localized summary message text, used only if facesMessage is null
+ * @param detail Localized detail message text, used only if facesMessage is null
+ */
+function ValidatorException(
+  facesMessage,
+  summary, 
+  detail
+  )
+</source>
       </P>
       <p>
       Once you have a javascript implementation of the validator and constructor, they are plugged in to the Java code using <code>org.apache.myfaces.trinidad.validator.ClientValidator</code>, which has similar methods to ClientConverter, and functions in exactly the same way. Please see the client-side converters section of this document for more information. An example will be provided in a future version of this document.

Modified: incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/convertValidate/convertValidate.jspx
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/convertValidate/convertValidate.jspx?rev=438638&r1=438637&r2=438638&view=diff
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/convertValidate/convertValidate.jspx (original)
+++ incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/convertValidate/convertValidate.jspx Wed Aug 30 14:32:47 2006
@@ -102,7 +102,7 @@
                 <tr:convertDateTime pattern="yyyy-MM-dd"/>
                 <tr:validateDateTimeRange minimum="2004-11-16"
                                           maximum="2004-12-16"
-                                          notInRangeMessageDetail='Date "{0}" does not fall within {1} : {2}'/>
+                                          notInRangeMessageDetail='Date "{1}" does not fall within {2} : {3}'/>
               </tr:inputDate>
             </tr:panelFormLayout>
            </tr:panelHeader>

Modified: incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/jsLibs/passwordValidator.js
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/jsLibs/passwordValidator.js?rev=438638&r1=438637&r2=438638&view=diff
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/jsLibs/passwordValidator.js (original)
+++ incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/jsLibs/passwordValidator.js Wed Aug 30 14:32:47 2006
@@ -41,7 +41,7 @@
                         this._messages[PasswordValidator.NUMBER_SUMMARY],
                         this._messages[PasswordValidator.NUMBER_DETAIL],
                         FacesMessage.SEVERITY_ERROR)
-    throw new ValidatorException(null, facesMessage);
+    throw new ValidatorException(facesMessage);
   }
     
   return null;

Modified: incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/jsLibs/ssnConverter.js
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/jsLibs/ssnConverter.js?rev=438638&r1=438637&r2=438638&view=diff
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/jsLibs/ssnConverter.js (original)
+++ incubator/adffaces/trunk/trinidad/trinidad-demo/src/main/webapp/jsLibs/ssnConverter.js Wed Aug 30 14:32:47 2006
@@ -14,12 +14,12 @@
  * limitations under the License.
  */
 
-function ssnGetAsString(value)
+function ssnGetAsString(value, label)
 {
   return value.substring(0,3) + '-' + value.substring(3,5) + '-' + value.substring(5);
 }
 
-function ssnGetAsObject(value)
+function ssnGetAsObject(value, label)
 { 
   if (!value)return null;
   var len=value.length;
@@ -40,13 +40,23 @@
     if (!isNaN(result))
       return result;
   }
- if (messageKey!=null && this._messages!=null)
- {
+  if (messageKey!=null && this._messages!=null)
+  { 
+    // format the detail error string
+    var detail = this._messages[messageKey];
+    if (detail != null)
+    {
+      var patternArray = new Array();
+      patternArray[0] = label;
+      patternArray[1] = value;
+      detail = FastMessageFormatUtils.format(detail, patternArray);
+    }
+  
     var facesMessage = new FacesMessage(
                         this._messages[SSNConverter.SUMMARY],
-                        this._messages[messageKey],
+                        detail,
                         FacesMessage.SEVERITY_ERROR)
-   throw new ConverterException(null, facesMessage);
+   throw new ConverterException(facesMessage);
  }
  return null;
 }

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/jsLibs/XhtmlScriptletFactory.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/jsLibs/XhtmlScriptletFactory.java?rev=438638&r1=438637&r2=438638&view=diff
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/jsLibs/XhtmlScriptletFactory.java (original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/jsLibs/XhtmlScriptletFactory.java Wed Aug 30 14:32:47 2006
@@ -102,18 +102,20 @@
   static
   {
     _sLocaleScriptlet =
-        new AliasedScriptlet(LOCALE_LIB, new String[]{"getUserLanguage()",
-                                                      "getJavaLanguage()",
-                                                      "Converter()",
-                                                      "Validator()",
-                                                      "isDigit()",
-                                                      "parseDigit()",
-                                                      "isNotLowerCase()",
-                                                      "isLowerCase()",
-                                                      "isUpperCase()",
-                                                      "isNotUpperCase()",
-                                                      "isLetter()",
-                                                      "getLocaleSymbols()"},
+        new AliasedScriptlet(LOCALE_LIB, new String[]{
+                              "getUserLanguage()",
+                              "getJavaLanguage()",
+                              "Converter()", 
+                              "Validator()",
+                              "FastMessageFormatUtils()",
+                              "isDigit()",
+                              "parseDigit()",
+                              "isNotLowerCase()",
+                              "isLowerCase()",
+                              "isUpperCase()",
+                              "isNotUpperCase()",
+                              "isLetter()",
+                              "getLocaleSymbols()"},
                             new String[]
                             {
                               CORE_LIB

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CharSets.js
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CharSets.js?rev=438638&r1=438637&r2=438638&view=diff
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CharSets.js (original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CharSets.js Wed Aug 30 14:32:47 2006
@@ -36,7 +36,8 @@
 EncodingFormat.prototype.LF  = "LF";
 
 function _cjkParse(
-  parseString
+  parseString,
+  label
   )
 {
   var i = 0;
@@ -50,10 +51,11 @@
    
     if (length < 0)
     {
-      var facesMessage = new FacesMessage(this._messages[this.LFS], 
-                                          this._messages[this.LF], 
-                                          FacesMessage.SEVERITY_ERROR);
-      throw new ValidatorException(null, facesMessage);     
+      var facesMessage = _createFacesMessage( this._messages[this.LFS],
+                                              this._messages[this.LF],
+                                              label,
+                                              parseString);   
+      throw new ValidatorException(facesMessage);     
     }
 
     i++;
@@ -79,7 +81,8 @@
 CjkFormat.prototype.validate  = _cjkParse;
 
 function _utf8Parse(
-  parseString
+  parseString,
+  label
   )
 {
   var i = 0;
@@ -101,10 +104,11 @@
 
     if (length < 0)
     {
-      var facesMessage = new FacesMessage(this._messages[this.LFS], 
-                                          this._messages[this.LF], 
-                                          FacesMessage.SEVERITY_ERROR);
-      throw new ValidatorException(null, facesMessage);              
+      var facesMessage = _createFacesMessage( this._messages[this.LFS],
+                                              this._messages[this.LF],
+                                              label,
+                                              parseString);   
+      throw new ValidatorException(facesMessage);              
     }
 
     i++;
@@ -131,15 +135,17 @@
 
 
 function _sbParse(
-  parseString
+  parseString,
+  label
   )
 {
   if (this._length < parseString.length)
   {
-    var facesMessage = new FacesMessage(this._messages[this.LFS], 
-                                        this._messages[this.LF], 
-                                        FacesMessage.SEVERITY_ERROR);
-    throw new ValidatorException(null, facesMessage);      
+    var facesMessage = _createFacesMessage( this._messages[this.LFS],
+                                            this._messages[this.LF],
+                                            label,
+                                            parseString);   
+    throw new ValidatorException(facesMessage);      
   }
 
   return parseString;

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/ColorFormat.js
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/ColorFormat.js?rev=438638&r1=438637&r2=438638&view=diff
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/ColorFormat.js (original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/ColorFormat.js Wed Aug 30 14:32:47 2006
@@ -52,16 +52,20 @@
  * parsing fails, undefined will be returned.
  */
 function _rgbColorParse(
-  parseString)
+  parseString,
+  label)
 {
   // return transparent color for localized transparent text
   if (this._allowsTransparent && _cfTrans == parseString)
     return new Color(0,0,0,0);
-    
-  var pattern = this._pattern;
-  var facesMessage = new FacesMessage(this._msg_summary, 
-                                      this._msg_detail, 
-                                      FacesMessage.SEVERITY_ERROR);
+     
+  var facesMessage = _createFacesMessage( this._msg_summary,
+                                          this._msg_detail,
+                                          label,
+                                          parseString,
+                                          this._patternsString);
+  
+  var pattern = this._pattern;                                       
   if (typeof pattern == "string")
   {
     return _rgbColorParseImpl(parseString,
@@ -98,7 +102,7 @@
   var parseContext = new Object();
   parseContext.currIndex = 0;
   parseContext.parseString = parseString;
-  parseContext.parseException = new ConverterException(null, msg);
+  parseContext.parseException = new ConverterException(msg);
   
   var parsedColor = new Color(0x00, 0x00, 0x00);
 
@@ -564,17 +568,9 @@
   // for debugging
   this._class = "RGBColorFormat";
   this._allowsTransparent = allowsTransparent;  
-  this._msg_summary = msg_summary;
-  
-  // format the detail error string
-  //   {2}  legal patterns
-  if (msg_detail != null)
-  {
-    this._msg_detail = _formatErrorString(msg_detail,
-                                   { 
-                                     "2":patternsString
-                                   });
-  }
+  this._msg_summary = msg_summary; 
+  this._msg_detail = msg_detail;
+  this._patternsString = patternsString;     
   
   if (pattern != null)
   {

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Core.js
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Core.js?rev=438638&r1=438637&r2=438638&view=diff
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Core.js (original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Core.js Wed Aug 30 14:32:47 2006
@@ -2367,6 +2367,8 @@
       if (!currInput)
         continue;
 
+      var label = _getLabel(form, currInput);
+
       // if currInput is an array then multiple elements have the same name.
       // Only the first will be validated as subsequent values should be in sync
       var elementType = currInput.type;
@@ -2403,7 +2405,8 @@
         {
           requiredErrorString = _getGlobalErrorString(currInput, 
                                               globalMessageIndex, 
-                                              requiredErrorString);   
+                                              requiredErrorString,
+                                              label);   
           failures += '\n' + requiredErrorString;
         }
       }
@@ -2430,7 +2433,7 @@
             {
               var converter = eval(converterConstructor);
               try{
-                value = converter.getAsObject(value);
+                value = converter.getAsObject(value, label);
               }
               catch (e)
               {
@@ -2445,15 +2448,14 @@
                 }
   
                 // get the formatted error string for the current input
-                var errorString1 = _getErrorString(currInput,
-                                                   null,
-                                                   e);
+                var errorString1 = e.getFacesMessage().getDetail();
   
                 if (errorString1)
                 {                         
                   errorString1 = _getGlobalErrorString(currInput, 
                                                        globalMessageIndex, 
-                                                       errorString1);                                         
+                                                       errorString1,
+                                                       label);                                         
                   failures += '\n' + errorString1;
                 }
               }
@@ -2482,7 +2484,7 @@
                 var validator = eval(validatorConstructor);
 
                 try {
-                  validator.validate(value);
+                  validator.validate(value, label);
                 }
                 catch (e)
                 {
@@ -2497,15 +2499,14 @@
   
                   // get the formatted error string for the current input and
                   // formatIndex
-                  var errorString = _getErrorString(currInput,
-                                                    null,
-                                                    e);
+                  var errorString = e.getFacesMessage().getDetail();
   
                   if (errorString)
                   {     
                     errorString = _getGlobalErrorString(currInput, 
                                                         globalMessageIndex, 
-                                                        errorString);       
+                                                        errorString,
+                                                        label);       
                     failures += '\n' + errorString;
                   }
                 }
@@ -2522,10 +2523,44 @@
   return failures;
 }
 
+/**
+ * Used for the converters and validators we provide which all have the form
+ *
+ * {0} - label
+ * {1} - string value
+ * {2} - extra param
+ * {3} - extra param
+ */
+function _createFacesMessage(
+  summary,
+  detail,
+  label,
+  value,
+  param2,  
+  param3
+)
+{  
+  // format the detail error string
+  if (detail != null)
+  {
+    var patternArray = new Array();
+    patternArray[0] = label;
+    patternArray[1] = value;
+    patternArray[2] = param2;
+    patternArray[3] = param3;
+    detail = _formatErrorString(detail, patternArray);
+  }
+  
+  return new FacesMessage(summary, 
+                          detail, 
+                          FacesMessage.SEVERITY_ERROR);
+}
+
 function _getGlobalErrorString(
   input,
   formatIndex,
-  errorString
+  errorString,
+  label
   )
 {
   var form = _getForm(input);  
@@ -2537,26 +2572,13 @@
     // get the appropriate error format
     var errorFormat = errorFormats[formatIndex];
 
-    if (errorFormat)
+    if (errorFormat && label != null)
     {
-      // get the mapping of id's to labels
-      var labelMap = window["_" + _getJavascriptId(form.name) + "_Labels"];
-    
-      // get the label for this input element, if one has been
-      // associated using the ID of the input element
-      if (labelMap)
-      {
-        var label = labelMap[_getID(input)];
-        
-        if (label)
-        {
-          return _formatErrorString(errorFormat,
-                                   {
-                                     "0":label,
-                                     "1":errorString
-                                   });
-        }
-      }
+        return _formatErrorString(errorFormat,
+                                 {
+                                   "0":label,
+                                   "1":errorString
+                                 });
     }
   }   
   
@@ -2755,6 +2777,28 @@
   return false;
 }
 
+
+function _getLabel(
+  form,
+  input
+)
+{
+
+  // get the mapping of id's to labels
+  var labelMap = window["_" + _getJavascriptId(form.name) + "_Labels"];
+  
+  var label;
+  
+  // get the label for this input element, if one has been
+  // associated using the ID of the input element
+  if (labelMap)
+  {
+    label = labelMap[_getID(input)];
+  }
+  
+  return label;
+}
+
 /**
  * Return the formatted error string for an input field
  * and an errorFormatIndex
@@ -2794,18 +2838,8 @@
 
   if (errorFormat)
   {
-    // get the mapping of id's to labels
-    var labelMap = window["_" + _getJavascriptId(form.name) + "_Labels"];
-
-    var label;
-
-    // get the label for this input element, if one has been
-    // associated using the ID of the input element
-    if (labelMap)
-    {
-      label = labelMap[_getID(input)];
-    }
-
+    var label = _getLabel(form, input);
+    
     // format the error string, replacing the following tokens
     //   {0}    the value of the label
     //   {1}    the value of the input element
@@ -2820,6 +2854,8 @@
 }
 
 
+
+
 /**
  * Returns the array of validation information used to validate the form at
  * submission time.
@@ -2867,6 +2903,7 @@
 }
 
 
+
 /**
  * Performs token replacement on the the error format, replacing each
  * token found in the token Object with the value for that token.
@@ -2941,6 +2978,7 @@
   var twoSingleQuotes = /''/g;
   return currString.replace(twoSingleQuotes, "'");
 }
+
 
 /**
  * Chain two functions together returning whether the default

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js?rev=438638&r1=438637&r2=438638&view=diff
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js (original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/CoreFormat.js Wed Aug 30 14:32:47 2006
@@ -20,30 +20,24 @@
   return "" + number;
 }
 
-function _decimalFacesMessage(
-  messages,
-  messageKey
-)
-{
-  return new FacesMessage(messages[(messageKey+ '_S')], 
-                          messages[messageKey], 
-                          FacesMessage.SEVERITY_ERROR);  
-}
-
 function _decimalParse(
   numberString,
   messages,
   maxPrecision,
   maxScale,
   maxValue,
-  minValue
+  minValue,
+  label
   )
 {
   var facesMessage = null; 
   if (!numberString)
   { 
-    facesMessage = _decimalFacesMessage(messages, DecimalFormat.D);
-    throw new ConverterException(null, facesMessage);
+    facesMessage = _createFacesMessage( messages[(DecimalFormat.D+ '_S')],
+                                        messages[DecimalFormat.D],
+                                        label,
+                                        numberString);
+    throw new ConverterException(facesMessage);
   }
        
 
@@ -56,8 +50,11 @@
     if ((numberString.indexOf(grouping) == 0) ||
         (numberString.lastIndexOf(grouping) ==  (numberString.length - 1)))
     {
-      facesMessage = _decimalFacesMessage(messages, DecimalFormat.D);
-      throw new ConverterException(null, facesMessage);
+      facesMessage =  _createFacesMessage( messages[(DecimalFormat.D+ '_S')],
+                                        messages[DecimalFormat.D],
+                                        label,
+                                        numberString);
+      throw new ConverterException(facesMessage);
     }
 
     // Remove the thousands separator - which Javascript doesn't want to see
@@ -130,11 +127,14 @@
           
           if ((messages == (void 0)) ||
               (messages[messageKey] == (void 0)))
-            throw  new ConverterException("Conversion failed, but no appropriate message found");  // default error format
+            throw  new ConverterException(null, null, "Conversion failed, but no appropriate message found");  // default error format
           else
           {
-            facesMessage = _decimalFacesMessage(messages, messageKey);
-            throw new ConverterException(null, facesMessage);
+            facesMessage =  _createFacesMessage( messages[(messageKey + '_S')],
+                                        messages[messageKey],
+                                        label,
+                                        numberString);
+            throw new ConverterException(facesMessage);
           }
         }
         
@@ -143,12 +143,16 @@
     }
   }
 
-  facesMessage = _decimalFacesMessage(messages, DecimalFormat.D);
-  throw new ConverterException(null, facesMessage);
+  facesMessage = _createFacesMessage( messages[(DecimalFormat.D+ '_S')],
+                                        messages[DecimalFormat.D],
+                                        label,
+                                        numberString);
+  throw new ConverterException(facesMessage);
 }
 
 function _decimalGetAsObject(
-  numberString
+  numberString,
+  label
   )
 {
   return _decimalParse(numberString, 
@@ -156,7 +160,8 @@
                        this._maxPrecision,
                        this._maxScale,
                        this._maxValue,
-                       this._minValue);
+                       this._minValue,
+                       label);
 }
 
 function DecimalFormat(
@@ -193,7 +198,8 @@
 
 
 function _decimalValidate(
-  value
+  value,
+  label
 )
 {
   // This should probably do more than call decimalParse!
@@ -208,11 +214,12 @@
                        this._maxPrecision,
                        this._maxScale,
                        this._maxValue,
-                       this._minValue);
+                       this._minValue,
+                       label);
   }
   catch (e)
   {
-    throw new ValidatorException((void 0), e.getFacesMessage());
+    throw new ValidatorException(e.getFacesMessage());
   }
 }
 
@@ -238,7 +245,8 @@
 
 
 function _regExpParse(
-  parseString
+  parseString,
+  label
   )
 {
   //For some reason when using digits as input values 
@@ -252,22 +260,13 @@
     return parseString;
   }
   else
-  {
-    // format the error string
-    //   {2}    a legal example
-    if (this._messages[RegExpFormat.NM] != null)
-    {
-      this._messages[RegExpFormat.NM] = 
-                  _formatErrorString(this._messages[RegExpFormat.NM],
-                                     { 
-                                       "2":this._pattern
-                                     });
-    }
-
-    var facesMessage = new FacesMessage(this._messages[RegExpFormat.NMS], 
-                                        this._messages[RegExpFormat.NM], 
-                                        FacesMessage.SEVERITY_ERROR);
-    throw new ValidatorException(null, facesMessage); 
+  {    
+    var facesMessage = _createFacesMessage( this._messages[RegExpFormat.NMS],
+                                            this._messages[RegExpFormat.NM],
+                                            label,
+                                            parseString,
+                                            this._pattern);                                          
+    throw new ValidatorException(facesMessage); 
   }
 }
 

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/DateFormat.js
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/DateFormat.js?rev=438638&r1=438637&r2=438638&view=diff
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/DateFormat.js (original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/DateFormat.js Wed Aug 30 14:32:47 2006
@@ -58,13 +58,17 @@
  * parsing fails, undefined will be returned.
  */
 function _simpleDateParse(
-  parseString
+  parseString,
+  label
   )
 {
   var pattern = this._pattern;
-  var facesMessage = new FacesMessage(this._msg_summary, 
-                                      this._msg_detail, 
-                                      FacesMessage.SEVERITY_ERROR);
+  
+  var facesMessage = _createFacesMessage( this._msg_summary,
+                                          this._msg_detail,
+                                          label,
+                                          parseString,
+                                          this._exampleString);                                      
   if (typeof pattern == "string")
   {
     return _simpleDateParseImpl(parseString,
@@ -113,7 +117,7 @@
   parseContext.parsedFullYear = (void 0);
   parseContext.parsedMonth = (void 0);
   parseContext.parsedDate = (void 0);
-  parseContext.parseException = new ConverterException(null, msg);
+  parseContext.parseException = new ConverterException( msg);
 
   var parsedTime = new Date(0);
   parsedTime.setDate(1);
@@ -1257,16 +1261,9 @@
   // for debugging
   this._class = "SimpleDateFormat";
   this._msg_summary = msg_summary;
+  this._msg_detail = msg_detail;
+  this._exampleString = exampleString;
   
-  // format the error string
-  //   {2}    a legal example
-  if (msg_detail != null)
-  {
-    this._msg_detail = _formatErrorString(msg_detail,
-                                   { 
-                                     "2":exampleString
-                                   });
-  }
   
   // save the Locale elements for the specified locale, or client locale
   // if no locale is specified

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Locale.js
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Locale.js?rev=438638&r1=438637&r2=438638&view=diff
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Locale.js (original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Locale.js Wed Aug 30 14:32:47 2006
@@ -564,16 +564,18 @@
  * Convert the specified model object value, into a String for display
  *
  * @param value Model object value to be converted 
+ * @param label label to identify the editableValueHolder to the user 
  */
-Converter.prototype.getAsString = function(value){}
+Converter.prototype.getAsString = function(value, label){}
 
 /**
  * Convert the specified string value into a model data object 
  * which can be passed to validators
  *
  * @param value String value to be converted 
+ * @param label label to identify the editableValueHolder to the user 
  */
-Converter.prototype.getAsObject = function(value){}
+Converter.prototype.getAsObject = function(value, label){}
 
 
 /**
@@ -592,35 +594,37 @@
  * Perform the correctness checks implemented by this Validator. 
  * If any violations are found, a ValidatorException will be thrown 
  * containing the FacesMessage describing the failure. 
+ * @param value value to be validated 
+ * @param label label to identify the editableValueHolder to the user
  */
-Validator.prototype.validate = function(value){}
+Validator.prototype.validate = function(value, label){}
 
 
 /** 
  * ConverterException is an exception thrown by the getAsObject() or getAsString() 
  * method of a Converter, to indicate that the requested conversion cannot be performed.
  *
- * @param detail Localized detail message text, used only if facesMessage is null
  * @param facesMessage the FacesMessage associated with this exception
+ * @param summary Localized summary message text, used only if facesMessage is null
+ * @param detail Localized detail message text, used only if facesMessage is null
  */
 function ConverterException(
-  detail,
-  facesMessage
+  facesMessage, 
+  summary,
+  detail
   )
 {
-  this._facesMessage = facesMessage;
   
-  if (facesMessage == void(0))
+  if (facesMessage == null)
   {
-    if (detail != void(0))
-      this._facesMessage = new FacesMessage((void 0), 
-                                            detail, 
-                                            FacesMessage.SEVERITY_ERROR);
-    else
-      this._facesMessage = new FacesMessage("Convesion Failure",
-                                            "Convesion Failure", 
+      this._facesMessage = new FacesMessage(summary, 
+                                            detail,
                                             FacesMessage.SEVERITY_ERROR);
   }
+  else
+  {
+    this._facesMessage = facesMessage;
+  }      
     
   
 }
@@ -640,29 +644,27 @@
  * A ValidatorException is an exception thrown by the validate() method of 
  * a Validator to indicate that validation failed.
  *
- * @param detail Localized detail message text, used only if facesMessage is null
  * @param facesMessage the FacesMessage associated with this exception
+ * @param summary Localized summary message text, used only if facesMessage is null
+ * @param detail Localized detail message text, used only if facesMessage is null
  */
 function ValidatorException(
-  detail,
-  facesMessage
+  facesMessage,
+  summary, 
+  detail
   )
 {
-  this._facesMessage = facesMessage;
   
-  if (facesMessage == void(0))
+  if (facesMessage == null)
   {
-    if (detail != void(0))
-      this._facesMessage = new FacesMessage((void 0), 
+      this._facesMessage = new FacesMessage(summary, 
                                             detail,
                                             FacesMessage.SEVERITY_ERROR);
-    else
-      this._facesMessage = new FacesMessage("Validation Failure", 
-                                            "Validation Failure",
-                                            FacesMessage.SEVERITY_ERROR);
   }
-    
-  
+  else
+  {
+    this._facesMessage = facesMessage;
+  }      
 }
 
 
@@ -749,3 +751,42 @@
   {
     this._severity = severity;
   }
+
+
+/**
+ * FastMessageFormatUtils is a greatly reduced version
+ * of the java.text.MessageFormat class, but delivered as a utility. 
+ * <p>
+ * The only syntax supported by this class is simple index-based
+ * replacement, namely:
+ * <pre>
+ *     some{1}text{0}here{2}andthere
+ * </pre>
+ * as well as escaping using single quotes.  Like MessageFormat,
+ * a single quote must be represented using two consecutive single
+ * quotes, but the contents of any text between single quotes
+ * will not be interpreted.  So, the following pattern could
+ * be used to include a left bracket:
+ * <pre>
+ *     some'{'text{0}
+ * </pre>
+ */
+function FastMessageFormatUtils()
+{
+}
+
+ /**
+  * Formats the given array of strings based on the initial
+  * pattern.   It is legal for this array to be shorter
+  * than that indicated by the pattern, or to have null
+  * entries - these will simply be ignored.
+  * @param formatString an array of strings
+  * @param params an array of strings
+  */
+FastMessageFormatUtils.format = function(
+  formatString, // error format string with embedded indexes to be replaced
+  params        // array of objects to replace indexes
+  )
+{
+  return _formatErrorString(formatString, params);
+}