EnumMap and jsp?

R

Rusty Wright

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.
 
D

Daniel Pitts

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.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,163
Latest member
Sasha15427
Top