This content has been marked as final.
Show 2 replies
-
1. Re: Using enums on JSP pages
treespace Apr 6, 2005 4:29 PM (in response to treespace)I have come up with a solution so elegant it brings tears to my eyes:)
Color is an enum. I convert it to a map that can be useBean'd and dereferenced in EL. So my app uses the enum while the JSP uses the same enum in map form. Sweet!
public class ColorMap<String, String> extends TreeMap {
public ColorMap() {
for(Color value : Color.values()) {
put(value.name(), value.name());
}
}
}
Usage: note that EL does map lookups using dot notation making for some very clean syntax:
<useBean id="colors" class="ColorMap"...
...
<input type="submit" value="${colors.Seafoam}" ... -
2. Re: Using enums on JSP pages
treespace Apr 6, 2005 4:33 PM (in response to treespace)Correction:
public class ColorMap extends TreeMap<String, String> { public ColorMap() { for(Color value : Color.values()) { put(value.name(), value.name()); } } }