我有一个页面,其中包含边界布局和为边界布局的每个区域定义的插槽(例如,EAST、WEST、NORTH、CENTER…)。
我希望通过在页面上上面的两个插槽中显示演示程序小部件来重用它。我成功地在其中一个插槽上显示了演示程序小部件,但每当我试图在两个单独的插槽中添加演示程序小程序时,我都会收到以下错误:
Exception caught: notifyReveal() called on a visible Presenter!
有人能告诉我怎么做吗。
下面是我的代码。
HomeView.java
@UiField
ContentPanel centerPanel;
@UiField
ContentPanel westPanel;
@Override
public void setInSlot(Object slot, Widget content) {
if (slot == HomePresenter.SLOT_EAST) {
if (content != null) {
eastPanel.add(content);
}
} else if (slot == HomePresenter.SLOT_WEST) {
if (content != null) {
westPanel.add(content);
}
} else if (slot == HomePresenter.SLOT_CENTER) {
if (content != null) {
centerPanel.add(content);
}
} else {
super.setInSlot(slot, content);
}
}
@Override
public void addToSlot(Object slot, Widget content) {
if (slot == HomePresenter.SLOT_EAST) {
if (content != null) {
eastPanel.add(content);
}
} else if (slot == HomePresenter.SLOT_WEST) {
if (content != null) {
westPanel.add(content);
}
} else if (slot == HomePresenter.SLOT_CENTER) {
if (content != null) {
centerPanel.add(content);
}
} else {
super.addToSlot(slot, content);
}
}
HomePresenter.java:
public static final Object SLOT_WEST = new Object();
public static final Object SLOT_CENTER = new Object();
@Override
protected void revealInParent() {
RevealRootContentEvent.fire(this, this); //Getting error over here
}
@Override
protected void onReset() {
super.onReset();
setInSlot(SLOT_WEST, null);
setInSlot(SLOT_CENTER, null);
indirectProvider.get(new AsyncCallback<LeftPanelPresenter>() {
@Override
public void onSuccess(LeftPanelPresenter result) {
addToSlot(SLOT_WEST, result);
addToSlot(SLOT_CENTER, result);
}
@Override
public void onFailure(Throwable caught) {
// TODO Auto-generated method stub
System.out.println("Not added to the slot");
}
});
}
提供者的目的是为您想要放置的每个位置创建每个PresenterWidget
的新实例。
我认为用同一个result
对象调用addToSlot()
两次会导致错误,因为该实例已经公开。
您可以使用一个循环为每个插槽创建一个新实例:
// create an array of the slots
List<Object> slots = new ArrayList<Object>();
slots.add(SLOT_WEST);
slots.add(SLOT_CENTER);
// call provider.get() on each slot in turn
for(Object slot : slots)
{
indirectProvider.get(new AsyncCallback<LeftPanelPresenter>()
{
@Override
public void onSuccess(LeftPanelPresenter result)
{
addToSlot(slot, result);
}
@Override
public void onFailure(Throwable caught)
{
// TODO Auto-generated method stub
System.out.println("Not added to the slot");
}
});
}