myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject svn commit: r826659 - in /myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/trinidad: ./ interceptor/ startup/ storage/ util/ validation/message/
Date Mon, 19 Oct 2009 13:05:06 GMT
Author: gpetracek
Date: Mon Oct 19 13:05:05 2009
New Revision: 826659

URL: http://svn.apache.org/viewvc?rev=826659&view=rev
Log:
cleanup

Modified:
    myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/trinidad/ExtValTrinidadValidationPhaseListener.java
    myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/trinidad/interceptor/TrinidadValidationExceptionInterceptor.java
    myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/trinidad/startup/TrinidadModuleStartupListener.java
    myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/trinidad/storage/DefaultClientValidatorStorage.java
    myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/trinidad/util/TrinidadUtils.java
    myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/trinidad/validation/message/TrinidadViolationMessage.java

Modified: myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/trinidad/ExtValTrinidadValidationPhaseListener.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/trinidad/ExtValTrinidadValidationPhaseListener.java?rev=826659&r1=826658&r2=826659&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/trinidad/ExtValTrinidadValidationPhaseListener.java
(original)
+++ myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/trinidad/ExtValTrinidadValidationPhaseListener.java
Mon Oct 19 13:05:05 2009
@@ -51,23 +51,36 @@
 
     public void beforePhase(PhaseEvent event)
     {
-        if(event.getPhaseId() != PhaseId.APPLY_REQUEST_VALUES && event.getPhaseId()
!= PhaseId.RENDER_RESPONSE)
-        {
-            return;
-        }
-
         FacesContext facesContext = FacesContext.getCurrentInstance();
 
-        RenderKitFactory renderKitFactory = (RenderKitFactory)
-            FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+        RenderKitFactory renderKitFactory = getRenderKitFactory();
 
-        String renderKitId = facesContext.getViewRoot().getRenderKitId();
+        String renderKitId = getRenderKitId(facesContext);
 
-        if(ExtValTrinidadRenderKit.ID.equals(renderKitId))
+        if(isIncompatibleRenderKit(renderKitId))
         {
-            return;
+            changeRenderKit(facesContext, renderKitFactory, renderKitId);
         }
+    }
+
+    private String getRenderKitId(FacesContext facesContext)
+    {
+        return facesContext.getViewRoot().getRenderKitId();
+    }
 
+    private RenderKitFactory getRenderKitFactory()
+    {
+        return (RenderKitFactory)
+            FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+    }
+
+    private boolean isIncompatibleRenderKit(String renderKitId)
+    {
+        return !ExtValTrinidadRenderKit.ID.equals(renderKitId);
+    }
+
+    private void changeRenderKit(FacesContext facesContext, RenderKitFactory renderKitFactory,
String renderKitId)
+    {
         RenderKit renderKit = renderKitFactory.getRenderKit(FacesContext.getCurrentInstance(),
renderKitId);
         renderKitFactory.addRenderKit(ExtValTrinidadRenderKit.ID, new ExtValTrinidadRenderKit(renderKit));
         facesContext.getViewRoot().setRenderKitId(ExtValTrinidadRenderKit.ID);

Modified: myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/trinidad/interceptor/TrinidadValidationExceptionInterceptor.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/trinidad/interceptor/TrinidadValidationExceptionInterceptor.java?rev=826659&r1=826658&r2=826659&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/trinidad/interceptor/TrinidadValidationExceptionInterceptor.java
(original)
+++ myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/trinidad/interceptor/TrinidadValidationExceptionInterceptor.java
Mon Oct 19 13:05:05 2009
@@ -55,44 +55,69 @@
                                  ValidatorException validatorException,
                                  ValidationStrategy validatorExceptionSource)
     {
-        refreshComponent(uiComponent);
-
         if(processComponent(uiComponent))
         {
-            FacesMessage facesMessage = validatorException.getFacesMessage();
+            tryToRefreshComponent(uiComponent);
+            tryToPlaceLabelInFacesMessage(uiComponent, metaDataEntry, validatorException);
+        }
+        return true;
+    }
 
-            handleRequiredValidatorException(uiComponent, validatorException);
+    private void tryToPlaceLabelInFacesMessage(
+            UIComponent uiComponent, MetaDataEntry metaDataEntry, ValidatorException validatorException)
+    {
+        tryToHandleRequiredValidatorException(uiComponent, validatorException);
 
-            String label = getLabel(uiComponent);
+        String label = detectLabelText(metaDataEntry, uiComponent);
 
-            if(label == null)
-            {
-                label = uiComponent.getClientId(FacesContext.getCurrentInstance());
-            }
+        processLabel(validatorException.getFacesMessage(), label);
+    }
 
