[
https://issues.apache.org/jira/browse/WICKET-5317?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Martin Grigorov updated WICKET-5317:
------------------------------------
Priority: Minor (was: Major)
> ConversionException message
> ---------------------------
>
> Key: WICKET-5317
> URL: https://issues.apache.org/jira/browse/WICKET-5317
> Project: Wicket
> Issue Type: Bug
> Affects Versions: 6.5.0
> Environment: Windows 7 + Google Chrome
> Reporter: Betlista
> Priority: Minor
> Labels: conversion, converter, converting
>
> I created my text field for time input where model is Integer:
> public class TimeTextField extends TextField<Integer> {
> private static final SimpleDateFormat sdf = new SimpleDateFormat();
> public TimeTextField(final String id, final IModel<Integer> model) {
> super(id, model);
> }
> public TimeTextField(final String id) {
> super(id);
> }
> @Override
> public <C> IConverter<C> getConverter(final Class<C> type) {
> if (type == Integer.class) {
> @SuppressWarnings("rawtypes")
> final IConverter converter = new TimeConverter();
> @SuppressWarnings("unchecked")
> final IConverter<C> converterTyped = converter;
> return converterTyped;
> }
> throw new IllegalArgumentException("Expected class is " +
> Integer.class.getName() + " got " + type.getName());
> }
> public static class TimeConverter implements IConverter<Integer> {
> private static final long serialVersionUID = -5849790156852845455L;
> @Override
> public Integer convertToObject(final String value, final Locale
> locale) {
> if (value == null) {
> return null;
> }
> final String trimmed = value.trim();
> try {
> final int minutes = (int) sdf.parse(trimmed).getTime() /
> 60000;
> return minutes;
> } catch (final ParseException pe) {
> throw new ConversionException("Time format is not valid.
> Valid time examples: 11:55 or 13:05")
> .setResourceKey("timeInMinutes.patternValidation");
> }
> }
> @Override
> public String convertToString(final Integer value, final Locale
> locale) {
> if (value == null) {
> return null;
> }
> final int hh = value / 60;
> final int mm = value % 60;
> return hh + ":" + mm;
> }
> }
> }
> When resource key is not set for ConversionException, default message ("The
> value of 'label' is not a valid Integer.") is displayed instead of the
> message passed to Exception.
> Same happens when there is no localization found for resource key.
> In both cases I'd expect that message passed to Exception is shown (in this
> case "Time format is not valid. Valid time examples: 11:55 or 13:05").
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira