You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Dan Allen <da...@mojavelinux.com> on 2003/04/18 21:26:13 UTC

constant/string category bridge

Okay, that subject makes no sense unless you know what I am talking
about. But read on...

Consider the case where you are listing a set of objects by
category.  An example of this might be article categories or perhaps
departments.  It would seem incorrect to hard-code the numeric ID
(assuming that is the route I went for classifying the objects in
the data store) into the view.  Therefore, I considered the
possibility of having a "string" representation of the ID.  In this
case I could do something list

/ListDepartment?cat=billing

My question relates to the legwork the business logic must do.
Where would be the best place to store the relationship between
string and numeric ID and how would it be done?  Assume in my DAO I
have constants setup such as

public static final int BILLING = 1000;

public static final int ACCOUNTING = 1001;  // would you suggest a prefix here?

My first stab would be to create an map such as

add("billing", BILLING);
add("accounting", ACCOUNTING);

and then make a lookup method such as

public static int lookupCategory(String category) {}

the other option would be to make the constant names congruent with
the string names except for case and then just to a
String.toUpperCase() and use reflection.  But then it takes away
from 

SITE_NEWS mapping to the string siteNews unless I hacked up the
string a bit.

Suggestions?  I really believe many people could potentially be
interested in the solution behind this thread.

Dan

-- 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Daniel Allen, <da...@mojavelinux.com>
http://www.mojavelinux.com/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
umm... i guess this is my signature. 8-}
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

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