Announcement

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

    getForm is null inside FormItem

    Hi,

    I'm trying to do what's described in this post, that is setting the Form's value on a custom FormItem so I can call this value via Form.getValues().

    However, the reference to getForm() inside the FormItem is null.

    Repro case:
    SmartGWT 1.3

    Code:
    private class MyCanvasItem extends CanvasItem {
    	private int timesClicked = 0;
    	public MyCanvasItem() {
    		super();
    		Button b = new Button("Click me");
    		b.addClickHandler(new ClickHandler() {
    			public void onClick(ClickEvent event) {
    				timesClicked++;
    				DynamicForm form = MyCanvasItem.this.getForm();
    				if (form == null) {
    					SC.say("Form reference is null :(");
    				} else {
    					form.setValue(MyCanvasItem.this.getName(), timesClicked);
    				}	
    			}
    		});
    		setCanvas(b);
    	}
    }
    
    private Canvas getFormRefTest() {
    	VLayout result = new VLayout();
    	
    	final DynamicForm form = new DynamicForm();
    	TextItem field1 = new TextItem("field1");
    	MyCanvasItem field2 = new MyCanvasItem();
    	field2.setName("field2");
    	field2.setTitle("Field 2");
    	
    	form.setFields(field1, field2);
    	
    	Button getValueMap = new Button("Show values");
    	getValueMap.addClickHandler(new ClickHandler() {
    		public void onClick(ClickEvent event) {
    			Map<String, String> map = form.getValues();
    			StringBuffer string = new StringBuffer("Form Value Map:<br/>");
    			for (String key : map.keySet()) {
    				string.append(key).append(": ").append(map.get(key)).append("<br/>");
    			}
    			SC.say(string.toString());
    		}
    	});
    	
    	
    	result.setMembers(form, getValueMap);
    	return result;
    }

    #2
    So what would be the best way to get a reference to the form inside the formitem?
    I see there are some ways to do it in SmartClient, but not with SmartGWT.

    Comment


      #3
      I'm using SmartGWT 2.0 and having the exact same problem.

      I have some FormItem's that I assign to a form via the setFields method, and later, when I try to get their associated form via getForm(), null is returned.

      Any help here?

      Comment


        #4
        It's too late for guys but may help somebody.
        You can get the form in case you've got an event from FormItem like com.smartgwt.client.widgets.form.fields.events.ClickEvent
        it has getForm() method which works.

        Comment


          #5
          Im having the same problem. I want to get the DynamicForm info without having to set up datasource (just get the values and read them client side).
          I keep getting null values too when i try to get the values from the form->formitem->value.

          Any help?

          dave

          Comment


            #6
            This is fixed in SVN.

            Comment


              #7
              I still get this a lot in FormItems.
              both this.getContainerWidget() == null and this.getForm() == null

              What works is this (workaround, I feel):
              I'm interested in those pointers when I do something.
              So when I act on the event and use event.getItem(), then
              event.getItem().getContainerWidget()
              and event.getItem().getForm() do give me the expected pointers.

              E.g:
              Code:
              addDoubleClickHandler(new DoubleClickHandler() {
              
                public void onDoubleClick(com.smartgwt.client.widgets.form.fields.events.DoubleClickEvent event) {
                  FormItem item = event.getItem();
                  Canvas notNull1 = item.getContainerWidget();
                  DynamicForm notNull2 = item.getForm();
                  Canvas isNull1 = MyEditor.this.getContainerWidget();
                  DynamicForm isNull2 = MyEditor.this.getForm();
              I guess using the event is not that bad, as it should contain the right widgets when using this item in a DynamicForm or when used in a ListGrid.
              Still, it's a bit strange that getForm returns null.

              Comment


                #8
                If this involves setEditorType, there are special rules (explained in the doc just linked) because the editorType you apply is used to create multiple FormItem instances (it's like a template).

                Comment

                Working...
                X