PresenterWidget removeFromSlot失败

时间:2017-12-08 09:30:15

标签: java gwt gwtp

当尝试从插槽中删除p​​resenterWidget时,类PresenterWidget方法rawRemoveFromSlot()中的比较失败并且getView()。removeFromSlot()未被调用。

〔实施例:

//this is called from my presenter
//widget here is an extension of PresenterWidget
WidgetSlot removeSlot = new WidgetSlot("widget" + widget.getId());
removeFromSlot(removeSlot, widget);

WidgetSlot类:

public class WidgetSlot<T extends PresenterWidget<?>> extends Slot<T> {

    private Object identifier;

    public WidgetSlot(Object identifier) {
        super();
        this.identifier = identifier;
    }

    public Object getIdentifier() {
        return identifier;
    }
}

使用浏览器调试客户端代码时:

public abstract class PresenterWidget <> {
   ...
    //this method is called
    private void rawRemoveFromSlot(IsSlot<?> slot, PresenterWidget<?> child) {
        if (child != null && child.slot == slot) { <!-- this fails because child.slot is not equal to slot even though they are...
            if (!child.isPopup()) {
                this.getView().removeFromSlot(slot.getRawSlot(), child);
            }

            child.orphan();
        }
    }
   ...
}
方法中的

slot(从浏览器调试器复制):

slot_0_g$: bZy_g$
    identifier_2_g$: "widget1" 
方法中的

child.slot(从浏览器调试器复制):

slot_3_g$: bZy_g$
    identifier_2_g$: "widget1"

除非我误解调试器信息,否则两个插槽似乎相等?方法中的插槽比较失败的唯一方法是插槽对象具有不同的引用。

有什么想法吗?

GWT版本:2.8.2

GWTP版本:1.6

1 个答案:

答案 0 :(得分:0)

问题是确定slot和child.slot是否相等,GWTP实现使用直接比较,意味着对象引用必须相等。在GWT 2.7和GWTP 1.4中,您可以将字符串作为插槽发送,如removeFromSlot("SOME_SLOT", widget),这样可以使用,因为mthod是removeFromSlot(Object object, PresenterWidget w)

对于新版本,不推荐使用此方法,而且必须将Slot对象传递给方法...而且由于我没有保存这些Slot对象,而是通过widget ID在运行时创建它们,removeFromSlot ()槽比较失败。

解决方案是在使用方法setInslot()创建窗口小部件时保存插槽引用,或者可能已经有方法检索窗口小部件插槽...

通常使用==来比较对象是不可取的。如果使用equals(),那么解决我的问题会很容易。