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/10/22 21:46:30 UTC
svn commit: r828830 [1/2] - in
/myfaces/extensions/validator/branches/branch_for_jsf_1_1:
core/src/main/java/org/apache/myfaces/extensions/validator/core/
core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/
core/src/main/java/o...
Author: gpetracek
Date: Thu Oct 22 19:46:27 2009
New Revision: 828830
URL: http://svn.apache.org/viewvc?rev=828830&view=rev
Log:
EXTVAL-44 and minor refactorings
Added:
myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/FacesMessagePropertyValidationInterceptor.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/ViolationSeverityValidationExceptionInterceptor.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/DefaultFacesMessageStorage.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/DefaultFacesMessageStorageManager.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/FacesMessageStorage.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/ValidationResult.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/mapper/DefaultFacesMessageStorageNameMapper.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/message/FacesMessageHolder.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/parameter/DefaultViolationSeverityInterpreter.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/parameter/ViolationSeverityInterpreter.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/payload/ViolationSeverity.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
myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/validation/ModelValidationResult.java
Modified:
myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/ExtValContext.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/AbstractValidationInterceptor.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/HtmlCoreComponentsValidationExceptionInterceptor.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/startup/ExtValStartupListener.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/DefaultGroupStorage.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/DefaultStorageManagerFactory.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/GroupStorage.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/strategy/AbstractValidationStrategy.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/util/ExtValUtils.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/util/GroupUtils.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/examples/feature-set_01/src/main/java/org/apache/myfaces/extensions/validator/demo/gui/beans/RegistrationPage.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/examples/feature-set_02/src/main/java/org/apache/myfaces/extensions/validator/demo/gui/beans/RegistrationPage.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/BeanValidationInterceptor.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/BeanValidationInterceptorInternals.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/ExtValBeanValidationContext.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/metadata/transformer/AbstractBeanValidationMetaDataTransformer.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/storage/DefaultBeanValidationGroupStorage.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/storage/DefaultModelValidationStorage.java
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/validation/ModelValidationPhaseListener.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/CrossValidationPhaseListener.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/crossval/strategy/AbstractCompareStrategy.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/property-validation/src/test/java/org/apache/myfaces/extensions/validator/test/core/interceptor/RegistrationPropertyValidationInterceptorTestCase.java
myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/property-validation/src/test/java/org/apache/myfaces/extensions/validator/test/core/interceptor/RegistrationValidationExceptionInterceptorTestCase.java
Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/ExtValContext.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/ExtValContext.java?rev=828830&r1=828829&r2=828830&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/ExtValContext.java (original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/ExtValContext.java Thu Oct 22 19:46:27 2009
@@ -32,6 +32,7 @@
import org.apache.myfaces.extensions.validator.core.metadata.MetaDataEntry;
import org.apache.myfaces.extensions.validator.core.recorder.ProcessedInformationRecorder;
import org.apache.myfaces.extensions.validator.core.validation.SkipValidationEvaluator;
+import org.apache.myfaces.extensions.validator.core.validation.parameter.ViolationSeverityInterpreter;
import org.apache.myfaces.extensions.validator.core.validation.strategy.ValidationStrategy;
import org.apache.myfaces.extensions.validator.internal.UsageCategory;
import org.apache.myfaces.extensions.validator.internal.UsageInformation;
@@ -58,6 +59,7 @@
private static ExtValContext extValContext;
+ private ViolationSeverityInterpreter violationSeverityInterpreter;
private FactoryFinder factoryFinder = DefaultFactoryFinder.getInstance();
private Map<String, RendererInterceptor> rendererInterceptors = new HashMap<String, RendererInterceptor>();
private List<String> deniedInterceptors = new ArrayList<String>();
@@ -96,9 +98,32 @@
return extValContext;
}
+ public void setViolationSeverityInterpreter(ViolationSeverityInterpreter violationSeverityInterpreter)
+ {
+ setViolationSeverityInterpreter(violationSeverityInterpreter, true);
+ }
+
+ public void setViolationSeverityInterpreter(
+ ViolationSeverityInterpreter violationSeverityInterpreter, boolean forceOverride)
+ {
+ if (this.violationSeverityInterpreter == null || forceOverride)
+ {
+ if (this.logger.isInfoEnabled() && violationSeverityInterpreter != null)
+ {
+ this.logger.info(violationSeverityInterpreter.getClass() + " is used");
+ }
+ this.violationSeverityInterpreter = violationSeverityInterpreter;
+ }
+ }
+
+ public ViolationSeverityInterpreter getViolationSeverityInterpreter()
+ {
+ return this.violationSeverityInterpreter;
+ }
+
/*
- * FactoryFinder
- */
+ * FactoryFinder
+ */
public FactoryFinder getFactoryFinder()
{
return this.factoryFinder;
@@ -124,10 +149,9 @@
{
if (this.skipValidationEvaluator == null || forceOverride)
{
- if (this.logger.isInfoEnabled())
+ if (this.logger.isInfoEnabled() && skipValidationEvaluator != null)
{
- this.logger.info(skipValidationEvaluator != null ?
- skipValidationEvaluator.getClass() : "no" + " is used");
+ this.logger.info(skipValidationEvaluator.getClass() + " is used");
}
this.skipValidationEvaluator = skipValidationEvaluator;
}
Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/AbstractValidationInterceptor.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/AbstractValidationInterceptor.java?rev=828830&r1=828829&r2=828830&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/AbstractValidationInterceptor.java (original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/AbstractValidationInterceptor.java Thu Oct 22 19:46:27 2009
@@ -107,7 +107,15 @@
}
catch (ValidatorException e)
{
- throw new ConverterException(e.getFacesMessage(), e);
+ try
+ {
+ //ViolationSeverityInterpreter might decide that it isn't an exception
+ ExtValUtils.tryToThrowValidatorExceptionForComponent(uiComponent, e.getFacesMessage(), e);
+ }
+ catch (ValidatorException finalException)
+ {
+ throw new ConverterException(e.getFacesMessage(), e);
+ }
}
}
Added: myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/FacesMessagePropertyValidationInterceptor.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/FacesMessagePropertyValidationInterceptor.java?rev=828830&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/FacesMessagePropertyValidationInterceptor.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/FacesMessagePropertyValidationInterceptor.java Thu Oct 22 19:46:27 2009
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.validator.core.interceptor;
+
+import org.apache.myfaces.extensions.validator.core.InvocationOrder;
+import org.apache.myfaces.extensions.validator.core.storage.FacesMessageStorage;
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+import org.apache.myfaces.extensions.validator.util.ExtValUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import java.util.Map;
+
+/**
+ * @author Gerhard Petracek
+ * @since x.x.3
+ */
+@InvocationOrder(900)
+@UsageInformation(UsageCategory.INTERNAL)
+public class FacesMessagePropertyValidationInterceptor implements PropertyValidationInterceptor
+{
+ protected final Log logger = LogFactory.getLog(getClass());
+
+ public boolean beforeValidation(
+ FacesContext facesContext, UIComponent uiComponent, Object convertedObject, Map<String, Object> properties)
+ {
+ return true;
+ }
+
+ public void afterValidation(
+ FacesContext facesContext, UIComponent uiComponent, Object convertedObject, Map<String, Object> properties)
+ {
+ FacesMessageStorage facesMessageStorage = ExtValUtils.getStorage(
+ FacesMessageStorage.class, FacesMessageStorage.class.getName());
+
+ if(facesMessageStorage != null)
+ {
+ facesMessageStorage.addAll();
+ }
+ }
+}
Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/HtmlCoreComponentsValidationExceptionInterceptor.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/HtmlCoreComponentsValidationExceptionInterceptor.java?rev=828830&r1=828829&r2=828830&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/HtmlCoreComponentsValidationExceptionInterceptor.java (original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/HtmlCoreComponentsValidationExceptionInterceptor.java Thu Oct 22 19:46:27 2009
@@ -22,7 +22,6 @@
import org.apache.myfaces.extensions.validator.core.property.PropertyInformationKeys;
import org.apache.myfaces.extensions.validator.core.validation.strategy.ValidationStrategy;
import org.apache.myfaces.extensions.validator.core.validation.message.LabeledMessage;
-import org.apache.myfaces.extensions.validator.core.validation.parameter.ViolationSeverity;
import org.apache.myfaces.extensions.validator.core.validation.exception.RequiredValidatorException;
import org.apache.myfaces.extensions.validator.core.InvocationOrder;
import org.apache.myfaces.extensions.validator.internal.UsageInformation;
@@ -55,8 +54,9 @@
* @author Gerhard Petracek
* @since 1.x.1
*/
-@InvocationOrder(200)
+@InvocationOrder(100)
@UsageInformation(UsageCategory.INTERNAL)
+@ToDo(value = Priority.HIGH, description = "check compatibility with bv-integration")
public class HtmlCoreComponentsValidationExceptionInterceptor implements ValidationExceptionInterceptor
{
protected final Log logger = LogFactory.getLog(getClass());
@@ -103,9 +103,10 @@
if(metaDataEntry != null && metaDataEntry.getValue() instanceof Annotation)
{
- if(!displayAsException(facesMessage, metaDataEntry.getValue(Annotation.class)))
+ //correct severity is e.g. provided by ViolationSeverityValidationExceptionInterceptor
+ ExtValUtils.tryToBlocksNavigationForComponent(uiComponent, facesMessage);
+ if(!FacesContext.getCurrentInstance().getRenderResponse())
{
- facesContext.addMessage(uiComponent.getClientId(facesContext), facesMessage);
//it's a special case - since validation will continue it's essential to reset it
((EditableValueHolder)uiComponent).setRequired(false);
return false;
@@ -136,24 +137,6 @@
ReflectionUtils.tryToGetMethod(uiComponent.getClass(), "getRequiredMessage"));
}
- @ToDo(value = Priority.MEDIUM, description = "refactor to a generic parameter extractor")
- private boolean displayAsException(FacesMessage facesMessage, Annotation annotation)
- {
- boolean isError = true;
-
- for(FacesMessage.Severity severity : ExtValUtils.getValidationParameterExtractor()
- .extract(annotation, ViolationSeverity.class, FacesMessage.Severity.class))
- {
- if(severity.compareTo(facesMessage.getSeverity()) < 0)
- {
- facesMessage.setSeverity(severity);
- isError = false;
- }
- }
-
- return isError;
- }
-
protected boolean processComponent(UIComponent uiComponent)
{
return uiComponent instanceof HtmlInputText ||
Added: myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/ViolationSeverityValidationExceptionInterceptor.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/ViolationSeverityValidationExceptionInterceptor.java?rev=828830&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/ViolationSeverityValidationExceptionInterceptor.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/interceptor/ViolationSeverityValidationExceptionInterceptor.java Thu Oct 22 19:46:27 2009
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.validator.core.interceptor;
+
+import org.apache.myfaces.extensions.validator.core.metadata.MetaDataEntry;
+import org.apache.myfaces.extensions.validator.core.validation.strategy.ValidationStrategy;
+import org.apache.myfaces.extensions.validator.core.validation.parameter.ViolationSeverity;
+import org.apache.myfaces.extensions.validator.core.InvocationOrder;
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+import org.apache.myfaces.extensions.validator.internal.ToDo;
+import org.apache.myfaces.extensions.validator.internal.Priority;
+import org.apache.myfaces.extensions.validator.util.ExtValUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.faces.component.UIComponent;
+import javax.faces.validator.ValidatorException;
+import javax.faces.application.FacesMessage;
+import java.lang.annotation.Annotation;
+
+/**
+ * @author Gerhard Petracek
+ * @since x.x.3
+ */
+@InvocationOrder(90)
+@UsageInformation(UsageCategory.INTERNAL)
+@ToDo(value = Priority.HIGH, description = "check compatibility with bv-integration")
+public class ViolationSeverityValidationExceptionInterceptor implements ValidationExceptionInterceptor
+{
+ protected final Log logger = LogFactory.getLog(getClass());
+
+ public boolean afterThrowing(UIComponent uiComponent,
+ MetaDataEntry metaDataEntry,
+ Object convertedObject,
+ ValidatorException validatorException,
+ ValidationStrategy validatorExceptionSource)
+ {
+ if(metaDataEntry.getValue() instanceof Annotation)
+ {
+ tryToPlaceSeverity(validatorException, metaDataEntry.getValue(Annotation.class));
+ }
+ return true;
+ }
+
+ private void tryToPlaceSeverity(ValidatorException validatorException, Annotation annotation)
+ {
+ for(FacesMessage.Severity severity : ExtValUtils.getValidationParameterExtractor()
+ .extract(annotation, ViolationSeverity.class, FacesMessage.Severity.class))
+ {
+ validatorException.getFacesMessage().setSeverity(severity);
+ }
+ }
+}
Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/startup/ExtValStartupListener.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/startup/ExtValStartupListener.java?rev=828830&r1=828829&r2=828830&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/startup/ExtValStartupListener.java (original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/startup/ExtValStartupListener.java Thu Oct 22 19:46:27 2009
@@ -22,6 +22,8 @@
import org.apache.myfaces.extensions.validator.internal.UsageInformation;
import org.apache.myfaces.extensions.validator.core.interceptor.ValidationInterceptor;
import org.apache.myfaces.extensions.validator.core.interceptor.HtmlCoreComponentsValidationExceptionInterceptor;
+import org.apache.myfaces.extensions.validator.core.interceptor.ViolationSeverityValidationExceptionInterceptor;
+import org.apache.myfaces.extensions.validator.core.interceptor.FacesMessagePropertyValidationInterceptor;
import org.apache.myfaces.extensions.validator.core.ExtValContext;
import org.apache.myfaces.extensions.validator.core.CustomInformation;
import org.apache.myfaces.extensions.validator.core.WebXmlParameter;
@@ -55,6 +57,7 @@
.DefaultModuleValidationStrategyToMsgResolverNameMapper;
import org.apache.myfaces.extensions.validator.core.validation.message.resolver.mapper
.SimpleValidationStrategyToMsgResolverNameMapper;
+import org.apache.myfaces.extensions.validator.core.validation.parameter.DefaultViolationSeverityInterpreter;
import org.apache.myfaces.extensions.validator.core.renderkit.ExtValRendererProxy;
import org.apache.myfaces.extensions.validator.util.ClassUtils;
import org.apache.myfaces.extensions.validator.util.ExtValUtils;
@@ -89,7 +92,9 @@
.addGlobalProperty(ExtValRendererProxy.KEY, ExtValRendererProxy.class.getName(), false);
initNameMappers();
- initDefaultValidationExceptionInterceptor();
+ initValidationExceptionInterceptors();
+ initViolationSeverityInterceptors();
+ initPropertyValidationInterceptors();
executeCustomStartupListener();
}
@@ -172,9 +177,21 @@
}
}
- private void initDefaultValidationExceptionInterceptor()
+ private void initValidationExceptionInterceptors()
{
ExtValContext.getContext().addValidationExceptionInterceptor(
new HtmlCoreComponentsValidationExceptionInterceptor());
+ ExtValContext.getContext().addValidationExceptionInterceptor(
+ new ViolationSeverityValidationExceptionInterceptor());
+ }
+
+ private void initViolationSeverityInterceptors()
+ {
+ ExtValContext.getContext().setViolationSeverityInterpreter(new DefaultViolationSeverityInterpreter(), false);
+ }
+
+ private void initPropertyValidationInterceptors()
+ {
+ ExtValContext.getContext().addPropertyValidationInterceptor(new FacesMessagePropertyValidationInterceptor());
}
}
Added: myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/DefaultFacesMessageStorage.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/DefaultFacesMessageStorage.java?rev=828830&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/DefaultFacesMessageStorage.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/DefaultFacesMessageStorage.java Thu Oct 22 19:46:27 2009
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.validator.core.storage;
+
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+import org.apache.myfaces.extensions.validator.internal.ToDo;
+import org.apache.myfaces.extensions.validator.internal.Priority;
+import org.apache.myfaces.extensions.validator.core.validation.message.FacesMessageHolder;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.context.FacesContext;
+import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.ArrayList;
+
+/**
+ * @author Gerhard Petracek
+ * @since x.x.3
+ */
+@UsageInformation(UsageCategory.API)
+public class DefaultFacesMessageStorage implements FacesMessageStorage
+{
+ Map<String, ValidationResult> results = new HashMap<String, ValidationResult>();
+
+ public void addFacesMessage(String clientId, FacesMessage facesMessage)
+ {
+ if(clientId == null)
+ {
+ clientId = "*";
+ }
+
+ if(!this.results.containsKey(clientId))
+ {
+ this.results.put(clientId, new ValidationResult());
+ }
+
+ this.results.get(clientId).addFacesMessageHolder(new FacesMessageHolder(facesMessage, clientId));
+ }
+
+ public List<FacesMessageHolder> getFacesMessages()
+ {
+ List<FacesMessageHolder> result = new ArrayList<FacesMessageHolder>();
+
+ for(ValidationResult validationResult : this.results.values())
+ {
+ result.addAll(validationResult.getFacesMessageHolderList());
+ }
+ return result;
+ }
+
+ public void addAll()
+ {
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ List<FacesMessageHolder> facesMessageHolderList;
+
+ for(ValidationResult validationResult : this.results.values())
+ {
+ facesMessageHolderList = validationResult.getFacesMessageHolderList();
+ sortFacesMessageHolderList(facesMessageHolderList);
+
+ for(FacesMessageHolder facesMessageHolder : facesMessageHolderList)
+ {
+ facesContext.addMessage(facesMessageHolder.getClientId(), facesMessageHolder.getFacesMessage());
+ }
+ }
+ }
+
+ @ToDo(Priority.HIGH)
+ private void sortFacesMessageHolderList(List<FacesMessageHolder> facesMessageHolderList)
+ {
+ //sort severities
+ }
+}
Added: myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/DefaultFacesMessageStorageManager.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/DefaultFacesMessageStorageManager.java?rev=828830&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/DefaultFacesMessageStorageManager.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/DefaultFacesMessageStorageManager.java Thu Oct 22 19:46:27 2009
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.validator.core.storage;
+
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+import static org.apache.myfaces.extensions.validator.internal.UsageCategory.INTERNAL;
+import org.apache.myfaces.extensions.validator.core.storage.mapper.DefaultFacesMessageStorageNameMapper;
+
+/**
+ * default storage-manager for faces messages
+ *
+ * @author Gerhard Petracek
+ * @since x.x.3
+ */
+@UsageInformation(INTERNAL)
+class DefaultFacesMessageStorageManager extends AbstractRequestScopeAwareStorageManager<FacesMessageStorage>
+{
+ DefaultFacesMessageStorageManager()
+ {
+ register(new DefaultFacesMessageStorageNameMapper());
+ }
+
+ public String getStorageManagerKey()
+ {
+ return StorageManager.class.getName() + "_FOR_FACES_MESSAGES:KEY";
+ }
+}
Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/DefaultGroupStorage.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/DefaultGroupStorage.java?rev=828830&r1=828829&r2=828830&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/DefaultGroupStorage.java (original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/DefaultGroupStorage.java Thu Oct 22 19:46:27 2009
@@ -44,17 +44,17 @@
private Map<String, List<Class>> restrictedGroups = new HashMap<String, List<Class>>();
- public void addGroup(Class groupClass, String viewId, String componentId)
+ public void addGroup(Class groupClass, String viewId, String clientId)
{
- addGroupToGroupStorage(groupClass, viewId, componentId, this.addedGroups);
+ addGroupToGroupStorage(groupClass, viewId, clientId, this.addedGroups);
}
- public void restrictGroup(Class groupClass, String viewId, String componentId)
+ public void restrictGroup(Class groupClass, String viewId, String clientId)
{
- addGroupToGroupStorage(groupClass, viewId, componentId, this.restrictedGroups);
+ addGroupToGroupStorage(groupClass, viewId, clientId, this.restrictedGroups);
}
- public Class[] getGroups(String viewId, String componentId)
+ public Class[] getGroups(String viewId, String clientId)
{
if(this.addedGroups.size() < 1)
{
@@ -65,14 +65,14 @@
String key = GroupUtils.getGroupKey(viewId, null);
List<Class> resultListForPage = buildGroupList(key, this.addedGroups);
- key = GroupUtils.getGroupKey(viewId, componentId);
+ key = GroupUtils.getGroupKey(viewId, clientId);
List<Class> resultListForComponent = buildGroupList(key, this.addedGroups);
//remove restricted groups
Class[] resultsForPage =
filterGroupList(GroupUtils.getGroupKey(viewId, null), resultListForPage);
Class[] resultsForComponent =
- filterGroupList(GroupUtils.getGroupKey(viewId, componentId), resultListForComponent);
+ filterGroupList(GroupUtils.getGroupKey(viewId, clientId), resultListForComponent);
if(resultsForPage.length == 0)
{
@@ -95,15 +95,15 @@
return mergeResults(resultsForPage, resultsForComponent);
}
- private void addGroupToGroupStorage(Class groupClass, String viewId, String componentId,
+ private void addGroupToGroupStorage(Class groupClass, String viewId, String clientId,
Map<String, List<Class>> groupStorage)
{
- List<Class> groupList = groupStorage.get(GroupUtils.getGroupKey(viewId, componentId));
+ List<Class> groupList = groupStorage.get(GroupUtils.getGroupKey(viewId, clientId));
if(groupList == null)
{
groupList = new ArrayList<Class>();
- groupStorage.put(GroupUtils.getGroupKey(viewId, componentId), groupList);
+ groupStorage.put(GroupUtils.getGroupKey(viewId, clientId), groupList);
}
if(!groupList.contains(groupClass))
Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/DefaultStorageManagerFactory.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/DefaultStorageManagerFactory.java?rev=828830&r1=828829&r2=828830&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/DefaultStorageManagerFactory.java (original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/DefaultStorageManagerFactory.java Thu Oct 22 19:46:27 2009
@@ -62,6 +62,7 @@
setStorageManager(RendererProxyStorage.class, new DefaultRendererProxyStorageManager(), false);
setStorageManager(GroupStorage.class, new DefaultGroupStorageManager(), false);
setStorageManager(MetaDataStorage.class, new DefaultMetaDataStorageManager(), false);
+ setStorageManager(FacesMessageStorage.class, new DefaultFacesMessageStorageManager(), false);
}
public StorageManager create(Class storageType)
Added: myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/FacesMessageStorage.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/FacesMessageStorage.java?rev=828830&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/FacesMessageStorage.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/FacesMessageStorage.java Thu Oct 22 19:46:27 2009
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.validator.core.storage;
+
+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.FacesMessageHolder;
+
+import javax.faces.application.FacesMessage;
+import java.util.List;
+
+/**
+ * @author Gerhard Petracek
+ * @since x.x.3
+ */
+@UsageInformation(UsageCategory.API)
+public interface FacesMessageStorage
+{
+ void addFacesMessage(String clientId, FacesMessage facesMessage);
+
+ List<FacesMessageHolder> getFacesMessages();
+
+ void addAll();
+}
Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/GroupStorage.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/GroupStorage.java?rev=828830&r1=828829&r2=828830&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/GroupStorage.java (original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/GroupStorage.java Thu Oct 22 19:46:27 2009
@@ -33,9 +33,9 @@
@UsageInformation(UsageCategory.API)
public interface GroupStorage
{
- void addGroup(Class groupClass, String viewId, String componentId);
+ void addGroup(Class groupClass, String viewId, String clientId);
- void restrictGroup(Class groupClass, String viewId, String componentId);
+ void restrictGroup(Class groupClass, String viewId, String clientId);
- Class[] getGroups(String viewId, String componentId);
+ Class[] getGroups(String viewId, String clientId);
}
Added: myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/ValidationResult.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/ValidationResult.java?rev=828830&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/ValidationResult.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/ValidationResult.java Thu Oct 22 19:46:27 2009
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.validator.core.storage;
+
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+import org.apache.myfaces.extensions.validator.internal.ToDo;
+import org.apache.myfaces.extensions.validator.internal.Priority;
+import org.apache.myfaces.extensions.validator.core.validation.message.FacesMessageHolder;
+
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @author Gerhard Petracek
+ * @since x.x.3
+ */
+@ToDo(value = Priority.LOW, description = "refactor it")
+@UsageInformation(UsageCategory.INTERNAL)
+class ValidationResult
+{
+ private List<FacesMessageHolder> facesMessageHolderList = new ArrayList<FacesMessageHolder>();
+
+ public void addFacesMessageHolder(FacesMessageHolder facesMessageHolder)
+ {
+ this.facesMessageHolderList.add(facesMessageHolder);
+ }
+
+ public List<FacesMessageHolder> getFacesMessageHolderList()
+ {
+ return facesMessageHolderList;
+ }
+}
Added: myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/mapper/DefaultFacesMessageStorageNameMapper.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/mapper/DefaultFacesMessageStorageNameMapper.java?rev=828830&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/mapper/DefaultFacesMessageStorageNameMapper.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/storage/mapper/DefaultFacesMessageStorageNameMapper.java Thu Oct 22 19:46:27 2009
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.validator.core.storage.mapper;
+
+import org.apache.myfaces.extensions.validator.core.mapper.NameMapper;
+import org.apache.myfaces.extensions.validator.core.storage.DefaultFacesMessageStorage;
+import org.apache.myfaces.extensions.validator.core.storage.FacesMessageStorage;
+
+/**
+ * use a public class to allow optional deregistration
+ *
+ * @author Gerhard Petracek
+ * @since x.x.3
+ */
+public class DefaultFacesMessageStorageNameMapper implements NameMapper<String>
+{
+ public String createName(String source)
+ {
+ return (FacesMessageStorage.class.getName().equals(source)) ?
+ DefaultFacesMessageStorage.class.getName() : null;
+ }
+}
Added: myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/message/FacesMessageHolder.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/message/FacesMessageHolder.java?rev=828830&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/message/FacesMessageHolder.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/message/FacesMessageHolder.java Thu Oct 22 19:46:27 2009
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.validator.core.validation.message;
+
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+
+import javax.faces.application.FacesMessage;
+
+/**
+ * @author Gerhard Petracek
+ * @since x.x.3
+ */
+@UsageInformation(UsageCategory.INTERNAL)
+public class FacesMessageHolder
+{
+ private FacesMessage facesMessage;
+ private String clientId;
+
+ public FacesMessageHolder(FacesMessage facesMessage)
+ {
+ this.facesMessage = facesMessage;
+ }
+
+ public FacesMessageHolder(FacesMessage facesMessage, String clientId)
+ {
+ this.facesMessage = facesMessage;
+ setClientId(clientId);
+ }
+
+ public FacesMessage getFacesMessage()
+ {
+ return facesMessage;
+ }
+
+ public String getClientId()
+ {
+ return clientId;
+ }
+
+ public void setClientId(String clientId)
+ {
+ if(!"*".equals(clientId))
+ {
+ this.clientId = clientId;
+ }
+ }
+}
Added: myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/parameter/DefaultViolationSeverityInterpreter.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/parameter/DefaultViolationSeverityInterpreter.java?rev=828830&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/parameter/DefaultViolationSeverityInterpreter.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/parameter/DefaultViolationSeverityInterpreter.java Thu Oct 22 19:46:27 2009
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.validator.core.validation.parameter;
+
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+
+import javax.faces.context.FacesContext;
+import javax.faces.component.UIComponent;
+import javax.faces.application.FacesMessage;
+
+/**
+ * mechanism to change the default behavior of extval
+ *
+ * @author Gerhard Petracek
+ * @since x.x.3
+ */
+@UsageInformation(UsageCategory.INTERNAL)
+public class DefaultViolationSeverityInterpreter implements ViolationSeverityInterpreter
+{
+ public boolean severityBlocksNavigation(
+ FacesContext facesContext, UIComponent uiComponent, FacesMessage.Severity severity)
+ {
+ return FacesMessage.SEVERITY_ERROR.equals(severity) || FacesMessage.SEVERITY_FATAL.equals(severity);
+ }
+
+ public boolean severityCausesValidatorException(
+ FacesContext facesContext, UIComponent uiComponent, FacesMessage.Severity severity)
+ {
+ return FacesMessage.SEVERITY_ERROR.equals(severity) || FacesMessage.SEVERITY_FATAL.equals(severity);
+ }
+
+ public boolean severityCausesViolationMessage(
+ FacesContext facesContext, UIComponent uiComponent, FacesMessage.Severity severity)
+ {
+ return true;
+ }
+
+ public boolean severityBlocksSubmit(
+ FacesContext facesContext, UIComponent uiComponent, FacesMessage.Severity severity)
+ {
+ return FacesMessage.SEVERITY_ERROR.equals(severity) || FacesMessage.SEVERITY_FATAL.equals(severity);
+ }
+
+ public boolean severityShowsIndication(
+ FacesContext facesContext, UIComponent uiComponent, FacesMessage.Severity severity)
+ {
+ return FacesMessage.SEVERITY_ERROR.equals(severity) || FacesMessage.SEVERITY_FATAL.equals(severity);
+ }
+}
Added: myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/parameter/ViolationSeverityInterpreter.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/parameter/ViolationSeverityInterpreter.java?rev=828830&view=auto
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/parameter/ViolationSeverityInterpreter.java (added)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/parameter/ViolationSeverityInterpreter.java Thu Oct 22 19:46:27 2009
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.validator.core.validation.parameter;
+
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+
+import javax.faces.context.FacesContext;
+import javax.faces.component.UIComponent;
+import javax.faces.application.FacesMessage;
+
+/**
+ * mechanism to change the default behavior of extval
+ *
+ * @author Gerhard Petracek
+ * @since x.x.3
+ */
+@UsageInformation(UsageCategory.API)
+public interface ViolationSeverityInterpreter
+{
+ /**
+ * @param facesContext current faces context
+ * @param uiComponent current component
+ * @param severity jsf severity for faces messages
+ * @return true if the given severity should block the navigation
+ * if #severityCausesValidatorException returns falls validation will be continued for the current property
+ * all messages which don't lead to an exception should be stored in an storage and
+ * added after the first message which gets thrown as exception
+ * a global PropertyValidationInterceptor add the messages of the storage as faces message
+ */
+ boolean severityBlocksNavigation(
+ FacesContext facesContext, UIComponent uiComponent, FacesMessage.Severity severity);
+
+ /**
+ * @param facesContext current faces context
+ * @param uiComponent current component
+ * @param severity jsf severity for faces messages
+ * @return true if the given severity should cause a validator exception
+ */
+ boolean severityCausesValidatorException(
+ FacesContext facesContext, UIComponent uiComponent, FacesMessage.Severity severity);
+
+ /**
+ *
+ * @param facesContext current faces context
+ * @param uiComponent current component
+ * @param severity jsf severity for faces messages
+ * @return true if a violation message leads to a faces message
+ */
+ boolean severityCausesViolationMessage(
+ FacesContext facesContext, UIComponent uiComponent, FacesMessage.Severity severity);
+
+ /**
+ * @param facesContext current faces context
+ * @param uiComponent current component
+ * @param severity jsf severity for faces messages
+ * @return true if the constraint with the given severity should be validated on the client side (if supported)
+ */
+ boolean severityBlocksSubmit(
+ FacesContext facesContext, UIComponent uiComponent, FacesMessage.Severity severity);
+
+ /**
+ * @param facesContext current faces context
+ * @param uiComponent current component
+ * @param severity jsf severity for faces messages
+ * @return true if the constraint with the given severity
+ * should cause e.g. a required marker independent of client-side validation (if supported)
+ */
+ boolean severityShowsIndication(
+ FacesContext facesContext, UIComponent uiComponent, FacesMessage.Severity severity);
+}
Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/strategy/AbstractValidationStrategy.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/strategy/AbstractValidationStrategy.java?rev=828830&r1=828829&r2=828830&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/strategy/AbstractValidationStrategy.java (original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/core/validation/strategy/AbstractValidationStrategy.java Thu Oct 22 19:46:27 2009
@@ -110,7 +110,8 @@
": throw original exception after processAfterValidatorException");
}
- throw validatorException;
+ ExtValUtils.tryToThrowValidatorExceptionForComponent(
+ uiComponent, validatorException.getFacesMessage(), validatorException);
}
if(logger.isTraceEnabled())
Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/util/ExtValUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/util/ExtValUtils.java?rev=828830&r1=828829&r2=828830&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/util/ExtValUtils.java (original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/util/ExtValUtils.java Thu Oct 22 19:46:27 2009
@@ -26,10 +26,12 @@
import org.apache.myfaces.extensions.validator.core.validation.message.resolver.MessageResolver;
import org.apache.myfaces.extensions.validator.core.validation.parameter.ValidationParameterExtractor;
import org.apache.myfaces.extensions.validator.core.validation.parameter.ValidationParameterExtractorFactory;
+import org.apache.myfaces.extensions.validator.core.validation.parameter.ViolationSeverityInterpreter;
import org.apache.myfaces.extensions.validator.core.factory.ClassMappingFactory;
import org.apache.myfaces.extensions.validator.core.ExtValContext;
import org.apache.myfaces.extensions.validator.core.WebXmlParameter;
import org.apache.myfaces.extensions.validator.core.storage.StorageManager;
+import org.apache.myfaces.extensions.validator.core.storage.FacesMessageStorage;
import org.apache.myfaces.extensions.validator.core.mapper.NameMapper;
import org.apache.myfaces.extensions.validator.core.interceptor.ValidationExceptionInterceptor;
import org.apache.myfaces.extensions.validator.core.interceptor.MetaDataExtractionInterceptor;
@@ -178,6 +180,11 @@
{
boolean result = true;
+ if(metaDataEntry == null)
+ {
+ metaDataEntry = new MetaDataEntry();
+ }
+
for(ValidationExceptionInterceptor validationExceptionInterceptor : ExtValContext.getContext()
.getValidationExceptionInterceptors())
{
@@ -646,4 +653,161 @@
{
return propertyInformation.getInformation(PropertyInformationKeys.PROPERTY_DETAILS, PropertyDetails.class);
}
+
+ public static void tryToThrowValidatorExceptionForComponentId(
+ String clientId, FacesMessage facesMessage, Throwable throwable)
+ {
+ UIComponent targetComponent = findComponent(clientId);
+
+ tryToThrowValidatorExceptionForComponent(targetComponent, facesMessage, throwable);
+ }
+
+ public static void tryToThrowValidatorExceptionForComponent(
+ UIComponent uiComponent, FacesMessage facesMessage, Throwable throwable)
+ {
+ ViolationSeverityInterpreter interpreter =
+ ExtValContext.getContext().getViolationSeverityInterpreter();
+
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+
+ if(interpreter.severityCausesValidatorException(facesContext, uiComponent, facesMessage.getSeverity()))
+ {
+ if(throwable == null)
+ {
+ throw new ValidatorException(facesMessage);
+ }
+ else
+ {
+ throw new ValidatorException(facesMessage, throwable);
+ }
+ }
+ else
+ {
+ tryToAddViolationMessageForComponent(uiComponent, facesMessage);
+ }
+ }
+
+ public static void tryToAddViolationMessageForComponentId(String clientId, FacesMessage facesMessage)
+ {
+ UIComponent targetComponent = findComponent(clientId);
+
+ if(targetComponent == null && clientId != null)
+ {
+ tryToAddViolationMessageForTestClientId(clientId, facesMessage);
+ return;
+ }
+ tryToAddViolationMessageForComponent(targetComponent, facesMessage);
+ }
+
+ @ToDo(value = Priority.MEDIUM, description = "required for test frameworks - goal: remove it")
+ private static void tryToAddViolationMessageForTestClientId(String clientId, FacesMessage facesMessage)
+ {
+ ViolationSeverityInterpreter interpreter =
+ ExtValContext.getContext().getViolationSeverityInterpreter();
+
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+
+ if(interpreter.severityCausesViolationMessage(facesContext, null, facesMessage.getSeverity()))
+ {
+ addFacesMessage(clientId, facesMessage);
+ }
+ tryToBlocksNavigationForComponent(null, facesMessage);
+ }
+
+ public static void tryToAddViolationMessageForComponent(UIComponent uiComponent, FacesMessage facesMessage)
+ {
+ ViolationSeverityInterpreter interpreter =
+ ExtValContext.getContext().getViolationSeverityInterpreter();
+
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+
+ if(interpreter.severityCausesViolationMessage(facesContext, uiComponent, facesMessage.getSeverity()))
+ {
+ if(uiComponent != null)
+ {
+ addFacesMessage(uiComponent.getClientId(facesContext), facesMessage);
+ }
+ else
+ {
+ if(LOGGER.isWarnEnabled())
+ {
+ LOGGER.warn("no component was found that might happen with test-frameworks" +
+ " and shouldn't happen in real applications");
+ }
+ }
+ }
+ tryToBlocksNavigationForComponent(uiComponent, facesMessage);
+ }
+
+ public static void addFacesMessage(FacesMessage facesMessage)
+ {
+ addFacesMessage(null, facesMessage);
+ }
+
+ public static void addFacesMessage(String clientId, FacesMessage facesMessage)
+ {
+ FacesMessageStorage storage = getStorage(FacesMessageStorage.class, FacesMessageStorage.class.getName());
+
+ if(storage != null)
+ {
+ storage.addFacesMessage(clientId, facesMessage);
+ }
+ else
+ {
+ FacesContext.getCurrentInstance().addMessage(clientId, facesMessage);
+ }
+ }
+
+ public static void tryToBlocksNavigationForComponentId(String clientId, FacesMessage facesMessage)
+ {
+ UIComponent targetComponent = findComponent(clientId);
+
+ tryToBlocksNavigationForComponent(targetComponent, facesMessage);
+ }
+
+ public static void tryToBlocksNavigationForComponent(UIComponent uiComponent, FacesMessage facesMessage)
+ {
+ ViolationSeverityInterpreter interpreter =
+ ExtValContext.getContext().getViolationSeverityInterpreter();
+
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+
+ if(interpreter.severityBlocksNavigation(facesContext, uiComponent, facesMessage.getSeverity()))
+ {
+ FacesContext.getCurrentInstance().renderResponse();
+ }
+ }
+
+ public static boolean severityBlocksSubmitForComponentId(String clientId, FacesMessage facesMessage)
+ {
+ ViolationSeverityInterpreter interpreter =
+ ExtValContext.getContext().getViolationSeverityInterpreter();
+
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ UIComponent targetComponent = findComponent(clientId);
+
+ return interpreter.severityBlocksSubmit(facesContext, targetComponent, facesMessage.getSeverity());
+ }
+
+ public static boolean severityShowsIndicationForComponentId(String clientId, FacesMessage facesMessage)
+ {
+ ViolationSeverityInterpreter interpreter =
+ ExtValContext.getContext().getViolationSeverityInterpreter();
+
+ FacesContext facesContext = FacesContext.getCurrentInstance();
+ UIComponent targetComponent = findComponent(clientId);
+
+ return interpreter.severityShowsIndication(facesContext, targetComponent, facesMessage.getSeverity());
+ }
+
+ private static UIComponent findComponent(String clientId)
+ {
+ UIComponent targetComponent = null;
+
+ if(clientId != null)
+ {
+ targetComponent = FacesContext.getCurrentInstance().getViewRoot().findComponent(clientId);
+ }
+ return targetComponent;
+ }
}
Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/util/GroupUtils.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/util/GroupUtils.java?rev=828830&r1=828829&r2=828830&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/util/GroupUtils.java (original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/core/src/main/java/org/apache/myfaces/extensions/validator/util/GroupUtils.java Thu Oct 22 19:46:27 2009
@@ -28,8 +28,8 @@
@UsageInformation(UsageCategory.INTERNAL)
public class GroupUtils
{
- public static String getGroupKey(String viewId, String componentId)
+ public static String getGroupKey(String viewId, String clientId)
{
- return componentId == null ? viewId : viewId + "@" + componentId;
+ return clientId == null ? viewId : viewId + "@" + clientId;
}
-}
+}
\ No newline at end of file
Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/examples/feature-set_01/src/main/java/org/apache/myfaces/extensions/validator/demo/gui/beans/RegistrationPage.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/examples/feature-set_01/src/main/java/org/apache/myfaces/extensions/validator/demo/gui/beans/RegistrationPage.java?rev=828830&r1=828829&r2=828830&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/examples/feature-set_01/src/main/java/org/apache/myfaces/extensions/validator/demo/gui/beans/RegistrationPage.java (original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/examples/feature-set_01/src/main/java/org/apache/myfaces/extensions/validator/demo/gui/beans/RegistrationPage.java Thu Oct 22 19:46:27 2009
@@ -27,6 +27,8 @@
import org.apache.myfaces.extensions.validator.baseval.annotation.Required;
import org.apache.myfaces.extensions.validator.baseval.annotation.Validator;
import org.apache.myfaces.extensions.validator.baseval.annotation.SkipValidation;
+import org.apache.myfaces.extensions.validator.core.validation.parameter.DisableClientSideValidation;
+import org.apache.myfaces.extensions.validator.core.validation.parameter.ViolationSeverity;
import org.apache.myfaces.custom.emailvalidator.EmailValidator;
public class RegistrationPage
@@ -45,7 +47,8 @@
@JoinValidation(value = "#{registrationPage.person.password}")
private String password;
- @Required(validationErrorMsgKey = "repeated_password_required")
+ @Required(validationErrorMsgKey = "repeated_password_required",
+ parameters = {DisableClientSideValidation.class, ViolationSeverity.Warn.class})
private String passwordRepeated;
//use #{registrationPage.person.nickName}, #{person.nickName}
Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/examples/feature-set_02/src/main/java/org/apache/myfaces/extensions/validator/demo/gui/beans/RegistrationPage.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/branches/branch_for_jsf_1_1/examples/feature-set_02/src/main/java/org/apache/myfaces/extensions/validator/demo/gui/beans/RegistrationPage.java?rev=828830&r1=828829&r2=828830&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/examples/feature-set_02/src/main/java/org/apache/myfaces/extensions/validator/demo/gui/beans/RegistrationPage.java (original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/examples/feature-set_02/src/main/java/org/apache/myfaces/extensions/validator/demo/gui/beans/RegistrationPage.java Thu Oct 22 19:46:27 2009
@@ -20,6 +20,7 @@
import org.apache.myfaces.extensions.validator.demo.domain.Person;
import org.apache.myfaces.extensions.validator.beanval.payload.DisableClientSideValidation;
+import org.apache.myfaces.extensions.validator.beanval.payload.ViolationSeverity;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
@@ -29,7 +30,7 @@
@NotNull(payload = DisableClientSideValidation.class)
private String password;
- @NotNull(payload = DisableClientSideValidation.class)
+ @NotNull(payload = ViolationSeverity.Warn.class)
private String passwordRepeated;
private Person person;
Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/BeanValidationInterceptor.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/BeanValidationInterceptor.java?rev=828830&r1=828829&r2=828830&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/BeanValidationInterceptor.java (original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/BeanValidationInterceptor.java Thu Oct 22 19:46:27 2009
@@ -130,8 +130,8 @@
Object convertedObject,
PropertyInformation propertyInformation)
{
- this.bviUtils.validate(facesContext, uiComponent, convertedObject,
- propertyInformation, supportMultipleViolationsPerField());
+ /*not used yet supportMultipleViolationsPerField()*/
+ this.bviUtils.validate(facesContext, uiComponent, convertedObject, propertyInformation);
}
protected boolean supportMultipleViolationsPerField()
Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/BeanValidationInterceptorInternals.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/BeanValidationInterceptorInternals.java?rev=828830&r1=828829&r2=828830&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/BeanValidationInterceptorInternals.java (original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/BeanValidationInterceptorInternals.java Thu Oct 22 19:46:27 2009
@@ -20,6 +20,7 @@
import org.apache.commons.logging.Log;
import org.apache.myfaces.extensions.validator.beanval.validation.strategy.BeanValidationVirtualValidationStrategy;
+import org.apache.myfaces.extensions.validator.beanval.util.BeanValidationUtils;
import org.apache.myfaces.extensions.validator.core.metadata.MetaDataEntry;
import org.apache.myfaces.extensions.validator.core.metadata.transformer.MetaDataTransformer;
import org.apache.myfaces.extensions.validator.core.property.PropertyDetails;
@@ -30,20 +31,14 @@
import org.apache.myfaces.extensions.validator.internal.ToDo;
import org.apache.myfaces.extensions.validator.internal.Priority;
import org.apache.myfaces.extensions.validator.util.ExtValUtils;
-import org.apache.myfaces.extensions.validator.util.JsfUtils;
-import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
-import javax.faces.validator.ValidatorException;
import javax.validation.ConstraintViolation;
import javax.validation.groups.Default;
import javax.validation.metadata.BeanDescriptor;
import javax.validation.metadata.ConstraintDescriptor;
import javax.validation.metadata.ElementDescriptor;
-import java.util.MissingResourceException;
-import java.util.ArrayList;
-import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.util.Set;
@@ -56,9 +51,6 @@
class BeanValidationInterceptorInternals
{
private Log logger;
- private final String defaultLabelMessageTemplate = "{1}: {0}";
- private String labelMessageTemplate = defaultLabelMessageTemplate;
- private final String JAVAX_FACES_VALIDATOR_BEANVALIDATOR_MESSAGE = "javax.faces.validator.BeanValidator.MESSAGE";
BeanValidationInterceptorInternals(Log logger)
{
@@ -184,7 +176,7 @@
void validate(FacesContext facesContext,
UIComponent uiComponent,
Object convertedObject,
- PropertyInformation propertyInformation, boolean supportMultipleViolationsPerField)
+ PropertyInformation propertyInformation)
{
Class baseBeanClass = getBaseClassType(propertyInformation);
String propertyName = getPropertyToValidate(propertyInformation);
@@ -202,108 +194,13 @@
.getValidator()
.validateValue(baseBeanClass, propertyName, convertedObject, groups);
- processConstraintViolations(
- facesContext, uiComponent, convertedObject, violations, supportMultipleViolationsPerField);
- }
-
- private void processConstraintViolations(FacesContext facesContext,
- UIComponent uiComponent,
- Object convertedObject,
- Set<ConstraintViolation> violations,
- boolean supportMultipleViolationsPerField)
- {
- List<String> violationMessages = new ArrayList<String>();
- for (ConstraintViolation violation : violations)
- {
- processConstraintViolation(uiComponent, convertedObject, violation, violationMessages);
-
- if (!supportMultipleViolationsPerField)
- {
- break;
- }
- }
-
- if (!violationMessages.isEmpty())
+ if(violations != null && !violations.isEmpty())
{
- throwException(facesContext, uiComponent, violationMessages, supportMultipleViolationsPerField);
+ BeanValidationUtils
+ .processConstraintViolations(facesContext, uiComponent, convertedObject, violations, true);
}
}
- private void processConstraintViolation(UIComponent uiComponent,
- Object convertedObject,
- ConstraintViolation violation,
- List<String> violationMessages)
- {
- String violationMessage = violation.getMessage();
-
- String labeledMessage = createLabeledMessage(violationMessage);
-
- ValidatorException validatorException = createValidatorException(labeledMessage);
-
- executeAfterThrowingInterceptors(uiComponent, convertedObject, validatorException);
-
- if (isMessageTextUnchanged(validatorException, labeledMessage))
- {
- violationMessages.add(violationMessage);
- }
- else
- {
- violationMessages.add(validatorException.getFacesMessage().getSummary());
- }
- }
-
- private String createLabeledMessage(String violationMessage)
- {
- if(labelMessageTemplate == null)
- {
- return this.defaultLabelMessageTemplate.replace("{0}", violationMessage);
- }
-
- this.labelMessageTemplate = loadStandardMessageTemplate();
-
- if(labelMessageTemplate == null)
- {
- return createLabeledMessage(violationMessage);
- }
- return labelMessageTemplate.replace("{0}", violationMessage);
- }
-
- private String loadStandardMessageTemplate()
- {
- try
- {
- return JsfUtils.getDefaultFacesMessageBundle().getString(JAVAX_FACES_VALIDATOR_BEANVALIDATOR_MESSAGE);
- }
- catch (MissingResourceException e)
- {
- return null;
- }
- }
-
- private void executeAfterThrowingInterceptors(UIComponent uiComponent,
- Object convertedObject,
- ValidatorException validatorException)
- {
- ExtValUtils.executeAfterThrowingInterceptors(
- uiComponent,
- null,
- convertedObject,
- validatorException,
- null);
- }
-
- private boolean isMessageTextUnchanged(ValidatorException validatorException, String violationMessage)
- {
- return violationMessage.equals(validatorException.getFacesMessage().getSummary()) ||
- violationMessage.equals(validatorException.getFacesMessage().getDetail());
- }
-
- private ValidatorException createValidatorException(String violationMessage)
- {
- return new ValidatorException(
- ExtValUtils.createFacesMessage(FacesMessage.SEVERITY_ERROR, violationMessage, violationMessage));
- }
-
private Class getBaseClassType(PropertyInformation propertyInformation)
{
return ExtValUtils.getPropertyDetails(propertyInformation).getBaseObject().getClass();
@@ -314,31 +211,6 @@
return ExtValUtils.getPropertyDetails(propertyInformation).getProperty();
}
- //override this method in the jsf 2.0 version
- private void throwException(FacesContext facesContext, UIComponent uiComponent,
- List<String> violationMessages, boolean supportMultipleViolationsPerField)
- {
- if (supportMultipleViolationsPerField)
- {
- boolean firstMessage = false;
- for (String message : violationMessages)
- {
- if (!firstMessage)
- {
- firstMessage = true;
- }
- else
- {
- facesContext.addMessage(uiComponent.getClientId(facesContext),
- ExtValUtils.createFacesMessage(FacesMessage.SEVERITY_ERROR, message, message));
- }
- }
- }
-
- throw new ValidatorException(ExtValUtils.createFacesMessage(
- FacesMessage.SEVERITY_ERROR, violationMessages.get(0), violationMessages.get(0)));
- }
-
private Class[] resolveGroups(FacesContext facesContext, UIComponent uiComponent)
{
return ExtValBeanValidationContext.getCurrentInstance().getGroups(
Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/ExtValBeanValidationContext.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/ExtValBeanValidationContext.java?rev=828830&r1=828829&r2=828830&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/ExtValBeanValidationContext.java (original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/ExtValBeanValidationContext.java Thu Oct 22 19:46:27 2009
@@ -112,19 +112,19 @@
return this.defaultMessageInterpolator;
}
- public void addGroup(Class groupClass, String viewId, String componentId)
+ public void addGroup(Class groupClass, String viewId, String clientId)
{
- this.groupStorage.addGroup(groupClass, viewId, componentId);
+ this.groupStorage.addGroup(groupClass, viewId, clientId);
}
- public void restrictGroup(Class groupClass, String viewId, String componentId)
+ public void restrictGroup(Class groupClass, String viewId, String clientId)
{
- this.groupStorage.restrictGroup(groupClass, viewId, componentId);
+ this.groupStorage.restrictGroup(groupClass, viewId, clientId);
}
- public Class[] getGroups(String viewId, String componentId)
+ public Class[] getGroups(String viewId, String clientId)
{
- return this.groupStorage.getGroups(viewId, componentId);
+ return this.groupStorage.getGroups(viewId, clientId);
}
public void addModelValidationEntry(ModelValidationEntry modelValidationEntry, String viewId, UIComponent component)
Modified: myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/metadata/transformer/AbstractBeanValidationMetaDataTransformer.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/metadata/transformer/AbstractBeanValidationMetaDataTransformer.java?rev=828830&r1=828829&r2=828830&view=diff
==============================================================================
--- myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/metadata/transformer/AbstractBeanValidationMetaDataTransformer.java (original)
+++ myfaces/extensions/validator/branches/branch_for_jsf_1_1/validation-modules/bean-validation/src/main/java/org/apache/myfaces/extensions/validator/beanval/metadata/transformer/AbstractBeanValidationMetaDataTransformer.java Thu Oct 22 19:46:27 2009
@@ -23,9 +23,12 @@
import org.apache.myfaces.extensions.validator.core.metadata.transformer.MetaDataTransformer;
import org.apache.myfaces.extensions.validator.core.metadata.MetaDataEntry;
import org.apache.myfaces.extensions.validator.beanval.payload.DisableClientSideValidation;
+import org.apache.myfaces.extensions.validator.beanval.payload.ViolationSeverity;
+import org.apache.myfaces.extensions.validator.util.ExtValUtils;
import javax.validation.metadata.ConstraintDescriptor;
import javax.validation.Payload;
+import javax.faces.application.FacesMessage;
import java.util.Map;
import java.util.HashMap;
import java.lang.annotation.Annotation;
@@ -41,14 +44,14 @@
{
ConstraintDescriptor<? extends T> constraintDescriptor = metaDataEntry.getValue(ConstraintDescriptor.class);
- if(isClientSideValidationEnabled(constraintDescriptor))
+ if(isClientSideValidationEnabled(constraintDescriptor) && isBlockingConstraint(constraintDescriptor))
{
return convertConstraintDescriptor((ConstraintDescriptor<T>)constraintDescriptor);
}
return new HashMap<String, Object>();
}
- private boolean isClientSideValidationEnabled(ConstraintDescriptor<? extends T> constraintDescriptor)
+ protected boolean isClientSideValidationEnabled(ConstraintDescriptor<? extends T> constraintDescriptor)
{
for(Class<? extends Payload> payload : constraintDescriptor.getPayload())
{
@@ -60,5 +63,27 @@
return true;
}
+ protected boolean isBlockingConstraint(ConstraintDescriptor<?> constraintDescriptor)
+ {
+ FacesMessage testMessage = new FacesMessage();
+ testMessage.setSeverity(ViolationSeverity.Error.VALUE);
+
+ for (Class<? extends Payload> payload : constraintDescriptor.getPayload())
+ {
+ if (ViolationSeverity.Warn.class.isAssignableFrom(payload))
+ {
+ testMessage.setSeverity(ViolationSeverity.Warn.VALUE);
+ }
+ else if(ViolationSeverity.Info.class.isAssignableFrom(payload))
+ {
+ testMessage.setSeverity(ViolationSeverity.Info.VALUE);
+ }
+ else if(ViolationSeverity.Fatal.class.isAssignableFrom(payload))
+ {
+ testMessage.setSeverity(ViolationSeverity.Fatal.VALUE);
+ }
+ }
+ return ExtValUtils.severityBlocksSubmitForComponentId(null, testMessage);
+ }
protected abstract Map<String, Object> convertConstraintDescriptor(ConstraintDescriptor<T> constraintDescriptor);
}