How do I ensure that the user has entered either a valid date or no date in a DateItem when useTextItem is set to true? I'd like this to be the default behavior for all DateItems unless I add other validations to specific DateItems.
I am already using DateUtil to set formatters and parser so that the current locale is used, as follows. This is fairly old code so if there is a better way to do this now please let me know.
I am already using DateUtil to set formatters and parser so that the current locale is used, as follows. This is fairly old code so if there is a better way to do this now please let me know.
Code:
// Set normal input and display format for dates based on locale DateUtil.setDateInputFormatter(new DateInputFormatter() { @Override public Date parse(String dateString) { if (dateString==null) return null; else return DateTimeFormat.getFormat(PredefinedFormat.DATE_SHORT).parse(dateString); } }); DateUtil.setShortDateDisplayFormatter(new DateDisplayFormatter() { @Override public String format(Date date) { if (date==null) return null; else return DateTimeFormat.getFormat(PredefinedFormat.DATE_SHORT).format(date); } }); DateUtil.setNormalDateDisplayFormatter(new DateDisplayFormatter() { @Override public String format(Date date) { if (date==null) return null; else return DateTimeFormat.getFormat(PredefinedFormat.DATE_MEDIUM).format(date); } });
Comment