This is my way of doing this, and it may be a tad crap.  In the page tag at
the top of the JSP I add one or more imports like so:

<%@ page language="java" import="com.marsh-bourdon.Constants" %>

I then just refer to the constants within the page like so:

<%= Constants.KEY_FOR_SOMETHING %>

This should then be checked by your ide for typos etc.

Cheers

Christopher Marsh-Bourdon
www.marsh-bourdon.com

-----Original Message-----
From: David Kennedy [mailto:[EMAIL PROTECTED] 
Sent: 21 March 2005 14:18
To: Struts Users Mailing List
Subject: Using constants in JSP pages


Most of our pages have a header/navbar which performs some highlighting 
of the current page's category etc. This means all pages must define 
beans to say things like, "My category is FOO, my sub-category is BAR"

I would like to get the compiler to spot typos:
(1) To make sure FOO matches one of the defined categories in the navbar.
(2) To make sure the category variable itself is correct.

I can achieve (1) by defining a simple constants class and using the 
'unstandard' taglib:
        <un: var="foo" type="com.foo.Constants" field="FOO"/>

How can I achieve (2)? A little paranoid I know, but I've already 
defined "fo" by mistake in a couple of places(*), and there doesn't seem 
to be any advantage to using a constant if it is in turn defined by 
another hand-typed variable!

All I can think of is
<un: var="<%=com.foo.Constants.FOO_NAME%>" type="..." field="...">
but if I'm going to use <%= %> I might as well just write
        <%= com.foo.Constants.FOO %>
rather than use bind at all!

(*) Where obviously the real var names are longer and easier to typo 
than foo.
-- 
David Kennedy
Swan Labs
http://www.swanlabs.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 ------


--------------------------------------------------------------------------------
The information contained herein is confidential and is intended solely for the
addressee. Access by any other party is unauthorised without the express
written permission of the sender. If you are not the intended recipient, please
contact the sender either via the company switchboard on +44 (0)20 7623 8000, or
via e-mail return. If you have received this e-mail in error or wish to read our
e-mail disclaimer statement and monitoring policy, please refer to 
http://www.drkw.com/disc/email/ or contact the sender. 3167
--------------------------------------------------------------------------------


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to