Question

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.

Was it helpful?

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.

OTHER TIPS

While the solution proposed by wypieprz works as far as manually retrieving context parameters in your application, it doesn't actually work all the way.

In particular the setConfiguration() happens too late for Vaadin to actually use the the configured heartbeat interval etc. Below is a way I got it to work. Basically it's the solution found here but with an additional @WebInitParam to get CDI to bootstrap properly again in the presence of an inline servlet configuration.

@WebServlet(value = { "/*", "/VAADIN/*"
            initParams = {
                @WebInitParam(name = Constants.SERVLET_PARAMETER_UI_PROVIDER, value = "com.vaadin.cdi.CDIUIProvider")
            })
@VaadinServletConfiguration(productionMode = false,
                            ui = MyVaadinUI.class,
                            closeIdleSessions = true,
                            heartbeatInterval = 10)
public static class Servlet extends VaadinServlet
{
}

Also, those parameters could be set in a properties file

vaadin.servlet.productionMode=true
vaadin.servlet.heartbeatInterval=55
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top