TheCoder4eu / BootsFaces-OSP

BootsFaces - Open Source Project
Apache License 2.0
247 stars 102 forks source link

DateTimePickerRenderer may call typed Converter with String #1160

Closed bmilcke closed 1 week ago

bmilcke commented 3 years ago

I am using a DateTimePickker with a bound LocalDate value and a corresponding Converter. The Converter is typed, i.e. implements Converter<LocalDate> not just Converter using Object. The field is also required.

When no value is set, on validation there is an error calling Converter<LocalDate> with the empty String "".

In the decode-Method Line 59 of the renderer subVal ist the empty String that is set as submitted value.

On rendering in the Method encodeHTML Line 222 the submitted value is retrieved as variable v, which is the empty String and not null. This value is passed to getValueAsString() and subsequently to getDateAsString()

In the call to getDateAsString in Line 115 the (untyped) converter is called with the empty String, which fails, because the expected parameter is of type LocalDate. This causes the converter to crash.

A workaround would be to implement untyped converters. But this is not the recommended way to implement converters.

One way to fix this would be to ensure that on setSubmittedValue no empty String is set but instead null.

Change the code in Line 59 and following of the renderer from

if (subVal != null) {
    dtp.setSubmittedValue(subVal);
    dtp.setValid(true);
}

to

if (subVal != null && !"".equals(subVal)) {
    dtp.setSubmittedValue(subVal);
    dtp.setValid(true);
}

I am not sure if this can be done without any negative effects on other code, but it seems reasonable to me.

stephanrauh commented 1 week ago

I'm afraid development of BootsFaces has slowed down considerably. We'll never manage to address this issue. Let's close it.