Hi,
I am using some vaadin themes in my application and give the user the availability to choose one of them.
Current theme name saved in cookies.
I can not use @Theme annotation for my UI class because Vaadin try to use that annotation theme name as default in bootstrap stage.
I have to create my custom VaadinCDIServletService (I am using vaadin-cdi) and override
getConfiguredTheme
method:
public class CustomVaadinCDIServlet extends VaadinCDIServlet {
@Override
protected VaadinServletService createServletService( DeploymentConfiguration deploymentConfiguration ) throws ServiceException {
final VaadinCDIServletService service = new VaadinCDIServletService(this, deploymentConfiguration) {
@Override
public String getConfiguredTheme( VaadinRequest request ) {
final String theme = Cookies.get( request, Constants.VAADIN_THEME_COOKIE_NAME );
return theme != null && Themes.contains( theme ) ? theme : Themes.VALO_facebook;
}
};
service.init();
return service;
}
}
It’s ugly code and, in my opinion, the best solution would be
@Theme( value="valo", themeCookieName=Constants.VAADIN_THEME_COOKIE_NAME )
where "
themeCookieName
" is annotation attribute contains the name for cookie with vaadin theme name.
Thanks,
Dmitry