incubator-adffaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mat...@apache.org
Subject svn commit: r476200 - in /incubator/adffaces/trunk/trinidad/trinidad-impl/src/main: java/org/apache/myfaces/trinidadinternal/validator/ javascript/META-INF/adf/jsLibs/
Date Fri, 17 Nov 2006 16:31:02 GMT
Author: matzew
Date: Fri Nov 17 08:31:01 2006
New Revision: 476200

URL: http://svn.apache.org/viewvc?view=rev&rev=476200
Log:
refactor client side converter/validator to lookup messagesKeys and not using constructor
(ADFFACES-155)

Modified:
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/validator/ByteLengthValidator.java
    incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/validator/RegExpValidator.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/CoreFormat.js

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/validator/ByteLengthValidator.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/validator/ByteLengthValidator.java?view=diff&rev=476200&r1=476199&r2=476200
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/validator/ByteLengthValidator.java
(original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/validator/ByteLengthValidator.java
Fri Nov 17 08:31:01 2006
@@ -23,11 +23,14 @@
 import java.util.HashSet;
 import java.util.Set;
 
+import javax.faces.application.FacesMessage;
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
 
 import org.apache.myfaces.trinidad.logging.TrinidadLogger;
+import org.apache.myfaces.trinidad.util.MessageFactory;
 import org.apache.myfaces.trinidad.validator.ClientValidator;
+import org.apache.myfaces.trinidadinternal.ui.laf.base.xhtml.XhtmlLafUtils;
 
 /**
  * <p>Enables byte length validation at the client side. </p>
@@ -103,9 +106,10 @@
     }
 
     String maxLength = String.valueOf(getMaximum());
-
     constr.append(maxLength);
-
+    
+    _applyCustomMessage(context, constr, maxLength);
+    
     constr.append(")");
 
     return constr.toString();
@@ -130,6 +134,29 @@
       default:
         return null;
     }
+  }
+  
+  private void _applyCustomMessage(FacesContext context, StringBuffer constr, String maxLength)
+  {
+    String maxMsgDetail = getMessageDetailMaximum();
+    if(maxMsgDetail != null)
+    {
+      String label = "{0}";    // this will get substituted on the client
+      Object[] params = new Object[] {label, "{1}", maxLength};
+      FacesMessage msg = MessageFactory.getMessage(context,
+          ByteLengthValidator.MAXIMUM_MESSAGE_ID,
+          maxMsgDetail,
+          params);
+      
+      constr.append(",'");
+      constr.append(XhtmlLafUtils.escapeJS(msg.getSummary()));
+      constr.append("','");
+      constr.append(XhtmlLafUtils.escapeJS(msg.getDetail()));
+      constr.append("'");
+      
+    }
+    
+    
   }
 
   static private int _getType(String encoding)

Modified: incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/validator/RegExpValidator.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/validator/RegExpValidator.java?view=diff&rev=476200&r1=476199&r2=476200
==============================================================================
--- incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/validator/RegExpValidator.java
(original)
+++ incubator/adffaces/trunk/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/validator/RegExpValidator.java
Fri Nov 17 08:31:01 2006
@@ -18,9 +18,11 @@
 import java.util.Collection;
 import java.util.Collections;
 
+import javax.faces.application.FacesMessage;
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
 
+import org.apache.myfaces.trinidad.util.MessageFactory;
 import org.apache.myfaces.trinidad.validator.ClientValidator;
 import org.apache.myfaces.trinidadinternal.renderkit.core.xhtml.XhtmlUtils;
 
@@ -64,11 +66,34 @@
     StringBuffer outBuffer = new StringBuffer(22
                                               + jsPattern.length());
 
-    outBuffer.append("new TrRegExpValidator("); // 21
+    outBuffer.append("new TrRegExpValidator('"); // 21
     outBuffer.append(jsPattern);
-    outBuffer.append(")");                // 1
+    _applyCustomMessage(context, outBuffer);
+    outBuffer.append("')");                // 1
 
     return outBuffer.toString();
+  }
+  
+  private void _applyCustomMessage(FacesContext context, StringBuffer outBuffer)
+  {
+    String noMatchMsg = getMessageDetailNoMatch();
+    if(noMatchMsg != null)
+    {
+      Object[] params = new Object[] {"{0}", "{1}", "{2}"};
+
+      FacesMessage message = MessageFactory.getMessage(context,
+                                  RegExpValidator.NO_MATCH_MESSAGE_ID,
+                                  noMatchMsg,
+                                  params);
+      String esNoMatchMsgPattern = XhtmlUtils.escapeJS(message.getDetail());
+      String esNoMatchMsgSummaryPattern = 
+                               XhtmlUtils.escapeJS(message.getSummary());
+      outBuffer.append("','");            //  7
+      outBuffer.append(esNoMatchMsgSummaryPattern);
+      outBuffer.append("','");            //  7
+      outBuffer.append(esNoMatchMsgPattern);
+    }    
+
   }
   
   public Collection<String> getClientImportNames()

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?view=diff&rev=476200&r1=476199&r2=476200
==============================================================================
--- 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
Fri Nov 17 08:31:01 2006
@@ -15,21 +15,27 @@
  */
 
 function TrByteLengthValidator(
-  length
+  length,
+  summary,
+  detail
   )
 {
   this._length   = length;
+  this._summary = summary;
+  this._detail = detail;
   this._class    = "TrByteLengthValidator";
 }
 
 TrByteLengthValidator.prototype = new TrValidator();
 
 function CjkFormat(
-  length
+  length,
+  summary,
+  detail
   )
 {
   this._base = TrByteLengthValidator;
-  this._base(length);
+  this._base(length, summary,detail);
   this._class = "CjkFormat";
   
 }
@@ -51,9 +57,20 @@
    
     if (length < 0)
     {
-      var facesMessage = _createFacesMessage( "org.apache.myfaces.trinidad.validator.ByteLengthValidator.MAXIMUM",
-                                              label,
-                                              parseString);   
+      var facesMessage;
+      if(this._summary == undefined)
+      {
+        facesMessage = _createFacesMessage( "org.apache.myfaces.trinidad.validator.ByteLengthValidator.MAXIMUM",
+                                                label,
+                                                parseString);
+      }
+      else
+      {
+        facesMessage = _createCustomFacesMessage(this._summary,
+                                            this._detail,
+                                            label,
+                                            parseString);
+      }
       throw new TrValidatorException(facesMessage);     
     }
 
@@ -67,11 +84,13 @@
 
 
 function Utf8Format(
-  length
+  length,
+  summary,
+  detail
   )
 {
   this._base = TrByteLengthValidator;
-  this._base(length);
+  this._base(length, summary,detail);
   this._class = "Utf8Format";
 }
 
@@ -101,9 +120,20 @@
 
     if (length < 0)
     {
-      var facesMessage = _createFacesMessage( "org.apache.myfaces.trinidad.validator.ByteLengthValidator.MAXIMUM",
-                                              label,
-                                              parseString);   
+      var facesMessage;
+      if(this._summary == undefined)
+      {
+        facesMessage = _createFacesMessage( "org.apache.myfaces.trinidad.validator.ByteLengthValidator.MAXIMUM",
+                                                label,
+                                                parseString);
+      }
+      else
+      {
+        facesMessage = _createCustomFacesMessage(this._summary,
+                                            this._detail,
+                                            label,
+                                            parseString);
+      }
       throw new TrValidatorException(facesMessage);              
     }
 
@@ -114,11 +144,13 @@
 }
 
 function SBFormat(
-  length
+  length,
+  summary,
+  detail
   )
 {
   this._base = TrByteLengthValidator;
-  this._base(length);
+  this._base(length, summary,detail);
   this._class = "SBFormat";
   
 }
