Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2007

Tip: Looking for answers? Try searching our database.

EnumMap and jsp?

Thread view: 
Rusty Wright - 17 Oct 2007 01:23 GMT
Is it possible to pass out to jsp an EnumMap and then "index" it with
the enum name?  I'm currently using a parallel map of Map<String, Size>;
for example

<img src="whatever.jpg"
  width="${photo.photoSizes['thumb1'].width}"
  height="${photo.photoSizes['thumb1'].height}"

Where photoSizes is the <String,Size> map.  In my java code I otherwise
use an enum instead of using the string thumb1, but the enum is used
with a parallel EnumMap, while this photoSizes is the <String,Size> map.

I would like to be able to always use an EnumMap.
Daniel Pitts - 17 Oct 2007 15:19 GMT
> Is it possible to pass out to jsp an EnumMap and then "index" it with
> the enum name?  I'm currently using a parallel map of Map<String, Size>;
[quoted text clipped - 10 lines]
>
> I would like to be able to always use an EnumMap.

I don't think that you can with a JSP.  However, you can make
photoSizes property into a bean with the methods getThumb1(),
getLarge(), etc...  Alternatively, you could have a utility method
somewhere that converts an EnumMap to a String map.

I know that enums are the cool new thing, but are you sure you should
be using them? Should you even be using a Map at all?  If you have a
fixed number of photo sizes, it might be better to have a bean class
that holds them all, and getters/setters.  This gives you most of the
benefits of a EnumMap, but also gives you more flexibility if you need
to handle certain cases differently.

Hope this helps,
Daniel.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.