-            //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 String detectLabelText(MetaDataEntry metaDataEntry, UIComponent uiComponent)
+    {
+        String label = getLabel(uiComponent);
 
-            if(facesMessage instanceof LabeledMessage)
-            {
-                ((LabeledMessage)facesMessage).setLabelText(label);
-            }
-            //if someone uses a normal faces message
-            else
+        label = getClientIdAsFallbackIfNeeded(uiComponent, label);
+
+        label = tryToOverrideLabelIfProvidedManually(metaDataEntry, label);
+        return label;
+    }
+
+    private void processLabel(FacesMessage facesMessage, String label)
+    {
+        if(facesMessage instanceof LabeledMessage)
+        {
+            ((LabeledMessage)facesMessage).setLabelText(label);
+        }
+        //if someone uses a normal faces message
+        else
+        {
+            for(int i = 0; i < 3; i++)
             {
-                for(int i = 0; i < 3; i++)
-                {
-                    ExtValUtils.tryToPlaceLabel(facesMessage, label, i);
-                }
+                ExtValUtils.tryToPlaceLabel(facesMessage, label, i);
             }
         }
-        return true;
     }
 
-    private void handleRequiredValidatorException(UIComponent uiComponent, ValidatorException
validatorException)
+    private String tryToOverrideLabelIfProvidedManually(MetaDataEntry metaDataEntry, String
label)
+    {
+        if(metaDataEntry != null && metaDataEntry.getProperty(PropertyInformationKeys.LABEL)
!= null)
+        {
+            return metaDataEntry.getProperty(PropertyInformationKeys.LABEL, String.class);
+        }
+        return label;
+    }
+
+    private String getClientIdAsFallbackIfNeeded(UIComponent uiComponent, String label)
+    {
+        if(label == null)
+        {
+            return uiComponent.getClientId(FacesContext.getCurrentInstance());
+        }
+        return label;
+    }
+
+    private void tryToHandleRequiredValidatorException(UIComponent uiComponent, ValidatorException
validatorException)
     {
         if(validatorException instanceof RequiredValidatorException)
         {
@@ -107,7 +132,7 @@
         }
     }
 
