Sei sulla pagina 1di 33

PERSONALIZATION TOOLKIT

WORKFLO W & AUTH ORIZA TION MANAGEME NT


GX WEBM ANAGER 9

Date
August 19, 2008

Target Audience
Editor
Application Manager
Developer

Target GX WebManager version


GX WebManager 9.5.0 and higher

Document ID and version


GXD00019_en, version 1.00
PERSONALIZATION TOOLKIT Workflow & Authorization Management

SU MMARY
In combination with the license component ‘User Access & Profiles’ this module makes it
possible to show a logged-in website visitor a personalized presentation based on his profile.
The visitor can modify his own profile and so adjust his main interests. The website manager
defines which fields are available to the web user. Based on these fields personalization rules
can be defined. Personalization rules are centrally maintained and applied o n several levels in
the content, for instance on page level and in forms.

This document describes how personalization works and where it can be applied. This
document is written for developers. To really understand personalization, knowledge of XML
and XSL is an absolute necessity.

To become familiar with XSL and before working with XSL, please read the tutorials at
http://www.zvon.org. Start with the XPATH tutorial and then study the XSL examples.

PREREQUISITES
Content Management

Basic Content Management


Advanced Content Management

Workflow & Authorization Management

User Access & Profiles

RELATED TOPICS
Connectivity Management

Advanced Forms

VERSION CONTROL

Version Date Description


1.0 August 19, 2008 Initial version

e-mail info@gx.nl http://www.gx.nl/ 3/33


PERSONALIZATION TOOLKIT Workflow & Authorization Management

e-mail info@gx.nl http://www.gx.nl/ 4/33


PERSONALIZATION TOOLKIT Workflow & Authorization Management

TABLE OF CONTE NTS

1 Overview of the possibilities ........................................................................ 7

2 Personalizing content ............................................................................... 9


2.1 Creating (combinations of) expressions .......................................................... 9
2.2 Combining expressions in personalization ...................................................... 11
2.3 Personalizing content elements ................................................................. 13
2.4 Personalizing pages .............................................................................. 14
2.5 Testing the personalizations ..................................................................... 15
2.6 Usage of the personalizations ................................................................... 16

3 Visitor profiles ...................................................................................... 17

4 XSL Transformation & Personalization............................................................. 19


4.1 Technical information............................................................................ 19
4.2 Constructing personalized HTML ................................................................ 22
4.3 Debugging with the admin tool .................................................................. 24

5 Personalized messages ............................................................................. 27

6 Preconditions ....................................................................................... 31

e-mail info@gx.nl http://www.gx.nl/ 5/33


PERSONALIZATION TOOLKIT Workflow & Authorization Management

e-mail info@gx.nl http://www.gx.nl/ 6/33


PERSONALIZATION TOOLKIT Workflow & Authorization Management

1 OVERVIEW OF THE POSS IBILITIES

Using personalization, it can be determined in GX WebManager whether certain parts of the


website should be shown or not. Personalization can be set at the page, page section, element,
and form level. Visitors‟ data can also be shown on a web page.

Maintaining data in the profile and recording the visitor‟s behavior allows offering information
important to that visitor. Once someone's areas of interest are known, the website can be
modified in such a way that the visitor sees content of interest to him. It also gives a better
overview for the visitor, if there is only information available that fits his interests.

Personalizing content makes the following possible:

User registration with advanced filters/preferences in a personal profile that is


maintained with a login name and password.

Showing certain content that fits the user‟s profile.

Making page parts conditional. For instance, showing an image or a paragraph only if the
visitor is logged in.

Blocking pages for certain visitors.

Showing information from the session on a „random‟ place on the website (e.g.,
Welcome <christianname>).

Partially completing forms by inserting known data.

Storing personal information on the server (called „personal workspace‟).

Generating forums and community functions based on the same account used for
personalization.

E-mailing newsletters based on the content in GX WebManager, but with an intermediary


editorial step. Newsletters can be HTML as well as plain text.

GX WebManager offers accessible personalization. This way, the visitors do not have to select
certain profiles again and again, and are able to set preferences regarding themes and
information items.