@@ -132,9 +164,20 @@
 {
   if (this._length < parseString.length)
   {
-    var facesMessage = _createFacesMessage( "org.apache.myfaces.trinidad.validator.ByteLengthValidator.MAXIMUM",
-                                              label,
-                                              parseString);   
+      var facesMessage;
+      if(this._summary == undefined)
+      {
+        facesMessage = _createFacesMessage( "org.apache.myfaces.trinidad.validator.ByteLengthValidator.MAXIMUM",
+                                                label,
+                                                parseString);
+      }
+      else
+      {
+        facesMessage = _createCustomFacesMessage(this._summary,
+                                            this._detail,
+                                            label,
+                                            parseString);
+      }
     throw new TrValidatorException(facesMessage);      
   }
 

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?view=diff&rev=476200&r1=476199&r2=476200
==============================================================================
--- 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
Fri Nov 17 08:31:01 2006
@@ -567,10 +567,14 @@
 }
 
 function TrRegExpValidator(
-  pattern
+  pattern,
+  summary,
+  detail
   )
 {  
   this._pattern  = pattern;
+  this._summary = summary;
+  this._detail = detail;
   this._class = "TrRegExpValidator";
 }
 
@@ -591,11 +595,23 @@
     return parseString;
   }
   else
-  {    
-    var facesMessage = _createFacesMessage( "org.apache.myfaces.trinidad.validator.RegExpValidator.NO_MATCH",
-                                            label,
-                                            parseString,
-                                            this._pattern);                             
            
+  {
+    var facesMessage;
+    if(this._summary == undefined)
+    {
+      facesMessage = _createFacesMessage( "org.apache.myfaces.trinidad.validator.RegExpValidator.NO_MATCH",
+                                              label,
+                                              parseString,
+                                              this._pattern);                           
              
+    }
+    else
+    {
+      facesMessage = _createCustomFacesMessage(this._summary,
+                                          this._detail,
+                                          label,
+                                          parseString,
+                                          this._pattern);                               
          
+    }
     throw new TrValidatorException(facesMessage); 
   }
 }



Mime
View raw message