@Test public void shouldUseTheDefaultLocale() throws ParseException { when(request.getSession()).thenReturn(session); when(request.getAttribute("javax.servlet.jsp.jstl.fmt.locale.request")).thenReturn(null); when(session.getAttribute("javax.servlet.jsp.jstl.fmt.locale.session")). thenReturn(null); when(context.getAttribute("javax.servlet.jsp.jstl.fmt.locale.application")). thenReturn(null); when(context.getInitParameter("javax.servlet.jsp.jstl.fmt.locale")). thenReturn(null); when(request.getLocale()).thenReturn(Locale.getDefault()); DecimalFormat fmt = new DecimalFormat("##0,00"); fmt.setParseBigDecimal(true); fmt.setMinimumFractionDigits(2); BigDecimal theValue = new BigDecimal("10.00"); String formattedValue = fmt.format(theValue); assertThat(converter.convert(formattedValue, BigDecimal.class, bundle), is(equalTo(theValue))); }
public BigDecimal convert(String value, Class<? extends BigDecimal> type, ResourceBundle bundle) { if (isNullOrEmpty(value)) { return null; } try { final Locale locale = localization.getLocale(); DecimalFormat fmt = (DecimalFormat) DecimalFormat.getInstance(locale); fmt.setParseBigDecimal(true); return (BigDecimal) fmt.parse(value); } catch (ParseException e) { throw new ConversionError(MessageFormat.format(bundle.getString("is_not_a_valid_number"), value)); } }
LocaleBasedBigDecimalConverter implements Converter<BigDecimal> { public BigDecimal convert(String value, Class<? extends BigDecimal> type, ResourceBundle bundle) { if (isNullOrEmpty(value)) { return null; } try { final Locale locale = localization.getLocale(); DecimalFormat fmt = (DecimalFormat) DecimalFormat.getInstance(locale); fmt.setParseBigDecimal(true); return (BigDecimal) fmt.parse(value); } catch (ParseException e) { throw new ConversionError(MessageFormat.format(bundle.getString("is_not_a_valid_number"), value)); } } }
LocaleBasedBigDecimalConverter implements Converter<BigDecimal> { public BigDecimal convert(String value, Class<? extends BigDecimal> type, ResourceBundle bundle) { if (isNullOrEmpty(value)) { return null; } try { final Locale locale = localization.getLocale(); DecimalFormat fmt = (DecimalFormat) DecimalFormat.getInstance(locale); fmt.setParseBigDecimal(true); return (BigDecimal) fmt.parse(value); } catch (ParseException e) { throw new ConversionError(MessageFormat.format(bundle.getString("is_not_a_valid_number"), value)); } } LocaleBasedBigDecimalConverter(Localization localization); }
LocaleBasedBigDecimalConverter implements Converter<BigDecimal> { public BigDecimal convert(String value, Class<? extends BigDecimal> type, ResourceBundle bundle) { if (isNullOrEmpty(value)) { return null; } try { final Locale locale = localization.getLocale(); DecimalFormat fmt = (DecimalFormat) DecimalFormat.getInstance(locale); fmt.setParseBigDecimal(true); return (BigDecimal) fmt.parse(value); } catch (ParseException e) { throw new ConversionError(MessageFormat.format(bundle.getString("is_not_a_valid_number"), value)); } } LocaleBasedBigDecimalConverter(Localization localization); BigDecimal convert(String value, Class<? extends BigDecimal> type, ResourceBundle bundle); }
LocaleBasedBigDecimalConverter implements Converter<BigDecimal> { public BigDecimal convert(String value, Class<? extends BigDecimal> type, ResourceBundle bundle) { if (isNullOrEmpty(value)) { return null; } try { final Locale locale = localization.getLocale(); DecimalFormat fmt = (DecimalFormat) DecimalFormat.getInstance(locale); fmt.setParseBigDecimal(true); return (BigDecimal) fmt.parse(value); } catch (ParseException e) { throw new ConversionError(MessageFormat.format(bundle.getString("is_not_a_valid_number"), value)); } } LocaleBasedBigDecimalConverter(Localization localization); BigDecimal convert(String value, Class<? extends BigDecimal> type, ResourceBundle bundle);  }