-    private void refreshComponent(UIComponent uiComponent)
+    private void tryToRefreshComponent(UIComponent uiComponent)
     {
         if(RequestContext.getCurrentInstance().isPartialRequest(FacesContext.getCurrentInstance()))
         {

Modified: myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/trinidad/startup/TrinidadModuleStartupListener.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/trinidad/startup/TrinidadModuleStartupListener.java?rev=826659&r1=826658&r2=826659&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/trinidad/startup/TrinidadModuleStartupListener.java
(original)
+++ myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/trinidad/startup/TrinidadModuleStartupListener.java
Mon Oct 19 13:05:05 2009
@@ -49,58 +49,99 @@
 
     protected void init()
     {
-        initTrinidadSupport();
+        deactivateDefaultExtValRenderKitWrapperFactory();
+
+        initClientSideValidationSupport();
+
+        initLabelInitializationSupport();
+
+        initValidationExceptionInterception();
+
+        replaceDefaultProxyWithTrinidadRendererProxy();
+
+        initTrinidadFacesMessageFactory();
+        /*
+         * if there are further incompatible renderers use the following quick-fix:
+         *         ExtValContext.getContext()
+                .addGlobalProperty(ExtValRendererProxy.KEY, null);
+           attention: it causes direct delegation without a check of double invocations
+         */
+
+        initTrinidadMetaDataExtractionInterceptor();
+
+        initTrinidadClientValidatorStorage();
     }
 
-    private void initTrinidadSupport()
+    private void deactivateDefaultExtValRenderKitWrapperFactory()
     {
-        //deactivate default approach
         ExtValContext.getContext().getFactoryFinder()
             .getFactory(FactoryNames.RENDERKIT_WRAPPER_FACTORY, AbstractRenderKitWrapperFactory.class).deactivate();
-        
-        String deactivateClientSideValidation = WebXmlParameter.DEACTIVATE_CLIENT_SIDE_TRINIDAD_VALIDATION;
+    }
 
-        if(deactivateClientSideValidation == null || !deactivateClientSideValidation.equalsIgnoreCase("true"))
+    private void initClientSideValidationSupport()
+    {
+        if(isClientSideValidationSupportEnabled(WebXmlParameter.DEACTIVATE_CLIENT_SIDE_TRINIDAD_VALIDATION))
         {
             ExtValContext.getContext().addComponentInitializer(new TrinidadComponentInitializer());
         }
+    }
 
-        String deactivateInitCoreOutputLabel = WebXmlParameter.DEACTIVATE_TRINIDAD_CORE_OUTPUT_LABEL_INITIALIZATION;
-
-        if(deactivateInitCoreOutputLabel == null || !deactivateInitCoreOutputLabel.equalsIgnoreCase("true"))
+    private void initLabelInitializationSupport()
+    {
+        if(isLabelInitializationEnabled(WebXmlParameter.DEACTIVATE_TRINIDAD_CORE_OUTPUT_LABEL_INITIALIZATION))
         {
             ExtValContext.getContext().registerRendererInterceptor(new TrinidadRendererInterceptor());
         }
+    }
 
-        String deactivateTrinidadValidationExceptionInterceptor =
-                WebXmlParameter.DEACTIVATE_TRINIDAD_VALIDATION_EXCEPTION_INTERCEPTOR;
-
-        if(deactivateTrinidadValidationExceptionInterceptor == null ||
-                !deactivateTrinidadValidationExceptionInterceptor.equalsIgnoreCase("true"))
+    private void initValidationExceptionInterception()
+    {
+        if(useValidationExceptionInterception(WebXmlParameter.DEACTIVATE_TRINIDAD_VALIDATION_EXCEPTION_INTERCEPTOR))
         {
             ExtValContext.getContext().addValidationExceptionInterceptor(new TrinidadValidationExceptionInterceptor());
         }
+    }
 
-        //deactivate extval renderer proxy - due to an incompatibility with the table renderer
+    private void replaceDefaultProxyWithTrinidadRendererProxy()
+    {
         ExtValContext.getContext()
                 .addGlobalProperty(ExtValRendererProxy.KEY, ExtValTrinidadRendererProxy.class.getName());
+    }
 
+    private void initTrinidadFacesMessageFactory()
+    {
         ExtValContext.getContext()
                 .addGlobalProperty(
                         FactoryNames.FACES_MESSAGE_FACTORY.name(),
                         TrinidadFacesMessageFactory.class.getName());
-        /*
-         * if there are further incompatible renderers use the following quick-fix:
-         *         ExtValContext.getContext()
-                .addGlobalProperty(ExtValRendererProxy.KEY, null);
-           attention: it causes direct delegation without a check of double invocations
-         */
+    }
 
+    private void initTrinidadMetaDataExtractionInterceptor()
+    {
         ExtValContext.getContext().addMetaDataExtractionInterceptor(new TrinidadMetaDataExtractionInterceptor());
+    }
 
+    private void initTrinidadClientValidatorStorage()
+    {
         ExtValContext.getContext().getFactoryFinder()
                 .getFactory(FactoryNames.STORAGE_MANAGER_FACTORY, StorageManagerHolder.class)
                 .setStorageManager(TrinidadClientValidatorStorage.class,
                         new DefaultClientValidatorStorageManager(), false);
     }
+
+    private boolean isLabelInitializationEnabled(String deactivateInitCoreOutputLabel)
+    {
+        return deactivateInitCoreOutputLabel == null || !deactivateInitCoreOutputLabel.equalsIgnoreCase("true");
+    }
+
+    private boolean isClientSideValidationSupportEnabled(String deactivateClientSideValidation)
+    {
+        return deactivateClientSideValidation == null || !deactivateClientSideValidation.equalsIgnoreCase("true");
+    }
+
+    private boolean useValidationExceptionInterception(String deactivateTrinidadValidationExceptionInterceptor)
+    {
+        return deactivateTrinidadValidationExceptionInterceptor == null ||
+                !deactivateTrinidadValidationExceptionInterceptor.equalsIgnoreCase("true");
+    }
 }

Modified: myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/trinidad/storage/DefaultClientValidatorStorage.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/trinidad/storage/DefaultClientValidatorStorage.java?rev=826659&r1=826658&r2=826659&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/trinidad/storage/DefaultClientValidatorStorage.java
(original)
+++ myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/trinidad/storage/DefaultClientValidatorStorage.java
Mon Oct 19 13:05:05 2009
@@ -58,13 +58,7 @@
     {
         if (uiComponent instanceof EditableValueHolder)
         {
-            for (Validator validator : ((EditableValueHolder) uiComponent).getValidators())
-            {
-                if (validator instanceof ExtValTrinidadClientValidatorWrapper)
-                {
-                    ((EditableValueHolder) uiComponent).removeValidator(validator);
-                }
-            }
+            removeWrapperFromComponent(uiComponent);
         }
         else
         {
@@ -75,4 +69,15 @@
             }
         }
     }
+
+    private void removeWrapperFromComponent(UIComponent uiComponent)
+    {
+        for (Validator validator : ((EditableValueHolder) uiComponent).getValidators())
+        {
+            if (validator instanceof ExtValTrinidadClientValidatorWrapper)
+            {
+                ((EditableValueHolder) uiComponent).removeValidator(validator);
+            }
+        }
+    }
 }
\ No newline at end of file

