views:

363

answers:

1

Hi

I am brand new to Spring web MVC. I am trying to create a simple 1 paged site that will check the users browser and display the current theme for that browser.

If its a mobile app, I need to allow the user a button to switch to the regular site.

Also the current theme for mobile and non-mobile is stored in a database, which includes the start date, end date and the theme name. The theme name is the folder where the theme's resources are located.

Being a beginner I have never used themeresolver.

Your help is much appreciated.

+1  A: 

ThemeResolver is reasonably straightforward to implement.

You won't be using the setThemeName() method, so have it throw an UnsupportedOperationException. Your resolveThemeName() method would:

  1. Get "User-Agent" request header and determine the appropriate theme.
  2. Run a DB query (you may want to cache this).
  3. Return theme name.

You'll then need to declare your implementation under 'themeResolver' name in your application context.

ChssPly76
Do you know where I can find an example of how to do this? Remember I'm a beginner.
tariqj
"Do this" means what exactly? I've described the process above; Spring source has a few predefined theme resolvers you can take a look at but they're not really doing much. If you have a particular issue you're having trouble with, please update your question and describe it; I'll be happy to help. It's way too generic as it is right now.
ChssPly76
Well, firstly, what beans do I need to put into my app-servlet.xml. Secondly will my class extend AbstractThemeResolver or extend SessionThemeResolver. Also since I only want the theme to be a directory location should I do this differently. Meaning in my jsp I already have the file name, but not the folder name.
tariqj
1) is in my answer above. 2) AbstractThemeResolver if you want to use default theme functionality; otherwise just implement ThemeResolver yourself. 3) Theme maps "keys" you're using in your view to actual resources. Resources can be in whatever directory location you want but you still need to define the theme itself which by default is done via resource bundle. See http://static.springsource.org/spring/docs/2.5.x/reference/mvc.html#mvc-themeresolver for details
ChssPly76