Hi! I'm building an application whose menus depend on user roles. Once user is logged in and, therefore, her roles are known, I want to create the Hyperlinks related to the user and add them to the menu. I'm using MVP. Here's my code for the presenter:
public class AdminMenuAreaPresenter extends WidgetPresenter<AdminMenuAreaPresenter.Display>
{
public interface Display extends WidgetDisplay{
public void addLink(String link);
}
private DispatchAsync dispatcher;
private SessionManager sessionManager;
@Inject
public AdminMenuAreaPresenter(AdminMenuAreaPresenter.Display display, EventBus bus, DispatchAsync dispatcher, SessionManager sessionManager){
super(display, bus);
this.dispatcher = dispatcher;
this.sessionManager = sessionManager;
this.bind();
}
@Override
protected void onBind() {
super.onBind();
registerHandler(eventBus.addHandler(LoginEvent.TYPE,
new LoginEventHandler() {
@Override
public void onLogin(LoginEvent event) {
display.addLink("register user");
}
}));
}
@Override
protected void onUnbind() {
// TODO Auto-generated method stub
}
@Override
protected void onRevealDisplay() {
// TODO Auto-generated method stub
}
}
And here's the View:
public class AdminMenuAreaView extends Composite implements AdminMenuAreaPresenter.Display{
private VerticalPanel vPanel;
private Hyperlink registerUserLink;
public AdminMenuAreaView(){
vPanel = new VerticalPanel();
initWidget(vPanel);
}
@Override
public Widget asWidget() {
return this;
}
public void addLink(String s){
registerUserLink = new Hyperlink(s, "this is new target");
this.vPanel.add(registerUserLink);
registerUserLink.setVisible(true);
}
public HasClickHandlers getRegisterUserLink(){
return registerUserLink;
}
What am I doing wrong?
Flow program goes throgh the addLink()
method, but nothing is added to the view either dom document.
Thank you.