The personalization function does not mean that visitors have to log in, but if a visitor is not
logged in, he may not access as much as if he were logged in. On an airline website, for instance,
anybody can request flight information but the user has to be logged in to actually book a flig ht.

e-mail info@gx.nl http://www.gx.nl/ 7/33


PERSONALIZATION TOOLKIT Workflow & Authorization Management

e-mail info@gx.nl http://www.gx.nl/ 8/33


PERSONALIZATION TOOLKIT Workflow & Authorization Management

2 PERSONALIZIN G CONTE N T

To personalize content, two steps have to be taken:

The content should have an indication for which type of visitor it is intended.

The type of information the visitor would like to see should be saved.

How content should be personalized is illustrated in this chapter with an example. Perform the
following steps:

1. Create (combinations of) expressions.

2. Personalize the content elements.

3. Personalize the pages.

4. Test the personalizations.

2 .1 C rea ting ( co mb in a tion s o f ) exp re ss ion s

Select the [XSLT Expressions] tab from the Format > Personalize menu to define
conditions that allow certain visitors to see or not see specific elements. Create a new expression
and complete the fields:

e-mail info@gx.nl http://www.gx.nl/ 9/33


PERSONALIZATION TOOLKIT Workflow & Authorization Management

The fields on this tab have the following meaning:

Field Description
Name Name of the expression.

Available Determines whether this personalization may be used or not.

Tag name Only in the Type=‟xsl‟ and Type=‟select‟ cases can a tag name be entered.
For other types, a name of the form wm-user-personalization-number is
generated.

Create a new tag (e.g., wm-user-christianname) that then can be used on


the page ( <wm-user-christianname />). This allows showing personal
information.
Type The options are:

‘Condition’: XPATH expression that generates „true‟.

‘Choose’: The same as „Condition‟ but with a redirect to another page if


the expression generates „false‟. The login page is the default. It can be
overruled on the [Choose redirect page] tab from the Edit >
Settings > Read access menu.

‘Select’: XPATH expression that retrieves information from an XML


structure.

‘XSL’: An XSL template, for all other options.


Show links „Yes‟ results in a protected page on the menu, but there is no effect if a
visitor with insufficient rights clicks the page. The visitor is redirected to the
login page and will be able to access the desired page if he logs in.
XSLT XSLT code (for Type=„XSL‟) or XPATH expression (for other types). Examples:

‘Condition’:

/root/system/user/sex = '1'

Meaning: Verify that the visitor is male.

‘Choose’:

count(/root/system/user/username) &gt; 0
and (/root/system/user/username) = 'administrator'

Meaning: First, verify that the „username‟ tag exists and then that the
user is the administrator.

‘Select’:

/root/system/user/firstname

Meaning: Retrieve the first name.

e-mail info@gx.nl http://www.gx.nl/ 10/33


PERSONALIZATION TOOLKIT Workflow & Authorization Management

‘XSL’:

<xsl:value-of select="/root/system/user/firstname"/>
<xsl:text > </xsl:text>
<xsl:value-of select="/root/system/user/lastname"/>

Meaning: Retrieve first name+space+last name.


Assigned to If this expression is used in one or more presentation models, the models are
listed here.

Test XSLT Tests whether the XSLT code is correct or not. This is only a syntax check.

Example of the expression use in the previous screen shot:

2 .2 C om b in ing exp re ss ion s in p e rsona liza tio n

Combinations of expressions can be created on the [Personalizations] tab. It can be


indicated if the combination should be complete (with an AND operator) or if at least one of the
expressions should conform (with an OR operator). A test is also run to see if the total XSLT
expression‟s syntax is correct or not.

e-mail info@gx.nl http://www.gx.nl/ 11/33


PERSONALIZATION TOOLKIT Workflow & Authorization Management

The fields on this tab have the following meaning:

Field Description
Name Name of the model.

Available Determines whether this personalization may be used or not.

Operator Choice of the operator (AND or OR).

Use NOT operator Surrounds the entire expression with an NOT.

