Package javax.validation

Examples of javax.validation.MessageInterpolator


  {
    if (validator == null)
    {
      Configuration<?> config = Validation.byDefaultProvider().configure();

      MessageInterpolator interpolator = config.getDefaultMessageInterpolator();
      interpolator = new SessionLocaleInterpolator(interpolator);

      ValidatorFactory factory = config.messageInterpolator(interpolator)
        .buildValidatorFactory();
View Full Code Here


            }
            context.getExternalContext().getApplicationMap().put(VALIDATOR_FACTORY_KEY, validatorFactory);
        }

        ValidatorContext validatorContext = validatorFactory.usingContext();
        MessageInterpolator jsfMessageInterpolator =
                new JsfAwareMessageInterpolator(context,
                           validatorFactory.getMessageInterpolator());
        validatorContext.messageInterpolator(jsfMessageInterpolator);
        javax.validation.Validator beanValidator = validatorContext.getValidator();
        Class[] validationGroupsArray = parseValidationGroups(getValidationGroups());
View Full Code Here

    static MessageInterpolator get(final ValidatorFactory validatorFactory)
    {
        _FacesMessageInterpolatorHolder.FacesMessageInterpolator ret = instance;
        if (ret == null)
        {
            final MessageInterpolator interpolator = validatorFactory.getMessageInterpolator();
            instance = ret = new FacesMessageInterpolator(interpolator);
        }
        return ret;
    }
View Full Code Here

    static MessageInterpolator get(final ValidatorFactory validatorFactory)
    {
        _FacesMessageInterpolatorHolder.FacesMessageInterpolator ret = instance;
        if (ret == null)
        {
            final MessageInterpolator interpolator = validatorFactory.getMessageInterpolator();
            instance = ret = new FacesMessageInterpolator(interpolator);
        }
        return ret;
    }
View Full Code Here

    static MessageInterpolator get(final ValidatorFactory validatorFactory)
    {
        _FacesMessageInterpolatorHolder.FacesMessageInterpolator ret = instance;
        if (ret == null)
        {
            final MessageInterpolator interpolator = validatorFactory.getMessageInterpolator();
            instance = ret = new FacesMessageInterpolator(interpolator);
        }
        return ret;
    }
View Full Code Here

    @SuppressWarnings({"rawtypes", "unchecked"})
    Configuration<?> configuration = (this.providerClass != null ?
        Validation.byProvider(this.providerClass).configure() :
        Validation.byDefaultProvider().configure());

    MessageInterpolator targetInterpolator = this.messageInterpolator;
    if (targetInterpolator == null) {
      targetInterpolator = configuration.getDefaultMessageInterpolator();
    }
    configuration.messageInterpolator(new LocaleContextMessageInterpolator(targetInterpolator));
View Full Code Here

      @SpecAssertion(section = "4.3.1", id = "e"),
      @SpecAssertion(section = "4.3.1.1", id = "a")
  })
  public void testSuccessfullInterpolationOfValidationMessagesValue() {

    MessageInterpolator interpolator = getDefaultMessageInterpolator();
    ConstraintDescriptor<?> descriptor = getDescriptorFor( DummyEntity.class, "foo" );
    MessageInterpolator.Context context = new TestContext( descriptor );

    String expected = "replacement worked";
    String actual = interpolator.interpolate( "{foo}", context );
    assertEquals( actual, expected, "Wrong substitution" );

    expected = "replacement worked replacement worked";
    actual = interpolator.interpolate( "{foo} {foo}", context );
    assertEquals( actual, expected, "Wrong substitution" );

    expected = "This replacement worked just fine";
    actual = interpolator.interpolate( "This {foo} just fine", context );
    assertEquals( actual, expected, "Wrong substitution" );

    expected = "{} replacement worked {unkown}";
    actual = interpolator.interpolate( "{} {foo} {unkown}", context );
    assertEquals( actual, expected, "Wrong substitution" );
  }
View Full Code Here

  }

  @Test
  @SpecAssertion(section = "4.3.1.1", id = "b")
  public void testRecursiveMessageInterpoliation() {
    MessageInterpolator interpolator = getDefaultMessageInterpolator();
    ConstraintDescriptor<?> descriptor = getDescriptorFor( DummyEntity.class, "fubar" );
    MessageInterpolator.Context context = new TestContext( descriptor );

    String expected = "recursion worked";
    String actual = interpolator.interpolate( ( String ) descriptor.getAttributes().get( "message" ), context );
    assertEquals(
        expected, actual, "Expansion should be recursive"
    );
  }
View Full Code Here

      @SpecAssertion(section = "4.3.1", id = "g"),
      @SpecAssertion(section = "4.3.1", id = "h")
  })
  public void testLiteralCurlyBraces() {

    MessageInterpolator interpolator = getDefaultMessageInterpolator();
    ConstraintDescriptor<?> descriptor = getDescriptorFor( DummyEntity.class, "foo" );
    MessageInterpolator.Context context = new TestContext( descriptor );

    String expected = "{";
    String actual = interpolator.interpolate( "\\{", context );
    assertEquals( actual, expected, "Wrong substitution" );

    expected = "}";
    actual = interpolator.interpolate( "\\}", context );
    assertEquals( actual, expected, "Wrong substitution" );

    expected = "\\";
    actual = interpolator.interpolate( "\\", context );
    assertEquals( actual, expected, "Wrong substitution" );
  }
View Full Code Here

  }

  @Test
  @SpecAssertion(section = "4.3.1.1", id = "a")
  public void testUnSuccessfulInterpolation() {
    MessageInterpolator interpolator = getDefaultMessageInterpolator();
    ConstraintDescriptor<?> descriptor = getDescriptorFor( DummyEntity.class, "foo" );
    MessageInterpolator.Context context = new TestContext( descriptor );

    String expected = "foo"// missing {}
    String actual = interpolator.interpolate( "foo", context );
    assertEquals( actual, expected, "Wrong substitution" );

    expected = "#{foo  {}";
    actual = interpolator.interpolate( "#{foo  {}", context );
    assertEquals( actual, expected, "Wrong substitution" );
  }
View Full Code Here

TOP

Related Classes of javax.validation.MessageInterpolator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.