Announcement

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

    Date validator fails on a datasource

    Hi!
    I have been trying to get the date to be recognized correctly in a datasource. The input of the date is JSON date generated by flexjson. Based an earlier query, I have been able to sort out the date into a format I like. However, the listGrid still is confused about the date. I get this in the developer console:

    22:57:52.607:XRP6:WARN:DataSource:isc_OID_4$499:isc_OID_4$499.date: value: "9/8/2008" failed on validator: {type: "isDate",
    typeCastValidator: true,
    _generated: true,
    defaultErrorMessage: "Must be a date."}

    Here is my data Source definition:
    Code:
    	  DataSourceDateField dateField = new DataSourceDateField("date", "Date");
    	  dateField.setFieldValueExtractor(new FieldValueExtractor() {
    
    		@SuppressWarnings("deprecation")
    		@Override
    		public Object execute(Object record, Object value,
    				DataSourceField field, String fieldName) {
    			try {
    				long d = ((Long)value).longValue();
    				Date da = new Date(d);
    				
    				// This is formatting the date to the MM/DD/YYYY format. I wish there was a better way.
    				return da.getMonth() + "/" + da.getDate() + "/" + (da.getYear()+1900);
    			}catch(ClassCastException exception){
    				//return value.toString();
    				/*
    				 * Something is wrong with this format is always throws the illegalArgumentException
    				 */
    				DateTimeFormat inputFormat = DateTimeFormat.getFormat("MM/dd/yyyy");
    				DateTimeFormat outputFormat = DateTimeFormat.getFormat("MMM dd yyyy");
    				try {
    					String _idate = value.toString();
    					Date inputDate = inputFormat.parse(_idate);
    					String output = outputFormat.format(inputDate);
    					return output;
    				}catch(IllegalArgumentException exception1){
    					return value;
    				}
    				
    			}
    		}
    	  });
    Note that the field extractor is called twice, I changed the format in the field extractor to try and figure out where the date parsing is messed up. Looks like the first time the date field extractor runs, the returned format is not a date. I tried playing with different values of setShortDateDisplayFormatter and setDateInputFormatter. Oddly enough the code in those functions never got called in the debugger.

    Here is what I spelt out in the grid:
    Code:
    	  grid.setDateFormatter(DateDisplayFormat.TOUSSHORTDATE);
    What do I need to change for the developer console not to generate the error message of date not being parsed? In the grid, the date shows up as a string which I cannot sort by in any meaningful way. If the framework realizes that its a date, I will have more luck.

    -Wish
Working...
X