Hi Isomorphic,
I'm trying to encode a criteria to save it in the database. All works fine till I add a date in the criteria.
When a date is added in the criteria, I'm not able to fetch the date with the criteria coming from the database.
The criteria is generated with a FilterBuilder.
I think the trouble come from the date parser... but I do not find a solution.
Here is an example
The filter encode looks like
with date is 03/06/2014 (format DD/MM/yyyy) in the filterbuilder for the field "CREATED".
The definition of the field "CREATED" is the datasource
Here is the date format that I use
Can you help me with that?
Thanks
Julien
I'm trying to encode a criteria to save it in the database. All works fine till I add a date in the criteria.
When a date is added in the criteria, I'm not able to fetch the date with the criteria coming from the database.
The criteria is generated with a FilterBuilder.
I think the trouble come from the date parser... but I do not find a solution.
Here is an example
Code:
JSONEncoder encoder = new JSONEncoder(); encoder.setDateFormat(JSONDateFormat.DATE_CONSTRUCTOR); String criteriaValue = JSON.encode(criteria.getJsObj(), encoder); System.out.println(criteriaValue); Criteria newCriteria = new AdvancedCriteria(JSON.decode(criteriaValue)); listGrid.fetchData(newCriteria);
Code:
{ "_constructor":"AdvancedCriteria", "operator":"and", "criteria":[ { "fieldName":"CREATED", "operator":"equals", "value":"2014-06-02T22:00:00.000", "_constructor":"AdvancedCriteria" } ] }
The definition of the field "CREATED" is the datasource
Code:
<field name="CREATED" type="creatorTimestamp" title="Created" hidden="false" details="true" />
Code:
private static DateTimeFormat dateTimeFormat = DateTimeFormat.getFormat("dd MMM yyyy - HH:mm:ss"); private static DateTimeFormat dateFormat = DateTimeFormat.getFormat("dd MMM yyyy"); private static DateTimeFormat timeFormat = DateTimeFormat.getFormat("HH:mm:ss"); DateUtil.setNormalDatetimeDisplayFormatter(new DateDisplayFormatter() { public String format(Date date) { return dateTimeFormat.format(date); } }); DateUtil.setNormalDateDisplayFormatter(new DateDisplayFormatter() { public String format(Date date) { return dateFormat.format(date); } }); DateUtil.setNormalTimeDisplayFormatter(new DateDisplayFormatter() { public String format(Date date) { return timeFormat.format(date); } }); DateUtil.setShortDatetimeDisplayFormatter(new DateDisplayFormatter() { public String format(Date date) { return dateTimeFormat.format(date); } }); DateUtil.setShortDateDisplayFormatter(new DateDisplayFormatter() { public String format(Date date) { return dateFormat.format(date); } }); DateUtil.setShortTimeDisplayFormatter(new DateDisplayFormatter() { public String format(Date date) { return timeFormat.format(date); } }); DateUtil.setDateParser(new DateParser() { public Date parse(String dateString) { if ((dateString == null) || (dateString.length() == 0)) return null; try{ return dateTimeFormat.parse(dateString); }catch(Exception e ){ e.printStackTrace(); } try{ return timeFormat.parse(dateString); }catch(Exception e){ e.printStackTrace(); } try { return dateFormat.parse(dateString); } catch (Exception e) { e.printStackTrace(); } return null; } });
Thanks
Julien
Comment