[hibernate-dev] [Bean Validation] Adding interpolation facilities

Emmanuel Bernard emmanuel at hibernate.org
Mon Mar 9 16:44:16 EDT 2009


Yes that's a valid argument.
BTW I plan to introduce some kind of context object (another one) in  
interpolate to allow future extension wo breaking everybody's code.

On  Mar 9, 2009, at 06:36, Hardy Ferentschik wrote:

> Wouldn't this also mean that you have to change the MessageResolver  
> interface from
>
> MessageInterpolator.interpolate(String message,  
> ConstraintDescriptor<?> constraintDescriptor, Object value)
>
> to
>
> MessageInterpolator.interpolate(String message,  
> ConstraintDescriptor<?> constraintDescriptor, Object value,  
> Map<String, String> interpolatedParameters)
>
> I can see the potential use case, but I am not sure whether it is  
> worth the added complexity in the API.
>
> --Hardy
>
>
>
> On Sun, 08 Mar 2009 00:52:49 +0100, Emmanuel Bernard <emmanuel at hibernate.org 
> > wrote:
>
>> What do you think of
>> public class ConstraintValidatorContext {
>>     addInterpolatedParameter(String name, String value);
>> }
>>
>> public class SyntaxValidator implements ConstraintValidator<Syntax,
>> String> {
>>     public boolean isValid(String value, ConstraintValidatorContext
>> context) {
>>         detectedSyntax = ...;
>>         context.addInterpolatedParameter("detectedSyntax",
>> detextedSyntax);
>>         return allowedSyntaxes.contains(detectedSyntax);
>>     }
>> }
>>
>> @Syntax(value={JAVA, HTML}, message="{constraint.syntax}")
>> String text;
>>
>> ValidatorMessage_en.properties
>> constraint.syntax=Unable to support {detectedSyntax}
>>
>>
>> =>
>> "Unable to support PHP"
>
>




More information about the hibernate-dev mailing list