You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Philip S. Constantinou" <ph...@wayfinder.net> on 2002/08/11 00:47:00 UTC

Recommended to use static enumeration

What is the recommended way to access static enumerations from taglibs? I've
defined a static enumeration class (see below) and I'd like to have an
elegant way to access them in the view. Right now I have to put Java in my
JSP  pages which I'd prefer not to do.

This is what I do now:
<% pageContext.setAttribute("statuses", myPackage.Status.getStatuses()); %>
<logic:iterate id="status" name="statuses" type="myPackage.Status">
<bean:write name="status" property="name"/><br>
</logic:iterate>

Is there a better way?

Thanks -
Phil

My static enumerations look like this:

public class Status {
private static HashSet_map = new HashSet();
public static final Status PASS = new Status("PASS","Pass");
public static final Status FAIL = new Status("FAIL","Fail");
public static final Status REJECT= new Status("RJCT","Reject");
protected Status(String code, String name) {
 this.code = code;
 this.name = name;
 _map.put(code, this);
}
public String getName() {
    return name;
}
public String getCode() {
    return code;
}
public static final Collection getStatuses() {
    return _values.values();
}
public static Status getStatus(String code) {
    return (Status)_map.get(code);
}
}


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>