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.