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 - www.firstdomain.com and www.seconddomain.com

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 www.firstdomain.com and using ‘theme B’ when it is accessed by www.seconddomain.com.

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.

Thanks

Should be simple enough. Implement
HttpServletRequestListener
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>();

    @Override
    public void onRequestStart(HttpServletRequest req, HttpServletResponse resp) {
        tlRequest.set(req);
    }

    @Override
    public void onRequestEnd(HttpServletRequest req, HttpServletResponse resp) {
        tlRequest.remove();
    }

Now in your init() method grab the request and call
getRequestURL()
,
getServerName()
, 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.

Cheers,
Bobby

Sorry, no setTheme() for Vaadin 7…

greetings
RalfN

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.

Cheers,
Bobby