myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject svn commit: r832979 - /myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/
Date Thu, 05 Nov 2009 02:52:35 GMT
Author: gpetracek
Date: Thu Nov  5 02:52:34 2009
New Revision: 832979

URL: http://svn.apache.org/viewvc?rev=832979&view=rev
Log:
improved message template support

Modified:
    myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/BeanValidationUtils.java
    myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/ExtValBeanValidationMetaDataInternals.java
    myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/LabeledMessageInternals.java

Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/BeanValidationUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/BeanValidationUtils.java?rev=832979&r1=832978&r2=832979&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/BeanValidationUtils.java
(original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/BeanValidationUtils.java
Thu Nov  5 02:52:34 2009
@@ -105,25 +105,28 @@
     {
         String violationMessage = violation.getMessage();
 
-        String labeledMessage = bvmi.createLabeledMessage(violationMessage);
+        String labeledMessageSummary = bvmi.createLabeledMessage(violationMessage, false);
+        String labeledMessageDetail = bvmi.createLabeledMessage(violationMessage, true);
 
         FacesMessage.Severity severity = bvmi.calcSeverity(violation);
 
-        ValidatorException validatorException = bvmi.createValidatorException(labeledMessage,
severity);
+        ValidatorException validatorException = bvmi
+                .createValidatorException(labeledMessageSummary, labeledMessageDetail, severity);
 
         if (!bvmi.executeAfterThrowingInterceptors(uiComponent, convertedObject, validatorException))
         {
             return null;
         }
 
-        if (bvmi.isMessageTextUnchanged(validatorException, labeledMessage))
+        if (bvmi.isMessageTextUnchanged(validatorException, labeledMessageSummary, labeledMessageDetail))
         {
             return ExtValUtils.createFacesMessage(severity, violationMessage, violationMessage);
         }
         else
         {
-            String newMessage = validatorException.getFacesMessage().getSummary();
-            return ExtValUtils.createFacesMessage(severity, newMessage, newMessage);
+            return ExtValUtils.createFacesMessage(severity,
+                    validatorException.getFacesMessage().getSummary(),
+                    validatorException.getFacesMessage().getDetail());
         }
     }
 

Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/ExtValBeanValidationMetaDataInternals.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/ExtValBeanValidationMetaDataInternals.java?rev=832979&r1=832978&r2=832979&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/ExtValBeanValidationMetaDataInternals.java
(original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/ExtValBeanValidationMetaDataInternals.java
Thu Nov  5 02:52:34 2009
@@ -544,9 +544,9 @@
         }
     }
 
-    String createLabeledMessage(String violationMessage)
+    String createLabeledMessage(String violationMessage, boolean isDetailMessage)
     {
-        return labeledMessageInternals.createLabeledMessage(violationMessage);
+        return this.labeledMessageInternals.createLabeledMessage(violationMessage, isDetailMessage);
     }
 
     FacesMessage.Severity calcSeverity(ConstraintViolation<?> violation)
@@ -591,16 +591,18 @@
                 null);
     }
 
-    boolean isMessageTextUnchanged(ValidatorException validatorException, String violationMessage)
+    boolean isMessageTextUnchanged(
+            ValidatorException validatorException, String violationSummaryMessage, String
violationDetailMessage)
     {
-        return violationMessage.equals(validatorException.getFacesMessage().getSummary())
||
-                violationMessage.equals(validatorException.getFacesMessage().getDetail());
+        return violationSummaryMessage.equals(validatorException.getFacesMessage().getSummary())
&&
+                violationDetailMessage.equals(validatorException.getFacesMessage().getDetail());
     }
 
