How to centralize Web Project properties in a configuration file

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

Introduction

When designing Web Projects, often the use of static values are required, such as values of conditions, passing of static values in Links Coupling, values in configuration Properties of the Units, etc. The problem of the usage of static values is that they may vary according to the environment in which the application is deployed (such as Web Services URLs in test environments and in production environments). WebRatio resolves this issue providing the WebRatio.properties file. This file contains a list of key-value pairs representing all the static values (the value of the pairs) of a Web Project giving a name to each (the key of the pairs). Those keys can then be used in the Web Project as placeholders instead of the proper values. In the generated Web application, at startup, all the keys are replaced with the corresponding values, in order to make the Web application work properly.

The structure of the WebRatio.properties file

In order to configure it correctly, the WebRatio.properties file must be placed, in the Web Project folder, in Web Content/WEB-INF/classes. The property file itself must have the same structure of a normal Java property file. Here's an example:

highlightedProductOfTheDay=true

highlightedCategoryOfTheDay=true

allProductsMaxResults=150

getDataWebService=http://webservices.daehosting.com/services/TemperatureConversions.wso

Remember that in properties files:

  • each line must contain a single property
  • comments must begin with "!" or "#"
  • spaces must be escaped with " "
  • The encoding is ISO-8859-1, also known as Latin-1. All non-Latin-1 characters must be entered by using Unicode escape characters

How to use the properties in the Web Project

once the WebRatio.properties file has been defined, it's possible to replace every static value in:

  • the Properties panel of the Units
  • in the Value Property of Conditions
  • in Link Couplings

with the corresponding key simply replacing the value with "${Name of the key}". Has example, referring to the WebRatio.properties file shown above, it's possible to change the Home Page of the Acme project:

Home page with static values

Home page with static values

using the properties:

Home page with properties

Home page with properties

or the Max Results Property of the All Stores Index Unit:

Index Unit Properties with static values

Index Unit Properties with static values

using the property:

Index Unit Properties with properties

Index Unit Properties with properties

Or a Link Coupling:

Link Coupling with static values

Link Coupling with static values

using the property:

Link Coupling with properties

Link Coupling with properties