Announcement

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

    DateUtil.setShortDatetimeDisplayFormatter problem

    Hi I am using smartgwt 2.5 nightly build from 2011-03-05, gwt 2.1.1 and FF 3.6.13 broswer.
    I found incoherent famework bahaviour.
    According to java doc "DateFormatAndStorage" datetime fields in requests will serialized in UTC. Problem is when I set DateUtil.setShortDatetimeDisplayFormatter.
    Code:
    		DateUtil.setShortDatetimeDisplayFormatter(new DateDisplayFormatter() {
    			
    			@Override
    			public String format(Date date) {
    				DateTimeFormat dtf = DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss");
    				return dtf.format(date);
    			}
    		});
    When field value is set in code
    Code:
    				btnSetDate.addClickHandler(new ClickHandler() {
    					
    					@Override
    					public void onClick(ClickEvent event) {
    						dtiDate.setValue(new Date());
    					}
    				});
    or by picker, after save in xml request datetime value is converted to UTC (in my case minus one hour)
    But when user enters date manually, after save, request goes to server with datetime values exact as they displayed in field.
    It only happens with with shortDateTimeDisplayFormater set, with
    Code:
    DateUtil.setShortDatetimeDisplayFormat(DateDisplayFormat.TOSERIALIZEABLEDATE)
    datetime values are converted (but since DateDisplayFormat.TOSERIALIZEABLEDATE cause time part missing, it is not suitable for me)
    I have server side logic written to save datetime values id database not in UTC time but local and now this logic does not work properly because in above scenario time sent to server sometimes is converted and sometimes not.
    Below my whole entry point class
    Code:
    public class SgwtDateTimeConvTest implements EntryPoint {
    	private VLayout vlTlo = new VLayout();
    		private DynamicForm frmDate = new DynamicForm(); 
    			private DateTimeItem dtiDate = new DateTimeItem("data", "Data");
    		private DynamicForm frmActions = new DynamicForm();
    			private ButtonItem btnZapisz = new ButtonItem("btnZapisz", "Zapisz");
    			private ButtonItem btnSetDate = new ButtonItem("btnSetDate", "Wpisz datę");
    			private ButtonItem btnGetDate= new ButtonItem("btnGetDate", "Pobierz datę");
    	public void onModuleLoad() {
    		
    		DateUtil.setShortDatetimeDisplayFormatter(new DateDisplayFormatter() {
    			
    			@Override
    			public String format(Date date) {
    				DateTimeFormat dtf = DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss");
    				return dtf.format(date);
    			}
    		});
    //		DateUtil.setShortDatetimeDisplayFormat(DateDisplayFormat.TOSERIALIZEABLEDATE);
    		
    		vlTlo.setSize("100%", "100%");
    		vlTlo.setShowEdges(true);
    			frmDate.setDataSource(DateDS.getInstance());
    //			frmDate.setUseAllDataSourceFields(true);
    			frmDate.setFields(dtiDate);
    			frmDate.setWidth(1);
    				
    			frmActions.setNumCols(3);
    			frmActions.setWidth(1);
    				btnZapisz.setStartRow(false);
    				btnZapisz.setEndRow(false);
    				btnZapisz.setAlign(Alignment.LEFT);
    				btnZapisz.addClickHandler(new ClickHandler() {
    					
    					@Override
    					public void onClick(ClickEvent event) {
    						frmDate.saveData(new DSCallback() {
    							
    							@Override
    							public void execute(DSResponse response, Object rawData, DSRequest request) {
    								// TODO Auto-generated method stub
    								
    							}
    						});
    					}
    				});
    				btnSetDate.setStartRow(false);
    				btnSetDate.setEndRow(false);
    				btnSetDate.setAlign(Alignment.LEFT);
    				btnSetDate.addClickHandler(new ClickHandler() {
    					
    					@Override
    					public void onClick(ClickEvent event) {
    						dtiDate.setValue(new Date());
    					}
    				});
    				btnGetDate.setStartRow(false);
    				btnGetDate.setEndRow(false);
    				btnGetDate.setAlign(Alignment.LEFT);
    				btnGetDate.addClickHandler(new ClickHandler() {
    					
    					@Override
    					public void onClick(ClickEvent event) {
    						DateTimeFormat dtf = DateTimeFormat.getFormat("yyyy-MM-dd HH:mm:ss");
    						SC.say(dtf.format(dtiDate.getValueAsDate()));
    					}
    				});
    			frmActions.setFields(btnZapisz, btnSetDate, btnGetDate);
    		vlTlo.addMember(frmDate);
    		vlTlo.addMember(frmActions);
    		vlTlo.draw();
    	}
    }
    and RestDataSourceClass
    Code:
    public class DateDS extends RestDataSource {
    	private static DateDS ds;
    	public static DateDS getInstance(){
    		if (ds == null){
    			ds = new DateDS("DateDS");
    		}
    		return ds;
    	}
    	public DateDS(String id) {
    		setID(id);
    		setDataProtocol(DSProtocol.POSTXML);
    		setDataFormat(DSDataFormat.XML);
    		setDataURL("/Date.Service");
    		OperationBinding fetchOB = new OperationBinding();
    		fetchOB.setOperationType(DSOperationType.FETCH);
    		OperationBinding addOB = new OperationBinding();
    		addOB.setOperationType(DSOperationType.ADD);
    		OperationBinding updateOB = new OperationBinding();
    		updateOB.setOperationType(DSOperationType.UPDATE);
    		setOperationBindings(addOB,fetchOB,updateOB);
    		DataSourceIntegerField dsifDateId = new DataSourceIntegerField("idDaty", "Id");
    		dsifDateId.setPrimaryKey(true);
    		DataSourceDateTimeField dsdtfDate = new DataSourceDateTimeField("data", "Data");
    		setFields(dsifDateId, dsdtfDate);
    	}
    
    	public DateDS(JavaScriptObject jsObj) {
    		super(jsObj);
    		// TODO Auto-generated constructor stub
    	}
    
    }
    If it is SGWT bug it will be corrected ?
    Last edited by lazinskip; 8 Mar 2011, 07:05.

    #2
    Any progress on this ?
    Isomorphic guys - I think issue is pretty obvious

    Comment

    Working...
    X