Example usage for com.vaadin.server VaadinResponse setCacheTime

List of usage examples for com.vaadin.server VaadinResponse setCacheTime

Introduction

In this page you can find the example usage for com.vaadin.server VaadinResponse setCacheTime.

Prototype

public void setCacheTime(long milliseconds);

Source Link

Document

Sets cache time in milliseconds, -1 means no cache at all.

Usage

From source file:com.ejt.vaadin.loginform.LoginForm.java

License:Apache License

private void init() {
    if (initialized) {
        return;/*  w  ww  .  ja va2 s . com*/
    }

    LoginFormState state = getState();
    state.userNameFieldConnector = createUserNameField();
    state.passwordFieldConnector = createPasswordField();
    state.loginButtonConnector = createLoginButton();

    String contextPath = VaadinService.getCurrentRequest().getContextPath();
    if (contextPath.endsWith("/")) {
        contextPath = contextPath.substring(0, contextPath.length() - 1);
    }
    state.contextPath = contextPath;

    VaadinSession.getCurrent().addRequestHandler(new RequestHandler() {
        @Override
        public boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response)
                throws IOException {
            if (LoginFormConnector.LOGIN_URL.equals(request.getPathInfo())) {
                response.setContentType("text/html; charset=utf-8");
                response.setCacheTime(-1);
                PrintWriter writer = response.getWriter();
                writer.append("<html>Success</html>");
                return true;
            } else {
                return false;
            }
        }
    });

    registerRpc(new LoginFormRpc() {
        @Override
        public void submitCompleted() {
            login();
        }
    });

    initialized = true;

    setContent(createContent(getUserNameField(), getPasswordField(), getLoginButton()));
}