Show links „Yes‟ results in a protected page on the menu, but there is no effect if
a visitor with insufficient rights clicks the page. The visitor is
redirected to the login page and will be able to access the desired
page if he logs in.
Assigned expressions The expressions of this model.

Total expression The XSLT code of the combined expression.

Test XSLT Tests whether the XSLT code is correct or not. This is only a syntax
check.

e-mail info@gx.nl http://www.gx.nl/ 12/33


PERSONALIZATION TOOLKIT Workflow & Authorization Management

2 .3 Pe rso na liz in g co n ten t e le men ts

The grey personalization icon of the content elements allows indicating which expression or
which personalization model has an element associated with it. Once an expression or a
personalization model is assigned to an element, the icon turns red:

Content elements in Media Repository articles can be personalized in a similar way:

e-mail info@gx.nl http://www.gx.nl/ 13/33


PERSONALIZATION TOOLKIT Workflow & Authorization Management

2 .4 Pe rso na liz in g pa ge s

It is also possible to personalize an entire page. On the relevant page, open the File >
Properties > Read access menu:

Check „Overrule inherited settings for this page‟, click [Apply], and select an expression or
personalization model under „Select a personalization‟. If desired, pass on the current settings to
the parallel or underlying pages:

e-mail info@gx.nl http://www.gx.nl/ 14/33


PERSONALIZATION TOOLKIT Workflow & Authorization Management

2 .5 Te s tin g the pe rson a liza tion s

To test if the personalization works correctly at the website environment, on the edit
environment go to the relevant page and open the Preview page using the File menu:

This screen lists the expressions and personalization models used on this page. Check the
personalization(s) to be tested and click [OK]. GX WebManager now shows what happens if a
visitor with the specific properties accesses this page.

Note: It is also possible to view a page on a certain date and time. This, for instance, could be
the case if an action page should show different information at certain times. Additional detail
falls beyond the scope of this document.

e-mail info@gx.nl http://www.gx.nl/ 15/33


PERSONALIZATION TOOLKIT Workflow & Authorization Management

2 .6 Us ag e of the pe rson a liza tion s

Which expressions and which personalization models are assigned to which pages can be viewed
on the [Usage] tab from the Format > Personalize menu:

e-mail info@gx.nl http://www.gx.nl/ 16/33


PERSONALIZATION TOOLKIT Workflow & Authorization Management

3 VISITOR PROFILES

Profiles are used for personalization. They contain default data (such as login name, address,
city, and subscriptions to various newsletters):

Data from external applications can also be used to set personalization for certain persons. The
forms module allows filling session variables with the use of special handlers, such as the
QueryToSessionHandler. In the personalization, the data can then be read again from the session
variables. This implies customization software and modifications to the database to read data
from the session variables and save them in the database. If the visitor returns, his information
can be retrieved from the database and his visit can be monitored immediately.

e-mail info@gx.nl http://www.gx.nl/ 17/33


PERSONALIZATION TOOLKIT Workflow & Authorization Management

e-mail info@gx.nl http://www.gx.nl/ 18/33


PERSONALIZATION TOOLKIT Workflow & Authorization Management

4 XSL TRANSFORMATION & PERSONALIZATION

4 .1 Tec hn ic a l in fo r ma tio n

Before explaining XSL transformation, some technical information about functioning of


personalization in GX WebManager follows:

The session is used in GX WebManager to store profiles (the use of the visitor‟s information to
personalize pages for that visitor). Using handlings, a visitor is logged in and his/her information
is retrieved from the database and added to the session in XML form, under session keys. The
handler performing this action is called „QueryToSessionHandler‟.
Session keys starting with „GX_‟ are special in GX WebManager and are used to personalize pages.
Session keys are divided in groups. The group can be found in the name. The name always consists
of three parts separated by hyphens: GX-<class_name>-<template_name>. Session keys with
visitor‟s information start, for instance, with GX-user. When creating keys, maintain these
groups, or it will not be possible to locate the session keys in the session.
For every requested page, an XML document is constructed from the XML saved in t he session
under these keys, the page HTML, and the information from the request.

Example: If a visitor is logged in, the XML being constructed will roughly look like this:

<root>
<system>
<cookies>
... all cookies ...
</cookies>
<headers>
... all headers ...
</header>
<requestparameters>
... all request parameters ...
</requestparameters>
<date>2005-12-09</date>
<time>11:17:06</time>
<usergroup>
<id>3</id>
<webid>26098</webid>
<groupname>Women</groupname>
<useindocuments>1</useindocuments>
<originalid/>
</usergroup>
... all other user groups where this user belongs to ...
<user>
<id>1</id>
<webid>26098</webid>
<username>noel</username>

e-mail info@gx.nl http://www.gx.nl/ 19/33


PERSONALIZATION TOOLKIT Workflow & Authorization Management

<email>noel@gx.nl</email>
<password>fugo45rd</password>
<firstname>Noël</firstname>
<lastname>Hilton</lastname>
... other user data ...
</user>
</system>
<showhtml>
<![CDATA[ HTML block ]]>
</showhtml>
<wm-user-personalization-45676 forpage="true" orgurl="http...">
<showhtml>
<![CDATA[ HTML block ]]>
</showhtml>
<wm-hostname default="127.0.0.1" />
<showhtml>
<![CDATA[ HTML block ]]>
</showhtml>
<wm-user-personalization-46482>
<showhtml>
<![CDATA[
<h2 class="header">Example of inline personalization:</h2>
<p class="normal">Welcome back!
]]>
</showhtml>
<wm-user-christianname />
<showhtml>
<![CDATA[
!<br /><br /><br /><br /></p>
]]>
</showhtml>
... all other content in HTML and XML (when needed) ...
</wm-user-personalization-45676>
<showhtml>
<![CDATA[ HTML block ]]>
</showhtml>
</root>

The XML above has been shortened in a few places to make it easier on the eye.

Note: If information is written to the session, the tags are GX-xxx-yyy. If information is
retrieved from the session, those same tags are WM-xxx-yyy.

e-mail info@gx.nl http://www.gx.nl/ 20/33


PERSONALIZATION TOOLKIT Workflow & Authorization Management

The XML is constructed as follows:

root
o system
 cookies (these are passed on from the browser in the request)
 headers (idem)
 requestparameters (idem)
 date
 time
 flow
 usergroup
 user
o showhtml
o wm-classname-templatename

This XML contains all the information needed to personalize a page:

The <system> tag contains all the information from the session needed to construct this
request.

The <flow> tag appears only during a form flow that consists of several steps and
contains the entered values and possible validator warnings, errors, etc. The form design
uses this information, with the described personalization mechanism, to show errors and
prefill previously completed form parts (e.g., if a step back is taken on a form).

The <usergroup> and <user> tags contain the web user information from the session.
This XML can also be requested in a handler by requesting the GX-usergroup or the
GX-user from the session object. If needed, XML can also be added to handlers by
saving XML fragments under their own session key. This session key should also start with
GX- (e.g., GX-myproject).

The <system> tag is followed by one or more <showhtml> tags with the page HTML in a
CDATA block. This is used to ensure that the XML parser does not try to parse the HTML.

The HTML is interrupted with special <wm-XML> tags. The personalization module in GX
WebManager generates these <wm-XML> tags. It is the intention to replace these tags
during the personalization. In the XML above, for instance, there is a
<wm-user-christianname > tag between the <showhtml> blocks. The personalization
ensures that this tag is replaced with the <firstname> value. The <firstname> is
located in the same document under the root/system/user/firstname tag. The
technique replacing these tags is XSL.

e-mail info@gx.nl http://www.gx.nl/ 21/33


PERSONALIZATION TOOLKIT Workflow & Authorization Management

4 .2 C on s tru c ting pe rson a lize d HTML

Personalized content and dynamic functionality use more resources than static pages. To
minimize this in the case of personalized pages, XSL transformations are used to combine the
content of a session with the cached content of the generator. This way, maximum use is made of
the cache when dynamic pages are constructed.

HTML

XSL translation

XML +
Session information

Session
GX user

Header
s
Cookies

Cache

XML
XSLT
Style sheet

GX WebManager
Generator

e-mail info@gx.nl http://www.gx.nl/ 22/33


