logout functionality not working

Hi,

i am working with vaadin 7 version, i have implemented logout functionality as below.

logout = new Button(“Logout”, new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
// Close the VaadinServiceSession
getUI().getSession().close();
// Invalidate underlying session instead if login info is stored there
VaadinService.getCurrentRequest().getWrappedSession().invalidate();

            getUI().close();

            // Redirect to avoid keeping the removed UI open in the browser
            getUI().getPage().setLocation(LoginView.NAME);

the above code is working fine but, once the user logs out then if user pressed the back arrow from the browser its going to my application, i wanted to restrict it, any help ?

This is all my code is doing:

    SMSession.INSTANCE.setLoggedInUser(null); // this just clears out a session attribute which holds the current user.
    getUI().getSession().close();
    getUI().getPage().setLocation( "/scoutmaster/" );

that is:

public void setLoggedInUser(User user)
    {
        UI.getCurrent().getSession().setAttribute(USER, user);
        
    }

My UI class then does this:

    //
        // We use a view change handler to ensure the user is always redirected
        // to the login view if the user is not logged in.
        //
        getNavigator().addViewChangeListener(new ViewChangeListener()
        {
            private static final long serialVersionUID = 1L;

            @Override
            public boolean beforeViewChange(ViewChangeEvent event)
            {

                // Check if a user has logged in
                boolean isLoggedIn = getSession().getAttribute("user") != null;
                boolean isLoginView = event.getNewView() instanceof LoginView;
                boolean isForgottenPasswordView = event.getNewView() instanceof ForgottenPasswordView;
                boolean isResetPasswordView = event.getNewView() instanceof ResetPasswordView;

                // TODO: should we cache this?
                // during dev its easier if we don't.
                UserDao daoUser = new DaoFactory().getUserDao();
                long userCount = daoUser.getCount();

                if (userCount == 0)
                {
                    // Deal with recursion. When we navigateTo the setupwizard
                    // it comes back through
                    // beforeViewChange so we have to check that aren't aready
                    // on our way to the
                    // setupview.
                    if (event.getNewView() instanceof SetupWizardView)
                        return true;
                    else
                    {
                        // Must be a first time login so lets go and run the
                        // setup wizard.
                        getNavigator().navigateTo(SetupWizardView.NAME);
                        return false;
                    }
                }

                if (!isLoggedIn && !isLoginView && !isForgottenPasswordView && !isResetPasswordView)
                {
                    // Redirect to login view always if a user has not yet
                    // logged in
                    getNavigator().navigateTo(LoginView.NAME);
                    return false;

                }
                else if (isForgottenPasswordView)
                {
                    return true;
                }
                else if (isLoggedIn && isLoginView)
                {
                    // If someone tries to access to login view while logged in,
                    // then cancel
                    return false;
                }
                else if (isLoggedIn)
                {
                    // check if the menu bar has been added and if not then add
                    // it.
                    if (NavigatorUI.this.menubar == null)
                    {
                        NavigatorUI.this.menubar = new MenuBuilder(navigator, viewMap).build();
                        NavigatorUI.this.menubar.setWidth("100%");
                        mainLayout.addComponentAsFirst(menubar);

                        mainLayout.addComponentAsFirst(menubar);

                    }
                }

                return true;
            }

            @Override
            public void afterViewChange(ViewChangeEvent event)
            {
                // For some reason the page title is set to null after each
                // navigation transition.
                getPage().setTitle("Scoutmaster");
            }
        });

    }

Hope that is some help.

thanks for your Brett!..

let me implement same way which you adviced…

typo mistake!..

thanks Brett!..