Announcement

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

    FilterBuilder and custom date parser

    Dear Support,

    I was able to reproduce a problem when I'm using the FilterBuilder, date picker and custom data parsers together.

    1) I've configured our own date parser (we've added our own parsers and formatters using the DateUtil API) :

    Code:
    [...]
    private static DateTimeFormat dateFormat = DateTimeFormat.getFormat("dd MMM yyyy");
    	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");
    [...]
    
    // We've setup all the Normal/Short Date/Time formaters and parses in your API
    DateUtil.setDateParser(new DateParser() {
    
    			public Date parse(String dateString) {
    				return dateFormat.parse(dateString);
    			}
    		});
    2) Here is a test case code (we are using the serialization to store the current filter of a listgrid) :

    Code:
    DataSource.load(DSBusinessUnit.DS_NAME,new Function() {
    			@Override
    			public void execute() {
    				VLayout panel = new VLayout();
    				panel.setBackgroundColor("white");
    				final FilterBuilder builder = new FilterBuilder();
    				builder.setDataSource(DataSource.get(DSBusinessUnit.DS_NAME));
    				panel.setMembers(builder);
    				panel.show();
    			}
    		}, false);
    3) In our Datasource we have this field:

    Code:
    <field name="CREATED" type="creatorTimestamp" title="$created" hidden="false" details="true" />
    To reproduce the bug on 4.0p:
    - Select that "CREATED" field in the field list
    - Use the date picker icon and select a Date (see screenshot)

    - First, we see that it uses our other formatters (DateTime !) to format the date displayed right to the picker.
    - Then it uses our formatter (Date) to when the picker popup is shown
    - As soon as we CLICK on a date in the popup, it use our DateTime formatter
    - The we have the following exception... because you seem to try to parse the collected date (in DateTime format) using the Date parser:

    We receive this kind of error:

    Code:
    java.lang.IllegalArgumentException: 29 Jan 2014 - 10:06:00
    	at com.google.gwt.i18n.shared.DateTimeFormat.parse(DateTimeFormat.java:1437)
    	at com.google.gwt.i18n.shared.DateTimeFormat.parse(DateTimeFormat.java:882)
    	at com.fircosoft.cdb.client.localization.Localization.parseDate(Localization.java:209)
    	at com.fircosoft.cdb.client.localization.Localization$7.parse(Localization.java:116)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    	at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    	at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
    	at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:293)
    	at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547)
    	at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
    	at java.lang.Thread.run(Unknown Source)
    Many thanks in advance for your help,
    Thomas
    Attached Files

    #2
    Did you perhaps post the wrong stack trace?

    SmartGWT is not in the stack trace, and the series of calls shown doesn't match the code you've shown here.

    Can you try creating a minimal, standalone test case to see if this is really a SmartGWT issue?

    Comment


      #3
      Here is a more complete and stand-alone test case and the corresponding stack trace. SmartGWT does not appear, but it happens when interacting your the popup widget, which I did not change of course.

      To reproduce:
      - select a field which is a datetime (or creatortimestamp)
      - click on the small calendar icon new to the value combo
      - select a date

      Code:
      final DateTimeFormat	dateTimeFormat	= DateTimeFormat.getFormat("dd MMM yyyy - HH:mm:ss");
      		final DateTimeFormat	dateFormat		= DateTimeFormat.getFormat("dd MMM yyyy");
      		final 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) {
      				try {
      					return dateFormat.parse(dateString);
      				} catch (Exception e) {
      					e.printStackTrace();
      					return null;
      				}
      			}
      		});
      			
      		DataSource.load(DSBusinessUnit.DS_NAME,new Function() {
      			@Override
      			public void execute() {
      				VLayout panel = new VLayout();
      				panel.setBackgroundColor("white");
      				final FilterBuilder builder = new FilterBuilder();
      				builder.setDataSource(DataSource.get(DSBusinessUnit.DS_NAME));
      				panel.setMembers(builder);
      				panel.show();
      			}
      		}, false);
      Stack:
      Code:
      java.lang.IllegalArgumentException: 13 Jan 2014 - 00:00:00
      	at com.google.gwt.i18n.shared.DateTimeFormat.parse(DateTimeFormat.java:1437)
      	at com.google.gwt.i18n.shared.DateTimeFormat.parse(DateTimeFormat.java:882)
      	at com.fircosoft.cdb.client.ComplianceDashboard$7.parse(ComplianceDashboard.java:90)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      	at java.lang.reflect.Method.invoke(Unknown Source)
      	at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
      	at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
      	at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
      	at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:293)
      	at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547)
      	at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
      	at java.lang.Thread.run(Unknown Source)
      java.lang.IllegalArgumentException: 13 Jan 2014 - 00:00:00
      	at com.google.gwt.i18n.shared.DateTimeFormat.parse(DateTimeFormat.java:1437)
      	at com.google.gwt.i18n.shared.DateTimeFormat.parse(DateTimeFormat.java:882)
      	at com.fircosoft.cdb.client.ComplianceDashboard$7.parse(ComplianceDashboard.java:90)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      	at java.lang.reflect.Method.invoke(Unknown Source)
      	at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
      	at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
      	at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
      	at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:293)
      	at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547)
      	at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
      	at java.lang.Thread.run(Unknown Source)

      Comment


        #4
        Sorry for the delay updating on this - it turns out, your parser is wrong - you're dealing with datetimes, but you're parsing dates.

        If you alter it to parse the dateTimeFormat, instead of the dateFormat, it will work.

        Comment

        Working...
        X