PERSONALIZATION TOOLKIT Workflow & Authorization Management

As shown in the last part of the previous paragraph, personalization in GX WebManager is nothing
more than transforming an XML document with an XSL style sheet. XSL is a programming language
used to transform XML documents into another format (XML, HTML, PDF, …). In GX WebManager,
the XML is constructed as described above; in other words, the page HTML, supplemented with
personal and other data. An XSL style sheet is used to transform this XML in a perso nalized HTML
document to eventually be presented to the visitor.

A <wm-user-christianname /> tag from the example in the previous paragraph is replaced
during the XSL transformation with the <firstname> value. The XSL needed to do this:

<xsl:template match="//wm-user-christianname">
<xsl:value-of disable-output-escaping="yes"
select="/root/system/user/firstname" />
</xsl:template>

This XSL template matches the <wm-user-christianname /> tags and replaces them with a
value selected from the XML document with the /root/system/user/firstname XPATH
expression.

Note: XPATH is a default related to XSL to select XML fragments.

This XSL template is part of a large XSL style sheet containing several templates that have been
created, for example, with the GX WebManager personalization module or that are part of
GX WebManager‟s standard functionality for, e.g., visitors, forms, searches, etc.

The personalization module allows adding new XSL templates. A personalization XSL template
name is always constructed as follows:

wm-<class_name>-<template_name>

The fact that the tag starts with wm (Attention: THIS IS MANDATORY!) is used by GX WebManager
to divide pages in parts that show up as CDATA in a „showhtml‟ block and in the WM tags (see the
example in the previous paragraph). This makes it possible to insert the
„Welcome <wm-user-christianname/>!‟ text line in the title of a paragraph. The page HTML
is then split in two pieces (before and after the WM tag) that end up in the „showhtml‟ blocks.
During the personalization, they are put together again.

In a nutshell:

By default, there is an XSL template that transforms the „showhtml‟ blocks to regular
HTML in the CDATA.
The WM tag matches the XSL template above and is in this template replaced with the
<firstname> value.

The WM tag used as an example (<wm-user-christianname />) is closed with a />. There are,
however, also WM tags that have a beginning and an ending tag. In between these tags, there can
be „showhtml‟ and other WM tags. These types of tags can be used to, for instance, authorize a
visitor. See also wm-user-personalization in the previous paragraph‟s example. The XSL
template for these types of tags does not consist of an „xsl:value-of‟ but an „xsl:choose‟

e-mail info@gx.nl http://www.gx.nl/ 23/33


PERSONALIZATION TOOLKIT Workflow & Authorization Management

(a conditional XSL expression). Parts of a page can be made conditional using such an expression
(e.g., showing a paragraph only if the visitor is logged in).

The personalization mechanism can be expanded. Customization handlers can often add their own
pieces of XML to the session under GX keys. In combination with project-specific XSL templates,
these keys can be used to personalize pages based on information from an external system
(retrieved by a customization handler) and placed in the session in XML form.

XSL is a very powerful language and allows very complicated actions (it is a professional
programming language). In GX WebManager – using XSL, forms, and personalizations - complicated
web applications are built for various projects (e.g., web shops). This information and knowledge
of XSL and Java allows programmers to do the same.

4 .3 D ebu gg in g with th e ad m in too l

To debug personalization, it can be handy to have the XML and XSL available that are generated
below the surface. Take the next step to retrieve the XML and XSL that WebManager uses:

Open the file <WebManager directory>\apache-tomcat\conf\server.xml

Check the reference to the XML file that contains the users (by default this is the file
tomcat-users.xml):

Change the next line (if present):


<Realm className="org.apache.catalina.realm.MemoryRealm" digest="MD5" />
To:
<Realm className="org.apache.catalina.realm.MemoryRealm" />

Open the file <WebManager directory>\apache-tomcat\conf\tomcat-users.xml

Check if the role “wmadmin” is present and that there is at least one user that uses that
role. A minimal population of the users XML file looks like this:

<?xml version='1.0' encoding='utf-8'?>


<tomcat-users>
<role rolename="wmadmin"/>
<user username="wmadmin" password="123456" roles="wmadmin"/>
</tomcat-users>

