Announcement

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

    ClassCastException caused by Tab.getTabCanvas()

    Hi,

    I found that there is probably bug in SmartGWT implementation in class com.smartgwt.client.widgets.tab.Tab, method getTabCanvas(). This method does not create Canvas through ObjectFactory even if there could be different Tab implementations (ImgTab or Button). It always returns and registers StatefulCanvas instance.

    In some cases it leads to ClassCastException fired from Button.getOrCreateRef() or ImgTab.getOrCreateRef().

    Use such tabset and try to switch between tabs, it leads to ClassCastException in onTabSelected handler:

    Code:
    final Canvas cnv1 = new Canvas();
    cnv1.setContents("111111111111");
    final Canvas cnv2 = new Canvas();
    cnv2.setContents("222222222222");
    
    TabSet tabset = new TabSet();
    final Tab tab1 = new Tab();
    final Tab tab2 = new Tab();
    
    tab1.setTitle("TEST-1");
    tab1.setPane(cnv1);
    
    tab2.setTitle("TEST-2");
    tab2.setPane(cnv2);
    
    tabset.setWidth100();
    tabset.setHeight100();
    tabset.addTabSelectedHandler(new TabSelectedHandler() {
    	@Override
    	public void onTabSelected(TabSelectedEvent event) {
    		try {
    			event.getTab().getTabCanvas();
    			EventHandler.getTarget();
    		} catch (Throwable t ) {
    			SC.say("EXCEPTION! " + t);
    		}
    	}
    });
    
    tabset.addTab(tab1);
    tabset.addTab(tab2);
    Am I right, that such implementation in Tab.getTabCanvas() is not correct? Can you make a fix? Now we have to completely override standard method Tab.getTabCanvas().

    Thanks!

    SmartClient: v10.0p_2015-03-19/LGPL Development Only (built 2015-03-19)
    browser: IE11

    #2
    This has been fixed in SGWT 5.0p and newer, and the fix should be in Sunday's nightly builds.

    Note that the problem is actually the difference between how getTabCanvas() and EventHandler.getTarget() create the Canvas, so a workaround might be to always use the first API to retrieve the Canvas (if you only need those APIs). In your sample code, the line actually causing the exception is EventHandler.getTarget() because it tries to cast the StatefulCanvas created in the previous line to a child class type.

    Comment

    Working...
    X