I don't at present use any taglibs whatsoever in the app I'm doing this in, so I don't know if there is any added complexity involved there. But as far as what I AM doing goes, I'm not sure what will really be helpful, so let me get as detailed as I can and you can ignore the superfolous parts...

First, the application I'm doing this in allows users to set their own color scheme, font scheme, and some other style elements (within a defined set of things they can possibly change). So, I have a UserScheme table with columns like BackgroundColor, FontSize, TextColor, etc.

So, in each JSP I have the line:

<link rel="StyleSheet" href="/app/styles.act" type="text/css">

This is mapped to an Action called StylesAction. All it does is reads in all the columns from the above table for the current user. I then dump all those values into a HashMap (I simply key it off the column name in the table).

Next, in the styles.jsp, I do things like this:

<% HashMap styleData = (HashMap)request.get("styleData"); %>
.cssMainBody {
 background-color : <%=(String)styleData.get("backgroundColor")%>;
 color : <%=(String)styleData.get("textColor")%>;
 font-family : <%=(String)styleData.get("fontFamily")%>;
 font-size : <%=(String)styleData.get("fontSize")%>;
 font-weight : <%=(String)styleData.get("fontWeight")%>;
}

...and so on. Then, I just use those style classes in my other JSP's like I would any other style tag (I always do className="xxx" where xxx is the classname like cssMainBody above).

That's all there is to it. Without knowing more about the taglibs your using I can't really say if this will work as-is or not, but it certainly works were taglibs are not involved. Hope that helps!

Frank

From: "Voinea, Marina" <[EMAIL PROTECTED]>
Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
Subject: RE: How to use dynamically generated CSS style with Struts tags
Date: Wed, 23 Jun 2004 10:06:32 -0400


Thank you very much for your answer, Frank,This is the second time you come to my help!


I don't want to seem lazy, but could you please give an example from the code...
(the style sheet jsp and an example of a tag , for ex: html:text or anything else which is using the info from the syle sheet : do you use JSTL or Struts tags are enough?
(
(I am curious how you pass info from the jsp stylesheet to the style and styleCLass attibutes of the STruts html tag....


I am just starting this, so I am sure I'll benefit from your proven experience...(instead of fighting my mistakes for a couple of days)


ALso, regarding performance: do you think there is a significant performance hit to generate the styles inline in the tags (there are some concerns here...), as opposed to using a style sheet file (generated/refreshed from time to time and maybe cashed in the browser...). The tags are dynamically generated anyway, so I'm thinking additional style at run time may not be that bad, what do you think? Did you do any comparisons/benchmarks?



Thank you very much, Marina

-----Original Message-----
From: Frank Zammetti [mailto:[EMAIL PROTECTED]
Sent: Tuesday, June 22, 2004 1:53 PM
To: [EMAIL PROTECTED]
Subject: Re: How to use dynamically generated CSS style with Struts tags


I had to do something almost identical... My solution was to make my CSS file a JSP, and when I referenced that stylesheet in all the other JSP's, I did:


where styles.act is actually an ActionMapping. I then had my StylesAction class, just like any other Action, that got some info out of the database and passed it along to the JSP, then I just used all the normal JSP/taglib functionality to dynamically build the CSS content.

Frank

>From: Bill Siggelkow <[EMAIL PROTECTED]>
>Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
>To: [EMAIL PROTECTED]
>Subject: Re: How to use dynamically generated CSS style with Struts tags
>Date: Tue, 22 Jun 2004 13:28:47 -0400
>
>Sounds like a custom JSP tag would work pretty well here ...
>
>Voinea, Marina wrote:
>
>>
>>Hi everybody,
>>Can you please help with the following question:
>>
>> What are the possible ways (and best) to modify the style sheet at run
>>time using Struts framework?
>> Our application is using Struts tags which refer to a static style
>>sheet elements as presented below:
>>
>> <html-el:link styleClass="<%=style%>" ....
>>
>> We need at run time to extract user settings from DB (fonts, colors) and
>>generate a style sheet accordingly .
>> We could generate the style sheet text file for the user and store it
>>somewhere on the disk and then refer to it, but then we may have too many
>>files (for all active users). There must be a more dynamic and elegant
>>soultion...
>> Can we use the Struts html:link and pass a String to the "style"
>>attribute of the html:link of the tag ? (It would be good for this string
>>to be extracted from a bean prepared by an action....).
>>
>> Any example of XSL taglib and Struts tag integration ? This is a very
>>important element for trully dynamic pages ... Any good experience that we
>>can learn from?
>>
>>
>> Thank you very much,
>> Marina
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>


_________________________________________________________________
MSN Movies - Trailers, showtimes, DVD's, and the latest news from Hollywood!
http://movies.msn.click-url.com/go/onm00200509ave/direct/01/



--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]


_________________________________________________________________
MSN 9 Dial-up Internet Access fights spam and pop-ups – now 3 months FREE! http://join.msn.click-url.com/go/onm00200361ave/direct/01/



--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to