Modified: myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/trinidad/util/TrinidadUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/trinidad/util/TrinidadUtils.java?rev=826659&r1=826658&r2=826659&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/trinidad/util/TrinidadUtils.java
(original)
+++ myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/trinidad/util/TrinidadUtils.java
Mon Oct 19 13:05:05 2009
@@ -43,13 +43,13 @@
     public static UIComponent findLabeledEditableComponent(CoreOutputLabel coreOutputLabel)
     {
         //TODO
-        if(coreOutputLabel.getFor() == null)
+        if(isLabelTargetAvailable(coreOutputLabel))
         {
             return null;
         }
 
         FacesContext facesContext = FacesContext.getCurrentInstance();
-        UIComponent result = facesContext.getViewRoot().findComponent(coreOutputLabel.getFor());
+        UIComponent result = resolveLabelTarget(facesContext, coreOutputLabel);
 
         if(result instanceof EditableValueHolder)
         {
@@ -63,4 +63,14 @@
 
         return null;
     }
+
+    private static UIComponent resolveLabelTarget(FacesContext facesContext, CoreOutputLabel
coreOutputLabel)
+    {
+        return facesContext.getViewRoot().findComponent(coreOutputLabel.getFor());
+    }
+
+    private static boolean isLabelTargetAvailable(CoreOutputLabel coreOutputLabel)
+    {
+        return coreOutputLabel.getFor() == null;
+    }
 }

Modified: myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/trinidad/validation/message/TrinidadViolationMessage.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/trinidad/validation/message/TrinidadViolationMessage.java?rev=826659&r1=826658&r2=826659&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/trinidad/validation/message/TrinidadViolationMessage.java
(original)
+++ myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/trinidad/validation/message/TrinidadViolationMessage.java
Mon Oct 19 13:05:05 2009
@@ -18,14 +18,14 @@
  */
 package org.apache.myfaces.extensions.validator.trinidad.validation.message;
 
-import org.apache.myfaces.trinidad.util.LabeledFacesMessage;
-import org.apache.myfaces.extensions.validator.internal.UsageInformation;
-import org.apache.myfaces.extensions.validator.internal.UsageCategory;
 import org.apache.myfaces.extensions.validator.core.validation.message.LabeledMessage;
+import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
 import org.apache.myfaces.extensions.validator.util.ExtValUtils;
+import org.apache.myfaces.trinidad.util.LabeledFacesMessage;
 
-import javax.faces.context.FacesContext;
 import javax.faces.application.FacesMessage;
+import javax.faces.context.FacesContext;
 
 /**
  * @author Gerhard Petracek
@@ -52,7 +52,7 @@
     {
         FacesMessage result = tryToPlaceLabel(super.getSummary());
 
-        if(result != null)
+        if (result != null)
         {
             super.setSummary(result.getSummary());
             return result.getSummary();
@@ -66,7 +66,7 @@
     {
         FacesMessage result = tryToPlaceLabel(super.getDetail());
 
-        if(result != null)
+        if (result != null)
         {
             super.setDetail(result.getDetail());
             return result.getDetail();
@@ -77,21 +77,36 @@
 
     private FacesMessage tryToPlaceLabel(String originalMessage)
     {
-        if(!(originalMessage != null &&
-                originalMessage.startsWith(MISSING_RESOURCE_MARKER) &&
-                originalMessage.endsWith(MISSING_RESOURCE_MARKER)))
+        if (isValidMessage(originalMessage))
         {
-            FacesMessage newFacesMessage = new FacesMessage(super.getSeverity(), super.getSummary(),
super.getDetail());
-            for(int i = 0; i < 3; i++)
-            {
-                ExtValUtils.tryToPlaceLabel(newFacesMessage, getLabelText(), i);
-            }
+            FacesMessage newFacesMessage = createOriginalFacesMessage();
+            tryToPlaceLabelIn(newFacesMessage);
             return newFacesMessage;
         }
 
         return null;
     }
 
+    private FacesMessage createOriginalFacesMessage()
+    {
+        return new FacesMessage(super.getSeverity(), super.getSummary(), super.getDetail());
+    }
+
+    private void tryToPlaceLabelIn(FacesMessage newFacesMessage)
+    {
+        for (int i = 0; i < 3; i++)
+        {
+            ExtValUtils.tryToPlaceLabel(newFacesMessage, getLabelText(), i);
+        }
+    }
+
+    private boolean isValidMessage(String originalMessage)
+    {
+        return !(originalMessage != null &&
+                originalMessage.startsWith(MISSING_RESOURCE_MARKER) &&
+                originalMessage.endsWith(MISSING_RESOURCE_MARKER));
+    }
+
     public void setLabelText(String label)
     {
         super.setLabel(label);



Mime
View raw message