Navigator related problem

Hi

This is Mohan reddy. I have quite interesting use the vaadin application for my products. So I facing problem with navigator like in vaadin dashboard application is one of example. Problem is, once enter or sign in to dashboard it navigates to dashboard view page right. After that one refresh a page or application it navigates to login page. For this how to prevent the navigate to login so can you give the sample code or guide me in how to prevent the navigates to login page. Thanks

PFA.: Untitled.png,Untitled1.jpg,Untitled2.jpg
14117.jpg
14118.jpg
14119.jpg

You have to store in your Session information (e.g attribute) that current session is already authenticated.

Then in enter-Method of your view you can check this info and display the login depending on the information.

Hi Holger Lober

Can you check once the dashboard navigation please. It is not navigates the root layout, its navigates the content views only. In this case how to handle can you give the sample code. One case if session information is there or not does’t matter for the navigation so, once i enter the button of login to moves to dashbord so in that page i can refresh its navigates to login layout.In that case i need to prevent the navigation

In the Dashboard-Demo UI check for authentication:

@Override
    protected void init(VaadinRequest request) {
        getSession().setConverterFactory(new MyConverterFactory());
        helpManager = new HelpManager(this);
        setLocale(Locale.US);
        setContent(root);
        root.addStyleName("root");
        root.setSizeFull();
        // Unfortunate to use an actual widget here, but since CSS generated
        // elements can't be transitioned yet, we must
        Label bg = new Label();
        bg.setSizeUndefined();
        bg.addStyleName("login-bg");
        root.addComponent(bg);
        
        final Object auth = UI.getCurrent().getSession().getAttribute("authenticated");
        if(auth == null) {
            log.debug("Not authenticated yet");
            buildLoginView(false);  
        } else {
            final boolean ok = (Boolean)auth;
            if(!ok) {
                log.debug("Not authenticated yet");
                buildLoginView(false);
            } else {
                buildMainView();
            }
        }     
    }

And in the Login-check set your authentication info: signin.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { if (username.getValue() != null && username.getValue().equals("") && password.getValue() != null && password.getValue().equals("")) { signin.removeShortcutListener(enter); // Here we set the authentication info UI.getCurrent().getSession().setAttribute("authenticated",Boolean.TRUE); buildMainView(); } else { if (loginPanel.getComponentCount() > 2) { // Remove the previous error message loginPanel.removeComponent(loginPanel.getComponent(2)); } // Add new error message Label error = new Label( "Wrong username or password. <span>Hint: try empty values</span>", ContentMode.HTML); error.addStyleName("error"); error.setSizeUndefined(); error.addStyleName("light"); // Add animation error.addStyleName("v-animate-reveal"); loginPanel.addComponent(error); username.focus(); } } });

Hope it will be helpful and I understood what you want to do :wink:

Hi

Its working now. Session attribute is helpfull for nagivation so thanks to helping to me now it working, last 2 weeks onword I facing problem but now iam happy to move fast my code for my product. So thanks lober . Good job lober