Announcement

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

    Bug in FilterBuilder using RelativeDateItem [Example included]

    After setting defaultValue to null on RelativeDateItem, FilterBuilder does not display the resulting criteria correctly.
    The example below illustrates this.

    The only difference in the code is
    Code:
    setEditorType(new RelativeDateItem(){{
    	setDefaultValue((Date)null);  // The only change 
    }});

    Code:
    package nl.tkvw.test.client;
    
    import java.util.Date;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.core.shared.GWT;
    import com.smartgwt.client.data.AdvancedCriteria;
    import com.smartgwt.client.data.DataSource;
    import com.smartgwt.client.data.DataSourceField;
    import com.smartgwt.client.types.FieldType;
    import com.smartgwt.client.util.BooleanCallback;
    import com.smartgwt.client.util.JSON;
    import com.smartgwt.client.util.SC;
    import com.smartgwt.client.widgets.Button;
    import com.smartgwt.client.widgets.events.ClickEvent;
    import com.smartgwt.client.widgets.events.ClickHandler;
    import com.smartgwt.client.widgets.form.FilterBuilder;
    import com.smartgwt.client.widgets.form.fields.RelativeDateItem;
    import com.smartgwt.client.widgets.layout.VLayout;
    
    /**
     * Entry point classes define <code>onModuleLoad()</code>.
     */
    public class TestApp implements EntryPoint {
    	FilterBuilder fb1;
    	FilterBuilder fb2;
        /**
         * This is the entry point method.
         */
        public void onModuleLoad() {
        	
        	new VLayout(){{
        		
        		setWidth100();
        		setHeight100();
        		addMember(new FilterBuilder(){{
        			fb1=this;
        			setDataSource(new DataSource(){{
        				setClientOnly(true);
        				addField(new DataSourceField("date",FieldType.DATE){{
        					setEditorType(new RelativeDateItem(){{
        						
        					}});
        				}});
        			}});
        		}});
        		addMember(new Button("Normal"){{
        			addClickHandler(new ClickHandler() {
    					@Override
    					public void onClick(ClickEvent event) {
    						SC.confirm("Did you set a relative date in the filterbuilder? ",new BooleanCallback() {
    							@Override
    							public void execute(Boolean value) {
    								if(Boolean.TRUE == value){
    									AdvancedCriteria criteria = fb1.getCriteria(false);
    									GWT.log(JSON.encode(criteria.getJsObj()));
    									fb1.clearCriteria();
    									fb1.setCriteria(criteria);
    									
    									SC.say("It is still displayed...");
    								}
    							}
    						});
    					}
    				});
        		}});
    
        		addMember(new FilterBuilder(){{
        			fb2=this;
        			setDataSource(new DataSource(){{
        				setClientOnly(true);
        				addField(new DataSourceField("date",FieldType.DATE){{
        					setEditorType(new RelativeDateItem(){{
        						setDefaultValue((Date)null);
        					}});
        				}});
        			}});
        		}});
        		addMember(new Button("See Bug"){{
        			addClickHandler(new ClickHandler() {
    					@Override
    					public void onClick(ClickEvent event) {
    						SC.confirm("Did you set a relative date in the filterbuilder? ",new BooleanCallback() {
    							@Override
    							public void execute(Boolean value) {
    								if(Boolean.TRUE == value){
    									AdvancedCriteria criteria = fb2.getCriteria(false);
    									GWT.log(JSON.encode(criteria.getJsObj()));
    									fb2.clearCriteria();
    									fb2.setCriteria(criteria);
    									
    									SC.say("And now it disappeared.");
    								}
    							}
    						});
    					}
    				});
        		}});
        		
        	}}.draw();
        	
        }
    
    }

    #2
    That's not a valid use of setEditorType() - see the docs for this method. To do something like that, you'd need to use an initHandler, not an anonymous initializer.

    Comment


      #3
      Thanks for your quick reply, but I think you've looked to quickly.
      I understand the use of setEditorType, what I am doing is legal and correct.Please take a close look at the example.

      So, the only think happening is that editorType will be set to "RelativeDateItem" and editorProperties will be {"defaultValue":null} for this datasourceField.

      ListGridBuilder uses these properties to create an editor,nothing more, nothing less. The inithandler is only required for custom objects or if I want custom handling. There is no need for that in this example.
      For your information, this is the implementation of setEditorType in DataSourceField.java of your SmartGWT code:
      Code:
          public void setEditorType(FormItem editorType) {
              //only set the editorType attribute if the passed editorType is a concrete subclass of FormItem
              if(!editorType.getClass().getName().equals(FormItem.class.getName())) {
                  String fiEditorType = editorType.getAttribute("editorType");
                  //fallback to type if editorType is not specified
                  if(fiEditorType == null) fiEditorType = editorType.getType();
                  if (fiEditorType != null) setAttribute("editorType", fiEditorType);
              }
              JavaScriptObject editorConfig = editorType.getConfig();
              setAttribute("editorProperties", editorConfig);
          }

      Comment

      Working...
      X