PresenterWidget removeFromSlot 失败
PresenterWidget removeFromSlot fails
当尝试从插槽中删除 presenterWidget 时,class 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 class:
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
问题是为了确定 slot 和 child.slot 是否相等,GWTP 实现使用直接比较,这意味着对象引用必须相等。在 GWT 2.7 和 GWTP 1.4 中,您可以将字符串作为插槽发送,例如 removeFromSlot("SOME_SLOT", widget)
,这会起作用,因为 mthod 是 removeFromSlot(Object object, PresenterWidget w)
。
在新版本中,此方法已被弃用,必须将 Slot 对象传递给方法...因为我没有保存这些 Slot 对象,而是让它们在运行时通过小部件 ID removeFromSlot 创建() 插槽比较失败。
解决方案是在使用方法 setInslot()
创建小部件时保存插槽引用,或者可能已经有检索小部件插槽的方法...
一般来说,使用==
来比较对象是不可取的。如果改用 equals()
,解决我的问题会很容易。
当尝试从插槽中删除 presenterWidget 时,class 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 class:
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
问题是为了确定 slot 和 child.slot 是否相等,GWTP 实现使用直接比较,这意味着对象引用必须相等。在 GWT 2.7 和 GWTP 1.4 中,您可以将字符串作为插槽发送,例如 removeFromSlot("SOME_SLOT", widget)
,这会起作用,因为 mthod 是 removeFromSlot(Object object, PresenterWidget w)
。
在新版本中,此方法已被弃用,必须将 Slot 对象传递给方法...因为我没有保存这些 Slot 对象,而是让它们在运行时通过小部件 ID removeFromSlot 创建() 插槽比较失败。
解决方案是在使用方法 setInslot()
创建小部件时保存插槽引用,或者可能已经有检索小部件插槽的方法...
一般来说,使用==
来比较对象是不可取的。如果改用 equals()
,解决我的问题会很容易。