Lori
Sep 12th, 2007, 11:22 AM
Hi.
I am trying to write good MVC Code and i wonder if there is a clean way to supply information about enums for the view.
Since i use AndroMDA (http://andromda.org) to generate my classes, i don't even get "real" enums but classes with static fields.
e.g.
public class ActiveFlag {
public static final ActiveFlag activated = new ActiveFlag(10);
public static final ActiveFlag deactivated = new ActiveFlag(20);
...
}
So now when for example i have a FormController i overwrite the referenceData method like this:
protected Map referenceData(HttpServletRequest request) throws Exception {
...
model.put("ActiveFlag_activated", ActiveFlag.activated);
model.put("ActiveFlag_deactivated", ActiveFlag.deactivated);
...
}
I have to do this if i - for example - want to set the correct selected state of a property which is represented by this enum and is displayed in a html select box.
But when it comes to larger enums with much more entries this implementation cannot be the only way. Can it?
Thanks in advance.
I am trying to write good MVC Code and i wonder if there is a clean way to supply information about enums for the view.
Since i use AndroMDA (http://andromda.org) to generate my classes, i don't even get "real" enums but classes with static fields.
e.g.
public class ActiveFlag {
public static final ActiveFlag activated = new ActiveFlag(10);
public static final ActiveFlag deactivated = new ActiveFlag(20);
...
}
So now when for example i have a FormController i overwrite the referenceData method like this:
protected Map referenceData(HttpServletRequest request) throws Exception {
...
model.put("ActiveFlag_activated", ActiveFlag.activated);
model.put("ActiveFlag_deactivated", ActiveFlag.deactivated);
...
}
I have to do this if i - for example - want to set the correct selected state of a property which is represented by this enum and is displayed in a html select box.
But when it comes to larger enums with much more entries this implementation cannot be the only way. Can it?
Thanks in advance.