Package org.springframework.springfaces.message

Examples of org.springframework.springfaces.message.ObjectMessageSource


   * Create the {@link SelectItem} for any {@link #getIncludeNoSelectionOption() included} noSelectionOption item.
   * @param context the faces context
   * @return a new select item
   */
  protected SelectItem createNoSelectionOption(FacesContext context) {
    ObjectMessageSource objectMessageSource = getObjectMessageSource(context);
    Locale locale = FacesUtils.getLocale(context);
    String label = objectMessageSource.getMessage(NO_SELECTION_OPTION_MESSAGE_CODE, null,
        NO_SELECTION_OPTION_DEFAULT_MESSAGE, locale);
    return new SelectItem(null, label, null, false, true, true);
  }
View Full Code Here


  }

  private String getItemLabel(FacesContext context, Object value) {
    String itemLabel = getItemLabel();
    if (itemLabel == null) {
      ObjectMessageSource messageSource = getObjectMessageSource(context);
      Locale locale = FacesUtils.getLocale(context);
      try {
        itemLabel = messageSource.getMessage(value, null, locale);
      } catch (NoSuchObjectMessageException e) {
      }
    }
    if (itemLabel == null) {
      itemLabel = deduceItemLabel(value);
View Full Code Here

    return itemLabel;
  }

  private ObjectMessageSource getObjectMessageSource(FacesContext context) {
    ApplicationContext applicationContext = getApplicationContext(context);
    ObjectMessageSource messageSource = ObjectMessageSourceUtils.getObjectMessageSource(getMessageSource(),
        applicationContext);
    return messageSource;
  }
View Full Code Here

    MessageSource messageSource = getSource();
    ApplicationContext applicationContext = getApplicationContext(context);
    Assert.state(((applicationContext != null) || (messageSource != null)),
        "Unable to find MessageSource, ensure that SpringFaces intergation "
            + "is enabled or set the 'source' attribute");
    ObjectMessageSource objectMessageSource = ObjectMessageSourceUtils.getObjectMessageSource(messageSource,
        applicationContext);
    return new UIMessageSourceMap(context, objectMessageSource,
        prefixCodes.toArray(new String[prefixCodes.size()]), isReturnStringsWhenPossible());
  }
View Full Code Here

    this.converterCaptor.getValue().getAsString(this.facesContext, parent, SampleEnum.ONE);
  }

  @Test
  public void shouldUseObjectMessageSourceToCreateLabel() throws Exception {
    ObjectMessageSource messageSource = mock(ObjectMessageSource.class);
    given(this.applicationContext.containsBean(AbstractApplicationContext.MESSAGE_SOURCE_BEAN_NAME)).willReturn(
        true);
    given(this.applicationContext.getBean(AbstractApplicationContext.MESSAGE_SOURCE_BEAN_NAME)).willReturn(
        messageSource);
    given(messageSource.getMessage(SampleEnum.ONE, null, this.locale)).willReturn("Eins");
    UIComponent parent = mockParent(UISelectMany.class);
    this.selectItems.setParent(parent);
    this.selectItems.setValue(Collections.singleton(SampleEnum.ONE));
    SelectItem actual = this.selectItems.getSelectItems().get(0);
    assertThat(actual.getLabel(), is("Eins"));
View Full Code Here

    assertThat(actual.getLabel(), is("Eins"));
  }

  @Test
  public void shouldSupportCustomMessageSource() throws Exception {
    ObjectMessageSource messageSource = mock(ObjectMessageSource.class);
    given(messageSource.getMessage(SampleEnum.ONE, null, this.locale)).willReturn("Eins");
    UIComponent parent = mockParent(UISelectMany.class);
    this.selectItems.setParent(parent);
    this.selectItems.setValue(Collections.singleton(SampleEnum.ONE));
    this.selectItems.setMessageSource(messageSource);
    SelectItem actual = this.selectItems.getSelectItems().get(0);
View Full Code Here

    assertThat(actual.getLabel(), is("Eins"));
  }

  @Test
  public void shouldIgnoreNoSuchObjectMessageException() throws Exception {
    ObjectMessageSource messageSource = mock(ObjectMessageSource.class);
    given(messageSource.getMessage(SampleEnum.ONE, null, this.locale)).willThrow(
        new NoSuchObjectMessageException(SampleEnum.ONE, this.locale));
    UIComponent parent = mockParent(UISelectMany.class);
    this.selectItems.setParent(parent);
    this.selectItems.setValue(Collections.singleton(SampleEnum.ONE));
    this.selectItems.setMessageSource(messageSource);
View Full Code Here

    assertThat(actual, is(equalTo("test")));
  }

  @Test
  public void shouldSupportTopLevelObjectWithArgumentsWhenBackedWithObjectMessageSource() throws Exception {
    ObjectMessageSource objectMessageSource = mock(ObjectMessageSource.class);
    MessageSourceMap map = new TestMessageSourceMap(objectMessageSource);
    ObjectResolvable resolvable = new ObjectResolvable();
    String expected = "test";
    given(objectMessageSource.getMessage((Object) eq("y"), emptyObjectArray(), nullLocale())).willReturn("y2");
    given(objectMessageSource.getMessage((Object) eq("z"), emptyObjectArray(), nullLocale())).willThrow(
        new NoSuchObjectMessageException("z", null));
    given(objectMessageSource.getMessage(eq(resolvable), eq(new Object[] { "y2", "z" }), nullLocale())).willReturn(
        expected);
    String actual = map.get(resolvable, "y", "z").toString();
    assertThat(actual, is(equalTo(expected)));
  }
View Full Code Here

TOP

Related Classes of org.springframework.springfaces.message.ObjectMessageSource

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.