Author: andyhot
Date: Wed Jun 13 19:23:34 2007
New Revision: 547090

URL: http://svn.apache.org/viewvc?view=rev&rev=547090
Log:
Easier message overriding for Identity validator

Modified:
    
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Identity.java
    
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/validator/TestIdentity.java

Modified: 
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Identity.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Identity.java?view=diff&rev=547090&r1=547089&r2=547090
==============================================================================
--- 
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Identity.java
 (original)
+++ 
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Identity.java
 Wed Jun 13 19:23:34 2007
@@ -39,7 +39,6 @@
 
     private String _fieldName;
     private int _matchType;
-    private String _identityMessage;
 
     private static final int DIFFER = 0;
     private static final int MATCH = 1;
@@ -126,31 +125,6 @@
         _fieldName = field;
         _matchType = DIFFER;
     }
-
-
-    /**
-     * Get the validation message.
-     *
-     * @return The message configured for this validator, will be null unless 
configured
-     *          via [EMAIL PROTECTED] #setIdentityMessage(String)}.
-     */
-    public String getIdentityMessage()
-    {
-        return _identityMessage;
-    }
-
-    /**
-     * Overrides the <code>field-too-short</code> bundle key. Parameter {0} is 
the minimum length.
-     * Parameter {1} is the display name of the field.
-     *
-     * @param message The message to set for this validator.
-     */
-
-    public void setIdentityMessage(String message)
-    {
-        _identityMessage = message;
-    }
-
     
     protected String buildIdentityMessage(ValidationMessages messages, 
IFormComponent field, IFormComponent referent)
     {
@@ -158,7 +132,7 @@
                 field.getDisplayName(), new Integer(_matchType), 
referent.getDisplayName()
         };
         
-        return messages.formatValidationMessage(_identityMessage,
+        return messages.formatValidationMessage(getMessage(),
                 ValidationStrings.INVALID_FIELD_EQUALITY, parameters);
     }
 

Modified: 
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/validator/TestIdentity.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/validator/TestIdentity.java?view=diff&rev=547090&r1=547089&r2=547090
==============================================================================
--- 
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/validator/TestIdentity.java
 (original)
+++ 
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/validator/TestIdentity.java
 Wed Jun 13 19:23:34 2007
@@ -72,7 +72,7 @@
         expect(otherField.getDisplayName()).andReturn("Password-2");
         
         ValidationMessages messages = newMessages();
-        trainIdentityMessages(messages, "Password-1", "Password-2", 1, 
"err1");        
+        trainIdentityMessages(messages, null, "Password-1", "Password-2", 1, 
"err1");        
 
         replay();
 
@@ -98,7 +98,8 @@
         expect(otherField.getDisplayName()).andReturn("Password-2");
         
         ValidationMessages messages = newMessages();
-        trainIdentityMessages(messages, "Password-1", "Password-2", 0, 
"error");
+        String msgOverride = "Should differ!";
+        trainIdentityMessages(messages, msgOverride, "Password-1", 
"Password-2", 0, msgOverride);
 
         replay();
 
@@ -108,7 +109,7 @@
         }
         catch (ValidatorException ex)
         {
-            assertEquals(ex.getMessage(), "error");
+            assertEquals(ex.getMessage(), msgOverride);
             assertEquals(ex.getConstraint(), ValidationConstraint.CONSISTENCY);
         }
     }
@@ -117,16 +118,16 @@
     {
         JSONObject json = new JSONObject();
         
-        IFormComponent field = newField(/*);//*/"Password", "pass1");
+        IFormComponent field = newField("Password", "pass1");
         expect(field.isDisabled()).andReturn(false);
         
-        IFormComponent otherField = newField(/*);//*/"Verify Password", 
"pass2");
+        IFormComponent otherField = newField("Verify Password", "pass2");
         trainGetContainerAndComponent(field, "other", otherField);
         
         FormComponentContributorContext context = 
newMock(FormComponentContributorContext.class);        
         expect(context.getProfile()).andReturn(json);        
                 
-        trainIdentityMessages(context, "Password", "Verify Password", 1, 
"Fields must match");        
+        trainIdentityMessages(context, null, "Password", "Verify Password", 1, 
"Fields must match");        
         
         IMarkupWriter writer = newWriter();
         IRequestCycle cycle = newCycle();
@@ -158,9 +159,10 @@
         expect(field.getBinding("value")).andReturn(ret);
     }   
 
-    private void trainIdentityMessages(ValidationMessages messages, String 
name1, String name2, int match, String result)
+    private void trainIdentityMessages(ValidationMessages messages, String 
msgOverride,
+            String name1, String name2, int match, String result)
     {
-        trainFormatMessage(messages, null, "invalid-field-equality", 
+        trainFormatMessage(messages, msgOverride, "invalid-field-equality", 
                 new Object[]{ name1, new Integer(match), name2 }, 
                 result);
     }    


Reply via email to