Package org.springframework.context.support

Examples of org.springframework.context.support.StaticMessageSource.addMessage()


      }
    };
    formModel.add("someProperty", new ValueHolder("value"));

    StaticMessageSource messageSource = new StaticMessageSource();
    messageSource.addMessage("typeMismatch", Locale.getDefault(), "{0} has an invalid format \"{1}\"");
    MessageSourceAccessor messageSourceAccessor = new MessageSourceAccessor(messageSource);
    provider.setMessageSourceAccessor(messageSourceAccessor);

    ValidationMessage message = provider.getErrorMessage(formModel, "someProperty", "new value",
        new IllegalArgumentException());
View Full Code Here


    Icon testIcon = new TestIcon(Color.RED);

    MessageSourceFieldFaceSource fieldFaceSource = new MessageSourceFieldFaceSource();

    StaticMessageSource messageSource = new StaticMessageSource();
    messageSource.addMessage("context.field.caption", Locale.getDefault(), "the caption");
    messageSource.addMessage("context.field.description", Locale.getDefault(), "the description");
    messageSource.addMessage("context.field.label", Locale.getDefault(), "the label");
    messageSource.addMessage("context.field.icon", Locale.getDefault(), "iconName");
    fieldFaceSource.setMessageSourceAccessor(new MessageSourceAccessor(messageSource));
View Full Code Here

    MessageSourceFieldFaceSource fieldFaceSource = new MessageSourceFieldFaceSource();

    StaticMessageSource messageSource = new StaticMessageSource();
    messageSource.addMessage("context.field.caption", Locale.getDefault(), "the caption");
    messageSource.addMessage("context.field.description", Locale.getDefault(), "the description");
    messageSource.addMessage("context.field.label", Locale.getDefault(), "the label");
    messageSource.addMessage("context.field.icon", Locale.getDefault(), "iconName");
    fieldFaceSource.setMessageSourceAccessor(new MessageSourceAccessor(messageSource));

    IconSource mockIconSource = (IconSource) EasyMock.createMock(IconSource.class);
View Full Code Here

    MessageSourceFieldFaceSource fieldFaceSource = new MessageSourceFieldFaceSource();

    StaticMessageSource messageSource = new StaticMessageSource();
    messageSource.addMessage("context.field.caption", Locale.getDefault(), "the caption");
    messageSource.addMessage("context.field.description", Locale.getDefault(), "the description");
    messageSource.addMessage("context.field.label", Locale.getDefault(), "the label");
    messageSource.addMessage("context.field.icon", Locale.getDefault(), "iconName");
    fieldFaceSource.setMessageSourceAccessor(new MessageSourceAccessor(messageSource));

    IconSource mockIconSource = (IconSource) EasyMock.createMock(IconSource.class);
    EasyMock.expect(mockIconSource.getIcon("iconName")).andReturn(testIcon);
View Full Code Here

    StaticMessageSource messageSource = new StaticMessageSource();
    messageSource.addMessage("context.field.caption", Locale.getDefault(), "the caption");
    messageSource.addMessage("context.field.description", Locale.getDefault(), "the description");
    messageSource.addMessage("context.field.label", Locale.getDefault(), "the label");
    messageSource.addMessage("context.field.icon", Locale.getDefault(), "iconName");
    fieldFaceSource.setMessageSourceAccessor(new MessageSourceAccessor(messageSource));

    IconSource mockIconSource = (IconSource) EasyMock.createMock(IconSource.class);
    EasyMock.expect(mockIconSource.getIcon("iconName")).andReturn(testIcon);
    EasyMock.replay(mockIconSource);
View Full Code Here

    BeanPropertyBindingResult ex = new BeanPropertyBindingResult(tb, "tb");
    ex.reject("invalid");
    ex.rejectValue("age", "invalidField");

    StaticMessageSource ms = new StaticMessageSource();
    ms.addMessage("invalid", Locale.US, "general error");
    ms.addMessage("invalidField", Locale.US, "invalid field");

    assertEquals("general error", ms.getMessage(ex.getGlobalError(), Locale.US));
    assertEquals("invalid field", ms.getMessage(ex.getFieldError("age"), Locale.US));
  }
View Full Code Here

    ex.reject("invalid");
    ex.rejectValue("age", "invalidField");

    StaticMessageSource ms = new StaticMessageSource();
    ms.addMessage("invalid", Locale.US, "general error");
    ms.addMessage("invalidField", Locale.US, "invalid field");

    assertEquals("general error", ms.getMessage(ex.getGlobalError(), Locale.US));
    assertEquals("invalid field", ms.getMessage(ex.getFieldError("age"), Locale.US));
  }
View Full Code Here

        .getELResolver().getType(context, null, getBaseVariable()));
  }

  public void testGetType_ResolvableCode() {
    StaticMessageSource ms = new StaticMessageSource();
    ms.addMessage("foo.bar", Locale.getDefault(), "hello");

    RequestContextHolder.setRequestContext(new MockRequestContext());
    assertEquals("Message should resolve to a type of String", String.class,
        context.getELResolver().getType(context, ms, "foo.bar"));
  }
View Full Code Here

        context.getELResolver().getType(context, ms, "foo.bar"));
  }

  public void testGetType_InvalidCode() {
    StaticMessageSource ms = new StaticMessageSource();
    ms.addMessage("foo.bar", Locale.getDefault(), "hello");

    RequestContextHolder.setRequestContext(new MockRequestContext());
    try {
      context.getELResolver().getType(context, ms, "foo.baz");
      fail("Message should not be resolvable");
View Full Code Here

  }

  public void testGetValue_ResolvableCode() {
    StaticMessageSource ms = new StaticMessageSource();
    ms.addMessage("foo.bar", Locale.getDefault(), "hello");

    RequestContextHolder.setRequestContext(new MockRequestContext());
    assertEquals("Message should resolve to a valid message value", "hello",
        context.getELResolver().getValue(context, ms, "foo.bar"));
  }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.