Details
-
Improvement
-
Status: Resolved
-
Minor
-
Resolution: Won't Fix
-
6.5.0
-
None
-
None
-
Windows 7 + Google Chrome
Description
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)
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)
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").