Themed by url

Hi, I would like to ask if / how Vaadin 7 could be used to accomplish the following:

I have 2 website domains - and

I want these to both forward to the same web application. This I can do fine through the Web Server.

But I want this one application to display using ‘theme A’ when it is accessed by and using ‘theme B’ when it is accessed by

Is this possible? And if so how would I go about it?

Note that the theme does not have to change at any other time.


Should be simple enough. Implement
and store the current request in a ThreadLocal (calls to onRequestStart aren’t serialized in the same way as business calls to the Application object are). So your application would include:

    private static final ThreadLocal<HttpServletRequest> tlRequest =
        new ThreadLocal<HttpServletRequest>();

    public void onRequestStart(HttpServletRequest req, HttpServletResponse resp) {

    public void onRequestEnd(HttpServletRequest req, HttpServletResponse resp) {

Now in your init() method grab the request and call
, or something similar to get the URL that was used to access the application. Then you can call setTheme() from there to set the correct theme.


Sorry, no setTheme() for Vaadin 7…


The Theme is determined in UIProvider#getTheme(). Via the overgiven UIProviderCreateEvent you can get the VaadinRequest. which can be casted to VaadinServletRequest. From there you can get the HttpServletRequest using the appropriate Getter. That Object you can ask for the Servername as Bobby already pointed out and return a matching Theme afterwards.

Using a custom UIProvider is just as easy as using an own UI, just link it in your web.xml.

Some day I’ll get to try out 7! :slight_smile:

Thanks, Tobias, for filling in the gaps.