Announcement

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

    SimpleType with custom editor problem

    I created a simple type to use in my application.
    my custom type:
    Code:
    public class TestST extends SimpleType{
      public TestST(){
        this.setName("testType");
        this.setValidators(new IsIntegerValidator());
        //next line breaks the code
        this.setEditorType(new TextItem());
      }
    }
    creating form from datasource with as field that has our custom type:
    Code:
    //following line is needed to find the type string
    new TestST().create();
    
    //datasource with one field that is set to our custom type
    DataSource ds = new DataSource();
    DataSourceField dsf = new DataSourceField();
    dsf.setName("name");
    dsf.setTitle("Title");
    dsf.setAttribute("type", "testType"); // smartgwt does not have a method for this
    ds.setFields(dsf);
    
    //form generated from the DataSource
    final DynamicForm df = new DynamicForm();
    df.setDataSource(ds);
    When i set the editor from inside my SimpleType, i get a runtime error (com.google.gwt.core.client.JavaScriptException: (TypeError): Object expected) when i add the form to the main canvas. Is this a bug or did i do something wrong?
    I have the problem with SmartGWT 1.1 and SmartGWT 1.2 SNAPSHOT.
    Setting the editor type from inside the datasource works ok but would like to do it from my type.

    I also go an other related question:
    I want to format the displayed value, in the SmartClient API I'm finding http://www.smartclient.com/docs/6.5.1/a/b/c/go.html#method..SimpleType.normalDisplayFormatter, but it seems that for SmartGWT I will have to work with maskvalidator. Is that true?

    #2
    I got seteditortype to work by setting the Attribute right away to the class name of a form item.
    Code:
    setAttribute("editorType", "SelectItem", false);
    but this still doesn't want to work if i use the classname of a custom element. any tips on how to do this?

    Comment


      #3
      Wow thanks a bunch for that line
      //following line is needed to find the type string
      new TestST().create();

      It finally let the ZipCodeUS example work which is in SmartClient showcase but not in SmartGWT showcase.

      Can you explain what it does? Or will I always refer to it as 'the magic code' :)


      Code:
      public void onModuleLoad() {
      	RootPanel.get().add(getCanvas());
      }
      
      
      private class ZipCodeUS extends SimpleType {
      	public ZipCodeUS() {
      		setName("ZipCodeUS");
      		RegExpValidator validator = new RegExpValidator();
      		validator.setExpression("^\\d{5}(-\\d{4})?$");
      		setValidators(validator);
      		setInheritsFrom("text");
      	}
      }
      
      public Canvas getCanvas() {
      	
      	VLayout layout = new VLayout();
      	
      	DataSource ds = new DataSource();
      	ds.setClientOnly(true);
      	
      	DataSourceField field = new DataSourceField();
      	field.setName("zipCode");
      	field.setTitle("Zip Code");
      	
      	JavaScriptObject jsobject = new ZipCodeUS().create();
      	field.setAttribute("type", "ZipCodeUS");
      	ds.addField(field);
      	
      	
      	
      	field = new DataSourceTextField("tester", "Framework field");
      	RegExpValidator validator = new RegExpValidator();
      	validator.setExpression("^\\d{5}(-\\d{4})?$");
      	field.setValidators(validator);
      	ds.addField(field);
      	
      	
      	final DynamicForm form = new DynamicForm();
      	form.setDataSource(ds);
      	//form.setValidateOnChange(true);
      	
      	
      	Button button = new Button("validate");
      	button.addClickHandler(new ClickHandler() {
      		
      		public void onClick(ClickEvent event) {
      			form.validate();
      		}
      	});
      	
      	layout.addMember(form);
      	layout.addMember(button);
      			
      	
      	return layout;
      }

      Comment

      Working...
      X