Open the URL:


http://<backend-hostname>:<port>/web/admin/status

If the status page is displayed successfully, then open the homepage of your website in
the same browser window. Use the backend hostname when visiting the homepage:
http://<backend-hostname>:<port>/web/show

e-mail info@gx.nl http://www.gx.nl/ 24/33


PERSONALIZATION TOOLKIT Workflow & Authorization Management

Log in as a webuser on the website and go to personalized page that you want to debug
the XML and XSL of. The XML can be retrieved by adding “/xmldebug=true” to the URL.
The XSL can be retrieved by adding “/xsldebug=true” to the URL. An example:
Normal URL: http://localhost/web/show/id=76284/langid=43
XML source: http://localhost/web/show/id=76284/langid=43/xmldebug=true
XSL source: http://localhost/web/show/id=76284/langid=43/xsldebug=true

Note: The XML is „smartly‟ constructed. This means that the XML from session keys beginning with
wm- (e.g., wm-user-lastname) is only added to the XML if the XSL used to do the
transformation also contains templates (in this case wm-user) that match this XML. Performance
is the reason for this: Long documents are harder to transform than short ones. However, during
the debugging, it can make it look like there is XML missing.

e-mail info@gx.nl http://www.gx.nl/ 25/33


PERSONALIZATION TOOLKIT Workflow & Authorization Management

e-mail info@gx.nl http://www.gx.nl/ 26/33


PERSONALIZATION TOOLKIT Workflow & Authorization Management

5 PERSONALIZED MESSAGE S

Personalization can also be used to create a handler. To produce the login name of the visitor,
the example in this chapter uses an XSL template as a parameter value. The handler should then
transform the XML in the session to this XSL to obtain the username. The code fragment below
shows a handler that prints the result of this transformation in the log.

package nl.gx.product.form;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import nl.gx.webmanager.handler.forms.FormComponentConfig;
import nl.gx.webmanager.handler.forms.FormDefinition;
import nl.gx.webmanager.handler.forms.HandleException;
import nl.gx.webmanager.handler.forms.Handler;
import nl.gx.webmanager.handler.forms.InitializationException;
import nl.gx.webmanager.handler.forms.State;
import nl.gx.webmanager.handler.forms.foundation.FormHandlerBase;

public class HelloWorldHandler extends FormHandlerBase implements Handler {

// Private logger for this class


private final static Logger LOG =
Logger.getLogger(HelloWorldHandler.class.getName());

String userXsl;
FormComponentConfig config;

public void init(FormComponentConfig c) throws InitializationException {


this.config = c;
userXsl = config.getRequiredParameterValue("userXSL");
}

public void doHandle(FormDefinition formDefinition,


State state,
HttpServletRequest req,
HttpServletResponse resp) throws HandleException {
// Transform:
String userName = config.getTextValue(state, req, this.userXsl);
// say hello in the log
LOG.severe("Hello " + userName + "!");
}
}

e-mail info@gx.nl http://www.gx.nl/ 27/33


PERSONALIZATION TOOLKIT Workflow & Authorization Management

In this fragment, the init method places the configuration object in a class field so it can be
used in the doHandle. The XSL template that has to produce the userName is read from the
userXSL parameter (this has to be entered as the parameter value in the forms module).

User XSL template:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">


<xsl:template match="/">
<xsl:value-of disable-output-escaping="yes" select="/handler/user/username" />
</xsl:template>
</xsl:stylesheet>

Note: The disable-output-escaping function is used to prevent extended ASCII characters


from being transformed into their HTML escape character version. It is the intention, for example,
to show „Noël‟ instead of „No&euml;l‟.

Note: The tags for the template‟s definition can be omitted (<xsl:template...).

Next, the transformation in the doHandle is performed by requesting getTextValue. This


method constructs the XML needed to perform the transformation (see the previous chapter) and
then transforms it with the included XSL template. The result of the transformation (the login
name) is printed in the log. This handler uses config.getTextValue. There are a number of
handy related methods such as getText:

String getText(State state, HttpServletRequest req, String parameterName)

