3

I have a web-app in Java, Spring, Struts 2 and Hibernate, that servers multiple clients. Each client with multiple users. To create a personal feel for each client, i would like to customize the header for each client. I'm using sitemesh as decorator, and am looking for tips or examples or someone who can point me in the right direction as to how to acomplish this in the best practice.

What would you think? Should i just code it direct in the header.jsp? Extracting the info about the logged in user and from that create a custom header by code? Or is there a more clever solution out there?

Thanks!

Update:

To further clearify what i want: Different properties-files for each client is not an option. We are looking at potentionally hundreds of clients. It needs to be database-driven. But thats the easy part. There is no problem storing the information in db and extracting it when needed.

What im trying to figure out is if there is some sort of standard way of doing this. Some sort of filter or Action that is run before the sitemesh decorator that will provide the decorator with the correct info?

user829237
  • 1,719
  • 8
  • 37
  • 61

2 Answers2

1

Struts2 provides application scope, for variables which are global to the application.

Load all the customer specific strings into #application scope (I would use spring to do this when the application starts up). From there referencing the strings would be pretty obvious: #application.greeting I don't like the idea of using an interceptor because there is nothing to intercept. I would say for what you are doing application scope is the perfect place. If it is a single client system I can see no reason why anything would be stored in application scope.

Aside: Tiles uses a different template paradigm than site mesh, and they have slightly different purposes. As such the two can be complimentary. Tiles relying on XML definitions can have it's definitions stored in a DB and is definitely less computationally intensive, however where there is interplay between different UI components... or disparate elements appearing on the page you need to use sitemesh. So for basic template needs tiles does everything and is quite easy to understand but say you wanted to make add a certain widget in the middle of the page which relies on JS which needs to be added to the header it would be tricky to do this in Tiles (although the obvious solution is to just roll the JS functionality into one JS file for all possible uses in a particular part of the site).

Asside 2: By using a view technology such as velocity or freemarker in conjunction with tiles it is conceivable to move the entire view layer into a database. I just thought I would mention that as for some maintenance issues that could be extremely beneficial.

Quaternion
  • 10,380
  • 6
  • 51
  • 102
  • Thanks, but it needs to be database-driven. Please look at my updated description. – user829237 May 08 '12 at 13:04
  • Re-wrote the answer. You would only want to load those strings only once (or make the re-loadable from an admin page but not every page in the whole application!) and it isn't a premature optimisation because it should be quite easy to do, and very easy to use. – Quaternion May 09 '12 at 00:44
  • Thank you again. I'm now well on my way to implementing this. I'm putting a HashMap in the context on startup. This is accessible in the jsp. Now i just need to get the correct Properties from the map by passing in the clientId. Im grasping in the dark here, so any tips on how to access correctly in jsp would be very helpful! – user829237 May 09 '12 at 14:01
  • Does each client have their own application server or is one application serving multiple clients? You should not need a map if each client is separate. – Quaternion May 11 '12 at 01:19
0

Sitemesh makes it's decisions about what decoration to use based upon the requested URL string, so unless you have a reference to the client in every url - either as part of the main url string or as a known parameter, then Sitemesh out of the box is not going to help.

This leaves a few possibilities to achieve what you want;

1) Write a filter that runs before Sitemesh that adds, for example, "&clientId="xx" to every incoming request.

2) Dive into the source code for Sitemesh & look for where Sitemesh finally makes it's decision about which decorators to use and override it. I've never tried this so I don't know how practical this might be.

3) Make the style sheet definition in your jsp pages an OGNL expression and provide that information in a base action class that all your actions extend. In this way you end up with (potentially) a different CSS file for each client and you provide your customisation via CSS.

Hope that this helps.

user497087
  • 1,561
  • 3
  • 24
  • 41