Search code examples
javavaadinvaadin7

Setting context-parameters programatically when using vaadin-cdi


I annotated my UIs with @CDIUI and dont use web.xml for the binding. But how can I set context-parameters like debugMode, heartbeatIntervall, closeIdleSessions ... ? Is there a way to annotated those features or pass them inside the UI instance? Or do I have to provide a web.xml anyway? What about System.getProperty (the JBoss property handling)? Thanks for any clue.


Solution

  • Try to implement your own DeploymentConfiguration in the following way:

    public class ExampleUI extends UI {
        private class ExampleConfiguration implements DeploymentConfiguration {
            @Override
            public int getHeartbeatInterval() {
                return 30;
            }
    
            @Override
            public boolean isCloseIdleSessions() {
                return true;
            }
        }
    
        @Override
        protected void init(VaadinRequest request) {
            getSession().setConfiguration(new ExampleConfiguration());
            ...
        }
    }
    

    Then you can get context parameters outside ExampleUI class in a standard way:

    VaadinSession.getCurrent().getConfiguration().getHeartbeatInterval();
    VaadinSession.getCurrent().getConfiguration().isCloseIdleSessions();
    

    I hope this helps.