A skin refers to a user interface's appearance; it gives a Web application a different look and feel. A skin changes the way the user interface appears when a user clicks a button, but does not change the UI's behavior. A change in the skin thus results in a change to an application's appearance, but to achieve that modification, your Web application must know how to use a skin.
Why should you skin a Web application in the first place? Well, there are several motives for using skins, but certainly they are not always a must. In a simple application, skinning it would be overkill, but in some situations, as described in the list below, you must deal with skins:
Skinning a Web application is not an easy task. You can use Cascading Style Sheets and change an image's path, but you are limited to what you can do with CSS. If you have a component that looks completely different in each skin, that is, if the HTML differs in each skin, CSS won't help you. However, you could use CSS if simply changing styles solves your problem.
A good approach to creating a skin is to determine each piece of the user interface and generalize these pieces to apply an
appearance to each one. For example, if, in Skin A, you have a frame component that is just a plain table and, in Skin B,
a more complex table with headers, footers, images, and even sounds, different HTML (more <tr> and <td> tages) should be generated for each skin's frame. As an example, let's suppose that in Skin A, the HTML that must be generated
to render a label is:
<p>This is my Label</p>
Now, in Skin B, this is how a label would be rendered:
<table background="/images/tablebg.gif">
<tr>
<td bgcolor="#0000FF">
</td>
<td background="/images/cellbg.gif">
This is my Label
</td>
<td bgcolor="#0000FF">
</td>
</tr>
</table>
As you can see, these two pieces of UI differ completely in each skin. They both have the same information (This is my Label), but are rendered with different HTML tags. This functionality couldn't be achieved with CSS alone. Perhaps using Extensible
Stylesheet Language Transformations or XSL could be an option. Or you could use Xkins.
Xkins is a framework that manages skins for your Web application. In the early server-side Java days, you hard-coded HTML into a servlet. Then, JSP (JavaServer Pages) came along to allow you to put your HTML outside Java code. Nowadays, we have the same problem with taglibs that have HTML tags hard-coded in Java code. Using Xkins, you can place HTML outside your code with an additional and powerful feature: skins. For a detailed information about Xkins, visit Xkins's homepage.
Figure 1 illustrates Xkins's role in a Web application.

Figure 1. Xkins's role in a Web application
A Web application that uses Xkins and Struts through taglibs follows this request lifecycle:
XkinProcessor.
XkinProcessor gets the user's skin and the template that the taglib commands to render.
XkinProcessor uses the TemplateProcessor associated with the template.
TemplateProcessor is the class responsible for rendering the UI piece that composes the skin. The TemplateProcessor could use Velocity, JBYTE (Java By Template Engine), Groovy, or other template engine to render the output.
TemplateProcessor uses the resources from the skin (elements and paths) and returns the result of the template processing to the taglib.
Xkins addresses skin management by following these basic concepts:
One important benefit Xkins offers is that all HTML is in one place, and, if you need to tune it, you just simply change the templates. For instance, if your pages are too big, detect where the excessive HTML generation is or decide what images could be stripped, and then change the templates to reduce page size. You could also have a lightweight skin for those users accessing your Web application with low-speed connections and a richer skin UI for broadband users.
Archived Discussions (Read only)