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:
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:
Thank you & Best regards
Blama
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)
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 [B]is[/B] 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); } }); } }
Blama
Comment