开发者

Remove widget from GWT FlowPanel

开发者 https://www.devze.com 2023-02-03 20:25 出处:网络
I have the below class for managing the content I display based on the menu item the user selects. I am having an issue where it is not removing the previous widget. I have checked the widget exists i

I have the below class for managing the content I display based on the menu item the user selects. I am having an issue where it is not removing the previous widget. I have checked the widget exists in the Panel by using getWidgetIndex, and I have tried removing the widget using the object and the index with no success.

When I try the remove I get an exception which is also included below. Ideas?

public class BaseContentHandler implements ClickHandler{

    private Content item;

    public BaseContentHandler(Content content){
        this.item = content;
    }

    @Override
    public void onClick(ClickEvent event) {


        if(currentWidget != null){
            contentPanel.remove(contentPanel.getWidgetIndex(currentWidget)/*currentWidget*/);    
        }
        currentWidget = this.item;
        contentPanel.add(this.item);

    }

}

Exception:(TypeError): d is null stack: Bwb

Other suggestions are also welcome.开发者_Python百科

James


You might be better off using .hide() on currentWidget and .show() on this.item, keeping them all in the panel, rather than dynamically inserting and deleting them.


Something is missing in the code snippet you posted - where is contentPanel defined?

I guess the only possible point for the NPE is this line: contentPanel.remove(contentPanel.getWidgetIndex(currentWidget)/currentWidget/);

It seems that the exception you described is from a javascript tool, since "d" is a javascript object as a result of the GWT compilation. To get a more detailed info from the javascript level you should compile your GWT project in Detailed mode:

  1. Click on "Compile GWT project" icon (in Eclipse).
  2. Select "Output Style" - Detailed and compile.
  3. Run again your project and you'll get the same exception but the name will tell you what is the Java object you use and what is the original line in your java code that the exception has occurred.
0

精彩评论

暂无评论...
验证码 换一张
取 消