You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by gp...@apache.org on 2009/11/06 17:21:13 UTC

svn commit: r833454 - /myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/HtmlCoreComponentsValidationExceptionInterceptor.java

Author: gpetracek
Date: Fri Nov  6 16:21:12 2009
New Revision: 833454

URL: http://svn.apache.org/viewvc?rev=833454&view=rev
Log:
EXTVAL-66 validatorMessage support

Modified:
    myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/HtmlCoreComponentsValidationExceptionInterceptor.java

Modified: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/HtmlCoreComponentsValidationExceptionInterceptor.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/HtmlCoreComponentsValidationExceptionInterceptor.java?rev=833454&r1=833453&r2=833454&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/HtmlCoreComponentsValidationExceptionInterceptor.java (original)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/HtmlCoreComponentsValidationExceptionInterceptor.java Fri Nov  6 16:21:12 2009
@@ -71,65 +71,98 @@
             FacesContext facesContext = FacesContext.getCurrentInstance();
             FacesMessage facesMessage = ExtValUtils.convertFacesMessage(validatorException.getFacesMessage());
 
-            String label = (String) ReflectionUtils.tryToInvokeMethod(uiComponent,
-                ReflectionUtils.tryToGetMethod(uiComponent.getClass(), "getLabel"));
+            tryToUseInlineMessage(uiComponent, validatorException);
 
-            handleRequiredValidatorException(uiComponent, validatorException);
+            tryToUseLabel(facesContext, uiComponent, metaDataEntry, facesMessage);
 
-            if(label == null)
-            {
-                label = uiComponent.getClientId(facesContext);
-            }
+            tryToBlocksNavigation(uiComponent, metaDataEntry, facesMessage);
+        }
+        return true;
+    }
 
-            //override the label if the annotation provides a label
-            if(metaDataEntry != null && metaDataEntry.getProperty(PropertyInformationKeys.LABEL) != null)
-            {
-                label = metaDataEntry.getProperty(PropertyInformationKeys.LABEL, String.class);
-            }
+    private void tryToUseInlineMessage(UIComponent uiComponent, ValidatorException validatorException)
+    {
+        FacesMessage facesMessage = validatorException.getFacesMessage();
+        String inlineMessage;
 
-            if(facesMessage instanceof LabeledMessage)
-            {
-                ((LabeledMessage)facesMessage).setLabelText(label);
-            }
-            //if someone uses a normal faces message
-            else
+        if(validatorException instanceof RequiredValidatorException)
+        {
+            inlineMessage = getInlineRequiredMessage(uiComponent);
+
+            if(inlineMessage != null)
             {
-                for(int i = 0; i < 3; i++)
-                {
-                    ExtValUtils.tryToPlaceLabel(facesMessage, label, i);
-                }
+                facesMessage.setSummary(inlineMessage);
+                facesMessage.setDetail(inlineMessage);
             }
+        }
+        else
+        {
+            //
+            inlineMessage = getInlineValidatorMessage(uiComponent);
 
-            if(metaDataEntry != null && metaDataEntry.getValue() instanceof Annotation)
+            if(inlineMessage != null)
             {
-                //correct severity is e.g. provided by ViolationSeverityValidationExceptionInterceptor
-                ExtValUtils.tryToBlocksNavigationForComponent(uiComponent, facesMessage);
+                facesMessage.setSummary(inlineMessage);
+                facesMessage.setDetail(inlineMessage);
             }
         }
-        return true;
     }
 
-    private void handleRequiredValidatorException(UIComponent uiComponent, ValidatorException validatorException)
+    private void tryToUseLabel(FacesContext facesContext,
+                               UIComponent uiComponent,
+                               MetaDataEntry metaDataEntry,
+                               FacesMessage facesMessage)
     {
-        if(validatorException instanceof RequiredValidatorException)
+        String label = (String) ReflectionUtils.tryToInvokeMethod(uiComponent,
+            ReflectionUtils.tryToGetMethod(uiComponent.getClass(), "getLabel"));
+
+        if(label == null)
         {
-            FacesMessage facesMessage = validatorException.getFacesMessage();
-            String inlineMessage = getInlineRequiredMessage(uiComponent);
+            label = uiComponent.getClientId(facesContext);
+        }
 
-            if(inlineMessage != null)
+        //override the label if the annotation provides a label
+        if(metaDataEntry != null && metaDataEntry.getProperty(PropertyInformationKeys.LABEL) != null)
+        {
+            label = metaDataEntry.getProperty(PropertyInformationKeys.LABEL, String.class);
+        }
+
+        if(facesMessage instanceof LabeledMessage)
+        {
+            ((LabeledMessage)facesMessage).setLabelText(label);
+        }
+        //if someone uses a normal faces message
+        else
+        {
+            for(int i = 0; i < 3; i++)
             {
-                facesMessage.setSummary(inlineMessage);
-                facesMessage.setDetail(inlineMessage);
+                ExtValUtils.tryToPlaceLabel(facesMessage, label, i);
             }
         }
     }
 
+    @ToDo(value = Priority.MEDIUM, description = "check if it is still required here")
+    private void tryToBlocksNavigation(UIComponent uiComponent, MetaDataEntry metaDataEntry, FacesMessage facesMessage)
+    {
+        if(metaDataEntry != null && metaDataEntry.getValue() instanceof Annotation)
+        {
+            //correct severity is e.g. provided by ViolationSeverityValidationExceptionInterceptor
+            ExtValUtils.tryToBlocksNavigationForComponent(uiComponent, facesMessage);
+        }
+    }
+
     private String getInlineRequiredMessage(UIComponent uiComponent)
     {
         return (String)ReflectionUtils.tryToInvokeMethod(uiComponent,
                 ReflectionUtils.tryToGetMethod(uiComponent.getClass(), "getRequiredMessage"));
     }
 
+    private String getInlineValidatorMessage(UIComponent uiComponent)
+    {
+        return (String)ReflectionUtils.tryToInvokeMethod(uiComponent,
+                ReflectionUtils.tryToGetMethod(uiComponent.getClass(), "getValidatorMessage"));
+    }
+
     protected boolean processComponent(UIComponent uiComponent)
     {
         return uiComponent instanceof HtmlInputText ||