Hi Peter,

I think you might have trouble with having too many JSP tags in the page if
you employed a scheme like that. Yes, it seems a little crazy, but we have
had trouble when a page has many JSP tags (Struts or otherwise) in it. The
server would throw a cryptic exception - class verify error or something
like that. But there are some alternatives...

One alternative that would be really easy to implement is to create a couple
of different style sheets; one for each of the different color schemes (or
"themes") you wanted to support. Then you could just store a single
preference value (the name of the style sheet) and use that to select one of
the style sheets.

STYLE SHEETS (3 different files):
=================================
apple-theme.css
---------------
tr.datarow     { background: #00FF00 }

orange-theme.css
----------------
tr.datarow     { background: #FF9900 }

seablue-theme.css
-----------------
tr.datarow     { background: #0066CC }


JSP PAGE:
=========
<head>
<LINK rel="stylesheet"
    href="<bean:write name="styleBean" property="styleSheetName">"
    type="text/css">
</head>

<table .... >
   <tr class="datarow">
    ...
   <tr>
</table>

So, that would be easy to do but would allow the user only to select a whole
"theme" rather than choosing colors for individual elements. I suspect that
more flexibility could be afforded by having more style sheets to represent
more combinations, or it seems likely to me that there is some CSS facility
that would help support such fine-grained preferences. I am not a CSS
expert, so I don't have any specific suggestions there.

Ultimately, I think you want to have named styles hardcoded into the HTML
tags and then dynamically select (by choosing which style sheet(s) to link
to, etc.) what attribute values get associated with those style names (e.g.
the name "datarow" could have a green, orange, or blue background depending
on the user's preference). This strategy also has the nice feature of
letting you postpone the implementation of personalization until you have
time to do it. With those future plans in mind, however, it would seem wise
to choose style names that represent the meaning of the style (e.g.
"altrow") rather than a particular style attribute value itself (e.g.
"lightgrayrow").

Stuff that isn't so great about my example:
- I didn't try it, so it might need tweaking -- in particular, the quoting
might be faulty (we had some messages on that today)
- You might want to store a symbolic name rather than the CSS filename
itself as the preference value, or at least avoid storing the context path
with the name in the database. For example, you might construct the name
like this:

  linkHREF = request.getContextPath() + "/styles/" + storedPrefValue +
".css";

which might evaluate to something like:

  /myApp/styles/apple-theme.css

Using a bean to store this value in the session (as opposed to just storing
the preference value itself) is probably a good idea if you wish to switch
to a more complicated scheme in the future. That way, you can add bean
attributes without disrupting the code that manages the bean itself.
Creating your own custom tag to write out the <link> tag(s) could be a
useful technique as well. Initially, you might just have the tag write out a
<link> tag with a hardcoded href value. Then, if you implement theme-based
personalization, you can rewrite the tag to look for the prefs bean in the
session and transform the attribute into an href value for the <link> (which
also avoids duplication of the transform code). And eventually, you might
need to write out several <link> and/or <style> tags to support the user's
preferences; your custom tag could get the preference values from the bean
in the session and write out these tags accordingly. And through this whole
progression, your JSPs could remain unchanged with their symbolic style
names and your custom <link>-writing tag in the HEAD.

I am not that familiar with CSS specifics or more established
personalization techniques, but I think I would try something like I have
described here. I welcome any feedback, especially from those that are
knowledgeable about such things.

-Max

----- Original Message -----
From: "Peter Pilgrim" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, September 07, 2001 3:48 AM
Subject: Personalisation Best Practice


>
> What is a good way of using Struts and personalisation ?
>
> I would like to write a JavaBean with some personalisation getter and
setter.
> It would probably pick up the details from the database
> I would like to write method to change the background colours of table
rows
> for example in a trading application in conjunction with HTML
> Cascading Style Sheet. Suppose I have in my external CSS
>
>
> .tr-apple:     { background: #00FF00 }
> .tr-orange:    { background: #FF9900 }
> .tr-seablue:   { background: #0066CC }
>
> In the my JSP I could have a StyleBean
>
> class StyleBean { ...
>      String tr_bgcolor = "tr-apple"; // DEFAULT setting
>      String getTableRowBackgroundHTML() {
>           return "background=\""+tr_bgcolor+"\" ";
>      }
>      String setTableRowBackground( String htmlColor ) {
>           this.tr_bgcolor = htmlColor;
>      }
> ... }
>
> In the JSP it self
>
> <table .... >
>     <tr  "<bean:write name="styleBean" property="tableRowBackgroundHTML"
>" >
>     ...
>    <tr>
> </table>
>
> Thoughts on this cheap and nasty __personalisation__ strategy.
>
> --
> Peter Pilgrim          |  |        ++44 (0)207-545-9923
>             .... \  \  ___   /  / ... .
>             -   ----  ( * )  ---   --
> _____________________________Cafe_Savannah,_San Antonio,Ibiza__
>
>
>
> --
>
> This e-mail may contain confidential and/or privileged information. If you
are not the intended recipient (or have received this e-mail in error)
please notify the sender immediately and destroy this e-mail. Any
unauthorized copying, disclosure or distribution of the material in this
e-mail is strictly forbidden.
>
>
>

Reply via email to