This method retrieves the parameter and then tries to transform the session with its value. The
getText method already performs an XSL transformation of the parameter value. If this does not
work, the value of the parameter is generated.

Example (from the „Login – retrieve groups‟ handler):

The formpartcode parameter (<xsl:value-of select="/handler/user/username" />) specifies the


username value to be retrieved from the session.

This way, it can be decided in the forms module if the login name should be generated w ith XSL
or if it should simply be included as parameter without having to modify the Java code. A similar
getTexts method exists for parameters with multiple values. For a more detailed description on
how to create, deploy & configure handlers, please read the document “Integration APIs”
(http://www.gxdeveloperweb.com/Software/Documentation.htm#GXD0052 ).

e-mail info@gx.nl http://www.gx.nl/ 28/33


PERSONALIZATION TOOLKIT Workflow & Authorization Management

e-mail info@gx.nl http://www.gx.nl/ 29/33


PERSONALIZATION TOOLKIT Workflow & Authorization Management

e-mail info@gx.nl http://www.gx.nl/ 30/33


PERSONALIZATION TOOLKIT Workflow & Authorization Management

6 PRECONDITIONS

Using preconditions in combination with handlers, validators, or routers, is a powerful form of


personalization. The rule definitions of the forms allow setting preconditions. If the precondition
generates the FALSE or NULL value, the handler, validator, or router is terminated and not
executed. If the precondition generates the „true‟ value, the handler, validator, or router is
executed.

Example:

e-mail info@gx.nl http://www.gx.nl/ 31/33


PERSONALIZATION TOOLKIT Workflow & Authorization Management

To make it easier to understand the expression in the screen shot, the next page shows an
example of a piece of XML flow on a form that is part of the web user‟s registration process.

The image above shows a rule definition with a precondition based on the RequestRouter. The
precondition consists of an XSL expression that generates „true‟ if there are mistakes in the XML
flow.

Example of an XML flow:

<root>
<system>
...
<flow id="43772">
<formpath>43772</formpath>
<formnavigation>
http://127.0.0.1:7081/web/show?id=43680&amp;langid=43&amp;
cfe=43772&amp;ff=43772
</formnavigation>
<formelement id="43772" pageid="43682" formid="43775">
<formpart id="f44108" XSLtag="username">
<userentry>noel</userentry>
</formpart>
<formpart id="f44109">
<userentry>XXXXX</userentry>
</formpart>
<formpart id="f44110">
<userentry>YYYYY</userentry>
</formpart>
<formpart id="f44111" XSLtag="email">
<userentry>noel@gx.nl</userentry>
</formpart>
<error code="not_found">
This login name &apos;noel&apos; has already been used
</error>
<error code="not_found">
This e-mail address &apos;noel@gx.nl&apos; has already been used
</error>
</formelement>
<values></values>
</flow>
...
</system>
...
</root>

This fragment states that in a form flow, on a form element with a number of form parts, two
errors have occurred. The exact format of the XML flow is usually not important because the
SessionFormFlow class makes it easy to manipulate the flow from Java. The only exception is

e-mail info@gx.nl http://www.gx.nl/ 32/33


PERSONALIZATION TOOLKIT Workflow & Authorization Management

the use of preconditions, in which case XSLT or XPath expressions should be written to match this
XML.

The precondition in the RequestRouter screen shot above eventually shows up in an XSL style
sheet generated by GX WebManager:

<?XML version="1.0"?>
<xsl:stylesheet XMLns:XSL="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<xsl:if test=
"count(/handler/flow/formelement[@id=43772]/error) &gt; 0 ">true
</xsl:if>
</xsl:template>
</xsl:stylesheet>

It is easy to see that in this fragment the predefined @formelement@ variable has been replaced
by GX WebManager with a specific ID of a form element that also appears in the XML flow on the
previous page.

The XML transformation to this template generates „t rue‟, because there are error tags in the
form element with id=“43772”. The associated RequestRouter is executed.

More complicated expressions also allow checking the values of certain fields.

e-mail info@gx.nl http://www.gx.nl/ 33/33

Potrebbero piacerti anche