private Formatter<Number> configureFormatterFrom(NumberFormat annotation) { String pattern = resolveEmbeddedValue(annotation.pattern()); if (StringUtils.hasLength(pattern)) { return new NumberStyleFormatter(pattern); } else { Style style = annotation.style(); if (style == Style.CURRENCY) { return new CurrencyStyleFormatter(); } else if (style == Style.PERCENT) { return new PercentStyleFormatter(); } else { return new NumberStyleFormatter(); } } }
private Formatter<MonetaryAmount> configureFormatterFrom(NumberFormat annotation) { String pattern = resolveEmbeddedValue(annotation.pattern()); if (StringUtils.hasLength(pattern)) { return new PatternDecoratingFormatter(pattern); } else { Style style = annotation.style(); if (style == Style.NUMBER) { return new NumberDecoratingFormatter(new NumberStyleFormatter()); } else if (style == Style.PERCENT) { return new NumberDecoratingFormatter(new PercentStyleFormatter()); } else { return new NumberDecoratingFormatter(new CurrencyStyleFormatter()); } } }
private Formatter<Number> configureFormatterFrom(NumberFormat annotation) { String pattern = resolveEmbeddedValue(annotation.pattern()); if (StringUtils.hasLength(pattern)) { return new NumberStyleFormatter(pattern); } else { Style style = annotation.style(); if (style == Style.CURRENCY) { return new CurrencyStyleFormatter(); } else if (style == Style.PERCENT) { return new PercentStyleFormatter(); } else { return new NumberStyleFormatter(); } } }
private Formatter<MonetaryAmount> configureFormatterFrom(NumberFormat annotation) { String pattern = resolveEmbeddedValue(annotation.pattern()); if (StringUtils.hasLength(pattern)) { return new PatternDecoratingFormatter(pattern); } else { Style style = annotation.style(); if (style == Style.NUMBER) { return new NumberDecoratingFormatter(new NumberStyleFormatter()); } else if (style == Style.PERCENT) { return new NumberDecoratingFormatter(new PercentStyleFormatter()); } else { return new NumberDecoratingFormatter(new CurrencyStyleFormatter()); } } }
@Test public void printFormattedScopedAttributeResult() throws Exception { PercentStyleFormatter formatter = new PercentStyleFormatter(); tag.setExpression("bean.formattable"); int action = tag.doStartTag(); assertEquals(Tag.EVAL_BODY_INCLUDE, action); action = tag.doEndTag(); assertEquals(Tag.EVAL_PAGE, action); assertEquals(formatter.print(new BigDecimal(".25"), Locale.getDefault()), ((MockHttpServletResponse) context.getResponse()).getContentAsString()); }
private Formatter<Number> configureFormatterFrom(NumberFormat annotation) { String pattern = resolveEmbeddedValue(annotation.pattern()); if (StringUtils.hasLength(pattern)) { return new NumberStyleFormatter(pattern); } else { Style style = annotation.style(); if (style == Style.CURRENCY) { return new CurrencyStyleFormatter(); } else if (style == Style.PERCENT) { return new PercentStyleFormatter(); } else { return new NumberStyleFormatter(); } } }
private Formatter<MonetaryAmount> configureFormatterFrom(NumberFormat annotation) { String pattern = resolveEmbeddedValue(annotation.pattern()); if (StringUtils.hasLength(pattern)) { return new PatternDecoratingFormatter(pattern); } else { Style style = annotation.style(); if (style == Style.NUMBER) { return new NumberDecoratingFormatter(new NumberStyleFormatter()); } else if (style == Style.PERCENT) { return new NumberDecoratingFormatter(new PercentStyleFormatter()); } else { return new NumberDecoratingFormatter(new CurrencyStyleFormatter()); } } }