How to print Variables and Context Parameters in templates

by Alberto Molinaroli
11,144 views Published on Oct 24, 2011
Applies to: All versions
Table of contents

Introduction

WebRatio allows the user to add Variables to a page in order to define Condition Expression and to use Visibility Conditions in the templates (see this article for details). Moreover it's possible to define Context Parameter to store infomation in the sessionContext and make it available for all the JSP session. Sometimes there's the need to use the value of these two elements (Variables and Context Parameters) in the templates. It's possible to use JSTL in order to print these information.

Context Parameters

Suppose you want to print in a page all the default Context Parameters, which are automatically added to every Web Project.

These parameters contain information regarding the current Locale and the current User. Let's write a unit template for the NoOpContentUnit like the following:

<table cellspacing="2" cellpadding="1">
	<tr>
		<td>Current User: ${UserCtxParam}</td>
	</tr>
	<tr>
		<td>Current Group: ${GroupCtxParam}</td>
	</tr>
	<tr>
		<td>Current Language: ${LanguageISOCtxParam}</td>
	</tr>
	<tr>
		<td>Current Country: ${CountryISOCtxParam}</td>
	</tr>
</table>

In order to extract the value of a Context Parameter, it's possible to use its identifier or its name. Consider for example a Context Parameter like the one shown in the figure below.

This is a boolean Context Parameter with "isAdmistrator" as name and with "ctx1" as ID. You can print it using:

${isAdministrator}

or
${ctx1}

Suppose to add another Context Parameter to the Web Project, like the one on the image. 

This Context Parameter is named "Product" and has "ctx2" as ID. The main difference between this parameter and the previous one is that this is Entity based. In fact the "type" property is set on the "Entity" option and the associated Entity is "Product". The syntax necessary to print it is quite different. The Context Parameter contains only the Primary Key of the instance object belonging to the associated Entity. So, if the Primary Key of the "Product" Entity is the "OID" Attribute, then in order to print it you have to write:

${Product.OID}

or
${ctx2.OID}

Variables

Suppose to add to the Home Page of the "Acme" Sample Project a Variable named "LoginFailed".

This variable is originally set to the "false" value; then, when the login attempt failes, the variable is set to "true". You can use this variable to create a Condition Expression and to add a Visibility Condition to some page elements. You can also decide to print the variable directly in a template using this syntax:

${var1}

or

${LoginFailed}

This syntax does not change when the variable is defined on a Entity based unit.