You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Gene Campbell <ge...@yahoo.com> on 2003/06/08 01:14:12 UTC

JSP, Java and constant values best practise question

Hello all,

Suppose an action.execute method adds an Object to the
application cache

getServlet().getServletContext().setAttribute(...)

The key value should probably be specified as a
constant value to provide a level of indirection. 
(Suppose constants are stored in a java interface, and
THE_KEY='objectKey'.)  So, we'd have 

setAttribute( IConstants.THE_KEY, someObject );

Now, in the jsp file, the forward from this action, a
bit of JSTL is written to dump someObject.toString(). 
Here's a bit of code that will work.

<c:out value="${applicationScope.objectKey} />

Problem here is that THE_KEY is used in the Java
classes side, but the actual value is used on the jsp
side.  If the constant changed, the controller has now
lost touch with the view.  

I can't seem to figure out how to use
IConstants.THE_KEY in the jsp file too.

Another question might be, who cares about the
indirection.  Why's 'THE_KEY' any better than
'objectKey' anyway?  And, it is unlikely that
constants will ever change, so there no great find and
replace effort from which to protect yourself.  Once
you've done the integration testing, and it works,
done?

(Don't worry, I'm not wasting my employers time.  I'm
unemployed right now.)

Thoughts?  Thanks - gene


__________________________________
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org