Announcement

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

    Replace CanvasItem causes exception

    I am using smartGwt version:
    v8.3p_2012-11-24/LGPL Development Only (built 2012-11-24)

    I have a DynamicForm that contains several CanvasItems. The CanvasItems hold different elements that are created and removed dynamicaly.

    When I run the following code and click on the generated button, the new canvasItem is created, but when I click on the SelectItem drop down arrow I get an exception:
    [ERROR] [gwttest] 14:22:11.303:IFCS8:WARN:Log:TypeError: this.form is null

    Code:
    import com.google.gwt.core.client.EntryPoint;
    import com.smartgwt.client.widgets.Button;
    import com.smartgwt.client.widgets.events.ClickHandler;
    import com.smartgwt.client.widgets.form.DynamicForm;
    import com.smartgwt.client.widgets.form.fields.CanvasItem;
    import com.smartgwt.client.widgets.form.fields.SelectItem;
    import com.smartgwt.client.widgets.layout.VLayout;
    
    public class GwtTest implements EntryPoint {
    private CanvasItem mComboCanvasItem;
    private SelectItem mCombo;
    private DynamicForm mComboDynamicForm;
    private DynamicForm mDynamicForm;
    private VLayout mAppletPanel;
    
    public void onModuleLoad() {
    		mAppletPanel = new VLayout();
    		mAppletPanel.draw();
    		mComboCanvasItem = new CanvasItem();
    		mComboCanvasItem.setShowTitle(false);
    		mCombo = new SelectItem();
    		mCombo.setShowTitle(false);
    		mCombo.setValueMap("aaa","bbb");
    		mComboDynamicForm = new DynamicForm();
    		mComboDynamicForm.setFields(mCombo);
    		mComboCanvasItem.setCanvas(mComboDynamicForm);
    		
    		mDynamicForm = new DynamicForm();
    		mDynamicForm.setFields(mComboCanvasItem);
    		mAppletPanel.addMember(mDynamicForm );
    		
    		Button replaceFieldButton = new Button("replace fields");
    		replaceFieldButton.addClickHandler(new ClickHandler() {
    			
    			@Override
    			public void onClick(com.smartgwt.client.widgets.events.ClickEvent event) {
    				mComboCanvasItem = new CanvasItem();
    				mComboCanvasItem.setCanvas(mComboDynamicForm);
    				mComboCanvasItem.setShowTitle(false);
    				mDynamicForm.setFields(mComboCanvasItem);
    				mDynamicForm .redraw();
    				mComboCanvasItem.setCanvas(mComboDynamicForm);
    				mDynamicForm .redraw();
    				
    				mCombo.setValueMap("baaa","dbbb");
    				
    				
    			}
    		});
    			
    		mAppletPanel.addMember(replaceFieldButton);
    	}
    }
    }
    After this exception the drop down field is not displayed. only after clicking it again it is displayed.
    It looks like the previous CanvasItem is not destroyed and it catches the click event.
    Last edited by rottem; 17 Dec 2012, 12:11.

    #2
    Two redraws() in a row here is definitely unnecessary. Try removing both, and adding only a markForRedraw() at the end.

    Comment


      #3
      Hi,
      Thanks for your reply.
      1. If I remove the first call to redraw, the SelectItem disappears.
      I can replace the second one with markForRedraw.
      2. The exception that I described before still happens.
      Rottem

      Comment


        #4
        We can't tell what's going on here or even really what you're doing from this code. Among other problems, "mDateItems" isn't even declared.

        If you think there might be a framework bug here, please show a minimal, runnable piece of code demonstrating a framework issue.

        Comment


          #5
          I updated the code in the original message to be more complete.
          Rottem

          Comment


            #6
            More complete but still not nearly runnable. It needs to be not only runnable but a clear demonstration of a framework issue. Remember you are competing for time with other bug reports that are actual clear bugs.

            Comment


              #7
              Thank you for your reply. I replaced the code with a code that runs and demonstrates the exception.
              Please run it.
              Press the button that is displayed.
              Try to open drop down list. The first time that you press it, it doesn't open and there is an exception. This exception can be seen in the firebug or in the eclipse console.
              If you press it again the drop down list opens.
              I think that there shouldn't be exceptions when you try to open a drop down list of a SelectItem
              Thank you
              Rottem

              Comment


                #8
                The problem is that you're trying to make a Canvas simultaneously attach to two CanvasItems, which is not valid.

                You need to get rid of the old CanvasItem first; it won't be valid to call setCanvas() on a new CanvasItem until the old one is gone.

                The simplest way to do so is to call setItems() with an empty array of items, which destroys the old items.

                Comment


                  #9
                  Hi
                  I tried to follow your advice. I added the line
                  mDynamicForm.setItems(new FormItem[0]);
                  at the begining of the
                  onClick(...)

                  There is no change in the behavior.
                  Rottem

                  Comment


                    #10
                    You also need to get rid of the two calls to redraw() and the second call to setCanvas().

                    Comment


                      #11
                      After following your advice the code of the onClick is as follows
                      Code:
                      	mDynamicForm.setItems(new FormItem[0]);
                      				mComboCanvasItem = new CanvasItem();
                      				mComboCanvasItem.setCanvas(mComboDynamicForm);
                      				mComboCanvasItem.setShowTitle(false);
                      				mDynamicForm.setFields(mComboCanvasItem);
                      				mDynamicForm.markForRedraw();
                      Now, after pressing the button, the SelectItem disappears.

                      Comment


                        #12
                        OK, that code really should be working (but not any previous version). We'll check this out, in the meantime, completely re-creating the contained Canvas would work, and as an alternative, completely re-creating the outer containing form (mDynamicForm) while retaining the same nested Canvas (mComboDynamicForm) would probably also work.

                        Comment


                          #13
                          I recreated mDynamicForm, the onClick code looks as follows:
                          Code:
                          				mDynamicForm.setItems(new FormItem[0]);
                          				mAppletPanel.removeChild(mDynamicForm);
                          				mDynamicForm = new DynamicForm();
                          				mComboCanvasItem = new CanvasItem();
                          				mComboCanvasItem.setCanvas(mComboDynamicForm);
                          				mComboCanvasItem.setShowTitle(false);
                          				mDynamicForm.setFields(mComboCanvasItem);
                          				mAppletPanel.addMember(mDynamicForm );
                          				mDynamicForm.markForRedraw();
                          There is still no change

                          Comment


                            #14
                            Hi,
                            Can you please help me find a work-arround that I can use (unless you already fixed this issue).
                            Thank you
                            Rottem

                            Comment


                              #15
                              See previous response - you have tried only one of two suggested workarounds.

                              Comment

                              Working...
                              X