I’m trying to do access control the old fashion. If a user is in the session, go to a specif page. On page reload it should take to the designated page as well. I’m attempting to do so the following way but failed. What am I doing wrong? any help will be greatly appreciated.
package org.example.test;
import com.vaadin.navigator.Navigator;
import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
import com.vaadin.server.*;
import com.vaadin.ui.Label;
import com.vaadin.ui.Panel;
import com.vaadin.ui.UI;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author mhossain_c
*/
public class NavigatorTest extends UI
{
Navigator navigator;
public enum Views
{
TEST, ANOTHER
};
@Override
protected void init(VaadinRequest request)
{
Panel mainPanel = new Panel();
mainPanel.setSizeFull();
setContent(mainPanel);
// Trying to load the second page if a session already exists
// For actual app, this would if there are any user stored
if (VaadinSession.getCurrent().getAttribute(Navigator.class) != null)
{
VaadinSession.getCurrent().getAttribute(Navigator.class).
navigateTo(Views.ANOTHER.name());
}
else
{
navigator = new Navigator(this, mainPanel);
navigator.addView(Views.TEST.name(), new Test());
navigator.addView(Views.ANOTHER.name(), new Another());
navigator.navigateTo(Views.TEST.name());
VaadinSession.getCurrent().setAttribute(Navigator.class, navigator);
}
}
}
class Test extends Panel implements View
{
@Override
public void enter(ViewChangeEvent event)
{
//Do nothing
}
public Test()
{
Label label = new Label("This should be displayed first time app load");
setContent(label);
}
}
class Another extends Panel implements View
{
@Override
public void enter(ViewChangeEvent event)
{
//Do nothing
}
public Another()
{
Label label = new Label("If navigator already exists in the session "
+ ", upon reload this should be displayed");
setContent(label);
}
}