OpenTranqueraFramework Logo
Skin definition
Xkins Forms


This is a simple example using only Xkins. This means that this examples do not use Velocity, Struts or Xkins Forms. This example is just for show you how Xkins resources, paths and extensibility between Skins work. Xkin Components are show in Xkins Forms example

web.xml declaration

First, you must declare Xkins servlet in order to load Xkins. Xkins are loaded to ServletContext, so they are accesed from XkinProcessor facade.

Here we declare a default skin (invierno), configures configuration file and tell Xkins to monitor our definition changes in order to reload them automatically when they change.

You can also define a listener and context properties in order to start Xkins engine:


Xkins-definition file:

This is a piece of a xkin-definition file we will use in our examples, where we are declaring 2 skins: skin1 and skin2:
Click here to see the file.

In this example, Skin2 extends Skin1.
Skin1 declares 3 templates: frame, field and button.
Skin2 overwrites resources "back", "tipoLetra" and "colorLetra", frame's resources, field template content and buttons resources.

JSP file:

These skins can be used in JSP in the following way:

<%@page contentType="text/html"%>
<%@ taglib uri="/WEB-INF/tld/xkins.tld" prefix="xkin" %>
<%@ page import="net.sf.opentranquera.xkins.*" %>
//skin change on reload
String skin=XkinProcessor.getCurrentSkinName(request);
if(skin.equals("skin1")) {
} else {
XkinProcessor.setCurrentSkinName(request, skin);
<head><title>Skin: <xkin:xkinName/></title></head>
<xkin:template name="frame">
    <xkin:templateParameter name="width">40%</xkin:templateParameter>
    <xkin:templateParameter name="title">Xkins Demo</xkin:templateParameter>
    <xkin:templateParameter name="buttons">
        <xkin:template name="button">
            <xkin:templateParameter name="action">
        <xkin:template name="button">
            Change Skin
            <xkin:templateParameter name="action">
    <xkin:template name="field">
        <xkin:templateParameter name="label">
            First name
        <xkin:templateParameter name="data">
            <input type="text" name="nombre">
    <xkin:template name="field">
        <xkin:templateParameter name="label">
            Last name
        <xkin:templateParameter name="data">
            <input type="text" name="apellido">
    <xkin:template name="field">
        <xkin:templateParameter name="label">
        <xkin:templateParameter name="data">
            <input type="text" name="telefono">
    <xkin:template name="field">
        <xkin:templateParameter name="label">
        <xkin:templateParameter name="data">
            <input type="text" name="email">
<jsp:include page="../footer.jsp"/>

By using template tag, it commands the Processor to use each template. TemplateParameter tag is used to pass a parameter for the template. The bodyContent built-in parameter is passed through template tag body content.
In runtime, if skin name is set to "skin1", generated HTML by this JSP page would be:

In runtime, session attribute defined in Skin.ATTR_SKIN_NAME is used to determine skin name. Login will be responsible to set this attribute properly according to user?s preferences. If no vaule is set, default skin name is assumed. Default skin name can be declared as an init parameter in web.xml XkinServlet declaration.
If skin name is "skin2", the generated HTML would be:

Using Xkins in this way is posible but a little confussing, so it's better to write your own tags to clarify Xkins usage, or you can use Xkins Forms Tags or JSF integration.

Xkins taglibs

Xkins has some utility taglibs. We have seen an example of such taglibs in example using:

  • TemplateTag
  • TemplateParameterTags.

But there are some more tags that you can use to access Xkin's resources, paths, and other useful things:


This tag is used to access paths from Skins definitions.

<xkin:path name="backgrounds"/>

Will produce this output (assuming skin1 set in session) : /xkins/skins/skin1/backgrounds


You can access Skin resources with this tag.

<xkin:resource name="back"/>
<xkin:resource name="tipoLetra"/>

Output produced by this tag (assuming skin1 set in session):

Skin name management:

Allows you to set current Skin name in Session.

This tag saves current skin name value set in session. This is used along with RestoreActualXkinTag and is useful if you need to change Skin during a JSP.

This restores value saved by SaveActualXkinTag

This writes to output the name of the current skin.


Use Skin X set in session

<xkin:xkin name="skin2"/>

Use Skin2 templates, resources, etc.


Again, use Skin X set in session

Using Xkins in a no-web environment

You don't need a web environment in order to use Xkins. You can use Xkins in a context where no httpession exists.

For instance, if you are in a java class where you need to send an e-mail and you want e-mail text to use a template defined by Xkins, you can code as follows:

Xkins xks = (new XkinsLoader()).loadSkins("/config/xkins/mail-templates.xml");
Skin skin = xks.getSkin(XkinProcessor.DEFAULT_SKIN);
XkinProcessor xkpBody = new XkinProcessor();
Template tmpBody = skin.getTemplate("mail");
xkpBody.addParameter("text", "This is a text");

Your mail-templates definition will have a Skin with a mail template that receives a "text" parameter:

<?xml version="1.0" encoding="UTF-8"?>
       <!-- SKIN default -->
       <skin name="default" url="/skins/default">
             <processor type="net.sf.opentranquera.xkins.processor.VelocityTemplateProcessor"/>
             <template name="mail">
<tr bgcolor="cyan">

Your mail will has the following body:

	<tr bgcolor="cyan">
		<td>This is a text</td>

Print version | Download | Powered by