4

I read this article about dynamic CSS.

I would like to generate CSS based on db parameters.

Something similar to <link rel="stylesheet" href="mydynamicCss.ashx?cssCode=mainPage" type="text/css"/>

What is the best way to implement it in JSF?

I am using JSF2.0

3
  • 2
    An alternative way would be using EL in your css files, assuming you treat them as a resource (<h:outputStylesheet library="css" name="yourcss.css"/>). You can get the ExternalContext, for example, and try to do something with it. Although I can't figure out right now a way to get a paramter from the css file. Commented Jul 21, 2011 at 14:46
  • What is the advantage of using this ability? I don't have the CSS pre-defined I want to create it on the fly Commented Jul 21, 2011 at 16:18
  • oh, well. Then a Servlet is indeed the best option. If you want one per session, no problem. Just do this check in the Servlet. Commented Jul 21, 2011 at 16:25

2 Answers 2

2

I would rather use an extra servlet for this purpose, possibly something using velocity/freemarker or maybe there are existing libraries supporting css generation. The href link would be mapped to this servlet instead of JSF servlet. I haven't really seen a css taglib for JSF.

Sign up to request clarification or add additional context in comments.

4 Comments

However, I don't want this to occur each time that the page is loaded. only once per session
If you encoded your parameters in the URL, you could setup caching or answer with HTTP 304 Not modified. On the other hand these 2 template libraries are much faster than JSF so it would barely impact performance - assuming you do full page refreshes with header included.
I didn't understand your answer about HTTP 403
-1

I don't truly understand what you mean, but we create "dynamic" CSS by using conditions.

For instance

<a:repeat var="foo" value="#{foos}">
  <li class="#{foo % 2 == 0?'odd':'even'}">
   ....
</a:repeat>

1 Comment

No. I don't want to use it for each component. I want to generate the CSS dynamically

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.