<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tallan&#039;s Technology Blog &#187; JSP</title>
	<atom:link href="http://blog.tallan.com/tag/jsp/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.tallan.com</link>
	<description>Tallan&#039;s Top Technologists Share Their Thoughts on Today&#039;s Technology Challenges</description>
	<lastBuildDate>Fri, 03 Feb 2012 17:23:33 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>The Unstandard Tag Library: Using Constants Within JSPs</title>
		<link>http://blog.tallan.com/2010/07/01/the-unstandard-tag-library-using-constants-within-jsps/</link>
		<comments>http://blog.tallan.com/2010/07/01/the-unstandard-tag-library-using-constants-within-jsps/#comments</comments>
		<pubDate>Thu, 01 Jul 2010 14:18:20 +0000</pubDate>
		<dc:creator>Dylan Barrett</dc:creator>
				<category><![CDATA[Enterprise Java]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JSP]]></category>

		<guid isPermaLink="false">http://blog.tallan.com/?p=536</guid>
		<description><![CDATA[Introduction
The Unstandard Tag Library is a JSP tag library that was developed as part of the Jakarta Project.  Its purpose is to provide a collection       of useful tags that people have been requesting for JSTL.  The library serves as a place to keep all of these tags [...]]]></description>
			<content:encoded><![CDATA[<h2>Introduction</h2>
<p>The Unstandard Tag Library is a JSP tag library that was developed as part of the Jakarta Project.  Its purpose is to provide a collection       of useful tags that people have been requesting for JSTL.  The library serves as a place to keep all of these tags until they are officially added to       the Standard Tag Library.  This article focuses on the use of one of the tags contained within the library, the useConstants tag.</p>
<h2>The Problem</h2>
<p>While working on a project for a client, I realized that they were using a Java class with constants to define strings used within the application.       The idea was to use the constants everywhere in the application where the strings were needed so they could easily be maintained in one location without       having to search through the whole application when making a change.  This makes sense, and is a common best practice.  I was working on a JSP page that       needed to use the constants from the class.  It is now considered bad practice to use Java Scriptlets in your JSP page.  It is much better to use the       Expression Language (EL) in combination with JSTL and other custom tags.  Trying to keep to this rule I quickly ran into a problem.  The EL does not allow       and easy way to access constants from a Java class.  That is where the Unstandard Tag Library&#8217;s useConstants tag comes in handy.</p>
<h2>How To Use It</h2>
<p>Once you have added the library to your project it is very simple to use.  Let&#8217;s assume we have a java class containing constants such as the one below:</p>
<pre class="brush: java;">
package com.tallan.unstandard;  

public class MyConstants {    

  public static final String MY_CONSTANT_1 = 'Hello World';
  public static final String MY_CONSTANT_2 = 'Goodbye World';  

}
</pre>
<p>Let&#8217;s also assume that we added the tag library to our page as follows:</p>
<pre class="brush: xml;">
&lt;%@ taglib uri=&quot;http://jakarta.apache.org/taglibs/unstandard-1.0&quot;
           prefix=&quot;un&quot;%&gt;
</pre>
<p>We can then utilize the useConstants tag as follows:</p>
<pre class="brush: xml;">
&lt;un:useConstants var=&quot;Constants&quot;
                 className=&quot;com.tallan.unstandard.MyConstants&quot; /&gt;
</pre>
<p>After we run this line of code, an object called Constants will be available for use on the page.  We can use it with the EL and access the constants as       properties of the object.  For example:</p>
<pre class="brush: xml;">
&lt;p&gt;${Constants.MY_CONSTANT_1}&lt;/p&gt;
</pre>
<p>This solves our problem of using constants from a Java class within a JSP page without relying on scriptlets.</p>
<h2>Where To Get It</h2>
<p>You may be thinking &#8220;This is great, but where can I find this library?&#8221;  Unfortunately the Jakarta project has stopped development of the library and no       longer makes it obvious where you can get the code.  If you look around on the Jakarta site you will find that they allow you to get the project out of       source control and build it with Maven, but this is a little bit of a hassle.  If you want an easier way to get the library just go       <a href="http://people.apache.org/builds/jakarta-taglibs-sandbox/nightly/projects/unstandard/jakarta-taglibs-sandbox-unstandard-20060829.zip">here</a>.       This site contains old binaries of the library and they should work just fine.</p>
<h2>Conclusion</h2>
<p>The Unstandard Tag Library contains many useful tags that can help in the development of our JSP pages.  While it is no longer being actively developed, it can still       be a very useful tool.  We covered how to access constants from a Java class using the library&#8217;s useConstants tag.</p>
<h3>Want to Learn More?</h3>
<p>If you want to learn more about the tags available in the Unstandard Tag Library and how to use them, then head over to the documentation page for the library       located <a href="http://jakarta.apache.org/taglibs/sandbox/doc/unstandard-doc/index.html">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tallan.com/2010/07/01/the-unstandard-tag-library-using-constants-within-jsps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

