Win a copy of Java Challengers this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

dynamic handling of stylesheets

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
i want to implement a feature which would enable the end user to choose a different skin for a particular page. How should i do this?
 
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Personally, I'd go with a dropdown box.
 
author and iconoclast
Posts: 24203
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'll guess this is a JSP question, based on his past posting history. Off we go to the JSP forum.
 
Sheriff
Posts: 67528
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What version of JSP are you using? Or are you using JSP at all?
 
Bear Bibeault
Sheriff
Posts: 67528
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A simple JSP 2.0 implementation:

Set up your web app such that you have a folder structure (relative to the context root) like so:



where skin-name is the name of each of your "skins" (or "themes" as I usually call them). The stylesheets and images for each separate theme would go in their respective folders.

Call one "default" which is used when no specific skin is specified.

Now, since the current "skin" is specific to a user, store the skin name in the session as a scoped variable named 'skinName'.

On page, do something like:



Of course you would have to do the same for each stylesheet. And you'd need to adjust the URL of any images likewsie.

The approach I've actually used is along the lines of the above, but keeps the goo off the pages by setting up a small custom tag library which includes replacement tags for images and stylesheets (as well as for Javascript files in case they change theme to theme) that adjusts the URLs to the resources as approriate to the value of the current skin for the user. (The tags are also smart enough to pick up any missing resources from the 'default' theme so that resources that don't change across themes don't need to be copied -- but that's frosting).
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic