GWTP
GWTP copied to clipboard
Can't render NestedSlot inside another PermanentSlot
I'm going through this the whole day but I can't find the issue and GWTP is not giving any form of information back about what could be the problem. I'll just post here the content of my stackoverflow question. Whatever the problem is here.. the issue imho is that I'm not getting any hint on what is the actual problem.
Short summary:
I try to update a navigation bar after a place change event. To do so I created a GWTP Test*.java
that I try to render in a SLOT_NavBar
. However, this is not working. In order to see if I did something wrong I just made itself render in my SLOT_AdminToolMainContent
slot which is working perfectly fine. The question is why I can render TestView
in one slot but not in the other. GWTP is not giving me any clues about what I'm doing wrong here and I can't find anything in the documention that would help me out here.
I'm sure the problem must be either a misunderstanding from my side or something really stupid that I'm doing but I just fail to see the reason why this is not working.
I'm having here a "root" presenter:
AdminToolPresenter
public class AdminToolPresenter extends Presenter<AdminToolPresenter.MyView, AdminToolPresenter.MyProxy> {
public interface MyView extends View {
}
@ProxyStandard
@NameToken(AdminNameTokens.adminTool)
@UseGatekeeper(AdminGatekeeper.class)
public interface MyProxy extends ProxyPlace<AdminToolPresenter> {
}
/** */
public static final PermanentSlot<MenuPresenter> SLOT_Menu = new PermanentSlot<>();
/** */
public static final NestedSlot SLOT_AdminToolMainContent = new NestedSlot();
/** */
private MenuPresenter menuPresenter;
@Inject
public AdminToolPresenter(EventBus eventBus, MyView view, MyProxy proxy, MenuPresenter menuPresenter) {
super(eventBus, view, proxy, RevealType.RootLayout);
this.menuPresenter = menuPresenter;
}
@Override
protected void onBind() {
this.setInSlot(SLOT_Menu, this.menuPresenter);
}
@Override
protected void onReveal() {
LOGGER.fine("AdminToolPresenter.onReveal()");
}
}
and its view:
AdminToolView
public class AdminToolView extends ViewImpl implements AdminToolPresenter.MyView {
@SuppressWarnings("unused")
private final static Logger LOGGER = Logger.getLogger(AdminToolView.class.getName());
public interface Binder extends UiBinder<Widget, AdminToolView> {
}
@UiField HTMLPanel menuPanel;
@UiField SimplePanel adminMainContent;
@Inject
public AdminToolView(Binder uiBinder) {
this.initWidget(uiBinder.createAndBindUi(this));
this.bindSlot(AdminToolPresenter.SLOT_Menu, this.menuPanel);
this.bindSlot(AdminToolPresenter.SLOT_AdminToolMainContent, this.adminMainContent);
}
}
Everything I'm doing with this is working just fine for example:
TestPresenter
public class TestPresenter extends Presenter<TestPresenter.MyView, TestPresenter.MyProxy> implements TestUiHandlers {
private final static Logger LOGGER = Logger.getLogger(TestPresenter.class.getName());
interface MyView extends View , HasUiHandlers<TestUiHandlers> {
}
public static final Type<RevealContentHandler<?>> SLOT_Test = new Type<RevealContentHandler<?>>();
@NameToken(AdminNameTokens.test)
@ProxyStandard
interface MyProxy extends ProxyPlace<TestPresenter> {
}
@Inject
TestPresenter(EventBus eventBus, MyView view, MyProxy proxy) {
super(eventBus, view, proxy, AdminToolPresenter.SLOT_AdminToolMainContent);
this.getView().setUiHandlers(this);
}
@Override
public void prepareFromRequest(PlaceRequest request) {
LOGGER.severe("prepareFromRequest");
super.prepareFromRequest(request);
}
}
No problem at all! However, if I try to bind this to another slot:
@Inject
TestPresenter(EventBus eventBus, MyView view, MyProxy proxy) {
// MenuPresenter.SLOT_NavBar instead of AdminToolPresenter.SLOT_AdminToolMainContent
super(eventBus, view, proxy, MenuPresenter.SLOT_NavBar);
this.getView().setUiHandlers(this);
}
Then it's simply doing nothing! I only changed the slot - so why is this not working? Here is the MenuPresenter
and related code:
MenuPresenter
public class MenuPresenter extends PresenterWidget<MenuPresenter.MyView> implements MenuUiHandlers {
private final static Logger LOGGER = Logger.getLogger(MenuPresenter.class.getName());
interface MyView extends View, HasUiHandlers<MenuUiHandlers> {
}
/** Slot for the navigation bar. */
public static final NestedSlot SLOT_NavBar = new NestedSlot();
@Inject
MenuPresenter(EventBus eventBus, MyView view) {
super(eventBus, view);
this.getView().setUiHandlers(this);
}
@Override
protected void onReveal() {
LOGGER.severe("onReveal()");
}
}
MenuView
class MenuView extends ViewWithUiHandlers<MenuUiHandlers> implements MenuPresenter.MyView {
interface Binder extends UiBinder<Widget, MenuView> {
}
@UiField HTMLPanel navBarPanel;
@UiField MaterialSideNav sideNav;
private PlaceManager placeManager;
@Inject MenuView(Binder uiBinder, PlaceManager placeManager) {
this.initWidget(uiBinder.createAndBindUi(this));
this.bindSlot(MenuPresenter.SLOT_NavBar, this.navBarPanel);
this.placeManager = placeManager;
}
}
Please explain to me why this is not working - it is driving me nuts. I'm not getting anything from GWTP like "dude, you're trying to do something strange here". No warning, error or info. Just nothing and I don't see what I do wrong here!
From what I can see from your code, you're trying to reveal the TestPresenter
from the MenuPresenter
which is a PresenterWidget. You can't do that. It should be the other way around. I suppose what you really want to do is to nest the MenuPresenter
inside the TestPresenter
. If that is the case, you need to inject MenuPresenter
in TestPresenter
and call TestPresenter.setInSlot(<your_slot>, <your_presenter>)
. Take a look at this article on Typed Slots
and let me know if you still have problems!