CodeRAD icon indicating copy to clipboard operation
CodeRAD copied to clipboard

LabelPropertyView does not handle a null Date

Open Rocketeer007 opened this issue 2 years ago • 0 comments

I have a radLabel linked to a property which is a Date type, and uses the TimeAgo date format, like this:

<radLabel tag="Symbol.lastRefresh" dateFormat="TimeAgo" component.uiid="RefreshLabel" />

When the property value is null, I'd like to see "N/A", which is how the TimeAgoDateFormatter handles a null (quite nice, in my opinion). However, the logic in LabelPropertyView skips the formatter if the property value is null, and instead formats it as text (meaning I eventually see the text "null").

This is due to the implementation of LabelPropertyView._getText():

private String _getText() {
        Property prop = getPropertySelector().getLeafProperty();
        if (prop == null) {
            return "";
        }
        
        if (prop.getContentType().getRepresentationClass() == Date.class) {
            DateFormatterAttribute formatter = getField().getDateFormatter();
            if (formatter != null) {
                Date val = getPropertySelector().getDate(null);
                if (val != null) {
                    return formatter.getValue().format(val);
                }
            }
        }
                
        
        return getPropertySelector().getText("");
    }

Checking the various DateFormatter implementations, I think they all handle null in their own way, so I'd suggest removing the if (val != null) check.

Rocketeer007 avatar Sep 07 '23 16:09 Rocketeer007