myfaces-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rudy De Busscher (JIRA)" <...@myfaces.apache.org>
Subject [jira] Commented: (EXTVAL-82) Add the EmptyValueAwareValidationStrategy annotation to the Length and Pattern Annotations
Date Sat, 30 Jan 2010 21:15:34 GMT

    [ https://issues.apache.org/jira/browse/EXTVAL-82?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12806744#action_12806744
] 

Rudy De Busscher commented on EXTVAL-82:
----------------------------------------

The changed behaviour of @Length and @Pattern is indeed something that needs to be documented.
 In the case a project upgrades to version x.x.3, the required check they used to have implicitly,
is gone.

The following is, I think, the easiest solution without major changes (no additional constraint
or custom validation strategy required) in the codebase of the project that did an upgrade.

public class CompatiblePropertyValidationInterceptor extends PropertyValidationInterceptor
{

	@Override
	protected boolean isValidationStrategyCompatibleWithValue(
			ValidationStrategy validationStrategy, Object value) {
		if (validationStrategy instanceof LengthStrategy) {
			return value != null;
		}
		if (validationStrategy instanceof PatternStrategy) {
			return value != null;
		}
		return super.isValidationStrategyCompatibleWithValue(validationStrategy, value);
	}

	
}


and this class is registered in a custom startup listener as follows

        ExtValContext.getContext().denyRendererInterceptor(ValidationInterceptor.class);
        ExtValContext.getContext().registerRendererInterceptor(new CompatiblePropertyValidationInterceptor());

The functionality placed in the isValidationStrategyCompatibleWithValue method is the same
as putting an EmptyValueAwareValidationStrategy on the 2 strategies.

regards
Rudy

> Add the EmptyValueAwareValidationStrategy annotation to the Length and Pattern Annotations
> ------------------------------------------------------------------------------------------
>
>                 Key: EXTVAL-82
>                 URL: https://issues.apache.org/jira/browse/EXTVAL-82
>             Project: MyFaces Extensions Validator
>          Issue Type: Improvement
>          Components: Property Validation
>    Affects Versions: 1.2.3-SNAPSHOT, 2.0.3-SNAPSHOT, 1.1.3-SNAPSHOT
>            Reporter: Rudy De Busscher
>            Priority: Minor
>
> Adding the EmptyValueAwareValidationStrategy allows in JSF 2.0 that Length and Pattern
validations are triggered (with the javax.faces.VALIDATE_EMPTY_FIELDS parameter set).
> They will cause a validation error with an empty string (Length annotation with minimum
set or Pattern) so the Required annotation is no longer needed.
> Tested it out with ExtVal 2.0.3-SNAPSHOT and Myfaces 2.0.0-SNAPHOT (of 21/01) and it
works as expected.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message