Property taglib ver. 1.6

    Custom JSP taglib. Lets you work with properties from .ini (properties) files. For example:

Suppose you have a file test.ini:
 


user=guest
password=12345

You may read properties with this tag:
 


<%@ taglib uri="taglib.tld" prefix="ini" %>

<ini:getProperty file="test.ini" name="user"/>

or you may save property value in the page scope variable and use it later:
 


<ini:getProperty file="test.ini" name="password" id="A"/>
Password is: <%=A%>

You can use getProperty tag for the reading localized values. In this case you have to provide a base name for your properties files. For example:
 


<ini:getProperty baseName="test" name="title" id="A"/>
Title is: <%=A%>

in this example tag points to files in CLASSPATH (e.g. in WEB-INF/classes) with names like test_en.properties, test_en_US.properties, test_fr.properties etc. depends on the locale.

Tag getProperty is actually a body tag. In case of the given key does not exist tag will output own body as a default value.

By default (without the parameters file or baseName) tag reads System properties.

Tag forEachKey lets you iterate over existing keys. For example:
 


<%@ taglib uri="taglib.tld" prefix="ini" %>

<ini:forEachKey file="test.ini">
 <br>Key is: <%=key%>
 <br>Value is: <%=value%>
</ini:forEachKey>

and this code lets you read System properties:
 


<%@ taglib uri="taglib.tld" prefix="ini" %>

<ini:forEachKey>
 <p>Key is: <%=key%>
 <br>Value is: <%=value%>
</ini:forEachKey>

in the above-mentioned examples key and value are the nested variables you can use as references to current key and value.

Tags are:

getProperty

reads a value for the named property from the given file. Tag's body will be used as a default value. Parameters are:

1) file Optional parameter. Describes a name for your file
2) baseName Optional parameter. Describes a base name for properties files
3) locale Optional parameter. Describes a locale for your bundle. Without this parameter tag will use the locale from browser preferences.
4) name describes a name (key) for your property
5) id Optional parameter. Describes a page scope variable for data (type is java.lang.String). Without this parameter tag just prints data.

forEachKey

Body tag executes own body for the each key. Parameters are:

1) file Optional parameter. Describes a name for your file
2) baseName Optional parameter. Describes a base name for properties files
3) locale Optional parameter. Describes a locale for your bundle. Without this parameter tag will use the locale from browser preferences.
4) varKey Optional parameter. Describes a name for the nested page scope variable (type is java.lang.String) that will keep a value for the current key. Default value is key.
5) varValue Optional parameter. Describes a name for the nested page scope variable (type is java.lang.String) that will keep a current value. Default value is value.

for downloading:

Library: initag.jar    Description: taglib.tld

 © Coldbeans      Comments?

See also Coldtags suite - the largest collection of custom JSP tags.