-    ValidatorException createValidatorException(String violationMessage, FacesMessage.Severity
severity)
+    ValidatorException createValidatorException(
+            String violationSummaryMessage, String violationDetailMessage, FacesMessage.Severity
severity)
     {
         return new ValidatorException(
-                ExtValUtils.createFacesMessage(severity, violationMessage, violationMessage));
+                ExtValUtils.createFacesMessage(severity, violationSummaryMessage, violationDetailMessage));
     }
 
     List<FacesMessageHolder> getFacesMessageListWithLowSeverity(

Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/LabeledMessageInternals.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/LabeledMessageInternals.java?rev=832979&r1=832978&r2=832979&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/LabeledMessageInternals.java
(original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/util/LabeledMessageInternals.java
Thu Nov  5 02:52:34 2009
@@ -32,32 +32,73 @@
 class LabeledMessageInternals
 {
     //there is no concurrency issue here - it always leads to the same result
-    private final String defaultLabelMessageTemplate = "{1}: {0}";
-    private String labelMessageTemplate = defaultLabelMessageTemplate;
+    private final String defaultSummaryMessageTemplate = "{1}: {0}";
+    private final String defaultDetailMessageTemplate = "{1}: {0}";
+    private String summaryMessageTemplate = defaultSummaryMessageTemplate;
+    private String detailMessageTemplate = defaultDetailMessageTemplate;
     private static final String JAVAX_FACES_VALIDATOR_BEANVALIDATOR_MESSAGE =
             "javax.faces.validator.BeanValidator.MESSAGE";
+    private static final String JAVAX_FACES_VALIDATOR_BEANVALIDATOR_MESSAGE_DETAIL =
+            "javax.faces.validator.BeanValidator.MESSAGE_detail";
 
-    String createLabeledMessage(String violationMessage)
+    String createLabeledMessage(String violationMessage, boolean isDetailMessage)
     {
-        if(labelMessageTemplate == null)
+        if(isDetailMessage)
         {
-            return this.defaultLabelMessageTemplate.replace("{0}", violationMessage);
+            return tryToResolveDetailMessage(violationMessage);
+        }
+        else
+        {
+            return tryToResolveSummaryMessage(violationMessage);
+        }
+    }
+
+    private String tryToResolveSummaryMessage(String violationMessage)
+    {
+        if(summaryMessageTemplate == null)
+        {
+            return this.defaultSummaryMessageTemplate.replace("{0}", violationMessage);
+        }
+
+        this.summaryMessageTemplate = loadStandardMessageTemplate(false);
+
+        if(summaryMessageTemplate == null)
+        {
+            return createLabeledMessage(violationMessage, false);
+        }
+        return summaryMessageTemplate.replace("{0}", violationMessage);
+    }
+
+    private String tryToResolveDetailMessage(String violationMessage)
+    {
+        if(detailMessageTemplate == null)
+        {
+            return this.defaultDetailMessageTemplate.replace("{0}", violationMessage);
         }
 
-        this.labelMessageTemplate = loadStandardMessageTemplate();
+        this.detailMessageTemplate = loadStandardMessageTemplate(true);
 
-        if(labelMessageTemplate == null)
+        if(detailMessageTemplate == null)
         {
-            return createLabeledMessage(violationMessage);
+            return createLabeledMessage(violationMessage, true);
         }
-        return labelMessageTemplate.replace("{0}", violationMessage);
+        return detailMessageTemplate.replace("{0}", violationMessage);
     }
 
-    private String loadStandardMessageTemplate()
+    private String loadStandardMessageTemplate(boolean isDetailMessage)
     {
         try
         {
-            return JsfUtils.getDefaultFacesMessageBundle().getString(JAVAX_FACES_VALIDATOR_BEANVALIDATOR_MESSAGE);
+            if(isDetailMessage)
+            {
+                return JsfUtils.getDefaultFacesMessageBundle()
+                        .getString(JAVAX_FACES_VALIDATOR_BEANVALIDATOR_MESSAGE_DETAIL);
+            }
+            else
+            {
+                return JsfUtils.getDefaultFacesMessageBundle()
+                        .getString(JAVAX_FACES_VALIDATOR_BEANVALIDATOR_MESSAGE);
+            }
         }
         catch (MissingResourceException e)
         {



Mime
View raw message