Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    12.0p: How to save yyyy-MM-dd String from DateItem into field of type text

    Hi Isomorphic,

    I'm trying to save a date as text to the DB (we have custom fields where the actual value is saved in a field of the correct datatype, but in the GUI I can define a default value for these fields. This default value is stored in a text field. There are nicer designs for sure, but this is what I have) and have problems to get to the following:
    • Display select value from DateItem textField as yyyy-MM-dd (working)
    • Save it as text yyyy-MM-dd (not working)
    • On reload from DB parse it from DB as yyyy-MM-dd (I think it's working)
    Do you have any pointers?
    I thought I need to @Override DateItem.getValueAsDate(), or perhaps FormItem.getValue(), but this does not seem to work - breakpoints are not hit. The only breakpoint that is it, is the one for _getValue() (with underscore), that is doc'd, but does not have any text. This is what I have so far:

    Code:
        private class ISODateItem extends DateItem {
            // di.setDateFormatter(DateDisplayFormat.TOSERIALIZEABLEDATE);
            // di.setDisplayFormat(DateDisplayFormat.TOSERIALIZEABLEDATE);
            @Override
            public Object getValue() {
                return super.getValue(); // breakpoint at this line not hit
            }
    
            @Override
            public Date getValueAsDate() {
                return super.getValueAsDate(); // breakpoint at this line not hit
            }
    
            @Override
            public Object _getValue() {
                return super._getValue(); // breakpoint at this line is hit
            }
    
            public ISODateItem() {
                setEditorValueParser(new FormItemValueParser() {
                    @Override
                    public Object parseValue(String value, DynamicForm form, FormItem item) {
                        try {
                            DateTimeFormat dateTimeFormat = DateTimeFormat.getFormat("yyyy-MM-dd");
                            return dateTimeFormat.parse(value);
                        } catch (Exception e) {
                            // ignore
                        }
                        return null;
                    }
                });
    
                setEditorValueFormatter(new FormItemValueFormatter() {
                    @Override
                    public String formatValue(Object value, Record record, DynamicForm form, FormItem item) {
                        DateTimeFormat dateTimeFormat = DateTimeFormat.getFormat("yyyy-MM-dd");
                        return dateTimeFormat.format((Date) value);
                    }
                });
            }
        }
    Thank you & Best regards
    Blama

    #2
    The methods you tried to override are not marked as valid override points, so it's expected that your breakpoints are not hit. That last (_getValue) isn't even documented, so it wouldn't be valid to call, much less override.

    We're not really following the use case here. If you're trying to allow end users to define a default value, why wouldn't you just store that as a date?

    Even if you want to store a text value, the value of a DateItem must be a Date, period, it cannot be a text value. If you want to convert from text to date, you need to do it before you try to provide the value to a DateItem.

    Comment

    Working...
    X