Dynamic property taglib ver. 1.2


    Custom JSP taglib. Lets you work with properties from .ini (properties) files. This taglib is similar to Property taglib. But here you can use also a special syntax for properties values. 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"/>

Describing your values you may use a special syntax like application.var_name or session.var_name. E.g. in your ini file:
 


user=application.guest
password=session.pass
font=Arial

in this case application.guest corresponds to the attribute guest in application scope and session.pass corresponds to the attribute pass in session scope. So any value that starts with prefix application (session) will be calculated as a value for the attribute in the described scope.

So with this taglib you may still declare your values in static files but in the same time described values could be calculated dynamically.

In other aspects taglib is similar to Property taglib. So 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 too. 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.

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>

in this example 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: dyninitag.jar    Description: taglib.tld

 © Coldbeans      Comments?

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

Also in Coldtags: