2

I have a JSF 1.2 based Java web-application that is packaged as an EAR. It contains several JARs and one WAR that provides a web-UI as frontend. The WAR contains JSF pages (XHTML), CSS files and other web-resources like images. The build-system in use is maven 2 (multi-module project).

The goal is now to provide different "flavours" of the web-UI. Every flavour could have different style-sheets and different images but same functionality.

The question is, how could I do this without much code duplication/overhead. I guess I have to create several WAR modules (one for every flavour) and several EARs that depend on the different WARs. Disadvantage of this is that two more modules with all it's configuration have to be added for every flavour. All the JSF pages would have to be duplicated, which is really not nice (ok, providing the XHTMLs via a separate archive and using Maven's remote resources plugin to share remote resources could possibly help here).

  • Is the described setup the best solution to my problem or are there better ways?
  • Is there a way to change the style at runtime? I.e. provide the CSS-files and images as external resources?

Thanks in advance,
- martin

Martin Höller
  • 2,714
  • 26
  • 44
  • On possible approach could be a resource mapping servlet [like RichFaces 4 uses](http://rik-ansikter.blogspot.co.at/2012/02/re-routing-jsf-resource-requests-with.html). The resource mapper could be configured to load resources from external paths and provide it to the browser. – Martin Höller Nov 12 '14 at 09:12

1 Answers1

0

First of all, all your css should be externalized into file. Have different set of css pages for each theme. Lets say you have 2 pages in your app, home page and search page, and you want to have 2 themes red and blue, then you should have homeRed.css,searchRed.css and homeBlue.css and searchBlue.css.

Now about switching your themes at runtime, in dynamic web pages like JSPs, you can generate webpage depending on paramater value. Let's say colorStyle is your param name, then you can have JSP like

    <% if(colorStyle.equals("RED")){ %>
       <link rel="stylesheet" href="path/to/homeRed.css">
    <% } else { %>
        <link rel="stylesheet" href="path/to/homeBlue.css">
    <% } %>

You can read value of colorStyle from user or hardcode it in your app depending on your requirement.

Please note that above mentioned is very crude way of doing things in JSP which is not recommended these days, but as you are using JSF there must be provision for doing this in sophisticated manner.

*EDIT Update * In that case, what you want to do is doable by only 2 ways. Either maven configuration of source files or stanalone utility program to copy wanted files into folder of which you will create war. For maven configuration approach, you can select which set of files to include or exclude. for ref What's the "right" way to (temporarily) exclude sources from a maven build, and is there an easy way to do it from Eclipse?

Community
  • 1
  • 1
Pranalee
  • 3,389
  • 3
  • 22
  • 36
  • Sorry, but your answer doesn't help much. CSS directives are already in separate CSS-files, but I would have to include CSS-files and different images for all flavours into one WAR. That's not what I want. I want a WAR that includes only resources relevant for this flavour. Or if possible all the resources could be outside the WAR, but I guess that's difficult as they have to be provided to the browser. – Martin Höller Sep 13 '13 at 08:40
  • Your update suggests I build the WAR with different maven configurations, right? But that's not the maven way! I would get different artifacts depending on the used configuration. The build-process should be reproducible. So either I didn't get you right or this approach is a hack that would work but which I'm not going to use. – Martin Höller Sep 13 '13 at 11:23
  • Yes, I think these are hacky ways because I'm not sure if such requirement is supported as feature by any tool. – Pranalee Sep 13 '13 at 11:50