0 Replies Latest reply on Jan 18, 2009 4:17 PM by scott duke

    Problem with Enum on sorted list

    scott duke Novice

      I have an entity called Code.java that has a column defined as Enumerated.


      public class Code implements Serializable {
           private CodeType type;
           public CodeType getType() {
                return type;
           public void setType(CodeType type) {
                this.type = type;

      and CodeType.java

      public enum CodeType {
           private String value;
           private CodeType(String value) {
                this.value = value;
           public String getValue() {
                return value;

      Inside the CodeList.xhtml, the datatable looks like:

                  <rich:dataTable id="codeList" 
                           rendered="#{not empty codeList.resultList}">
                       <f:facet name="header">
                           <a4j:htmlCommandLink styleClass="columnHeader" reRender="codeList"
                                             value="Type #{codeList.order=='c.type asc' ? messages.down : ( codeList.order=='c.type desc' ? messages.up : '' )}">
                               <f:param name="codeListOrder" value="#{codeList.order=='c.type asc' ? 'c.type desc' : 'c.type asc'}"/>

      And in the CodeList.java:

      public class CodeList extends EntityQuery<Item> {
           private static final long serialVersionUID = 1008397397027179231L;
           private static final String[] RESTRICTIONS = {
                     "code.type = #{codeList.c.type}",
                     "lower(code.code) like concat(lower(#{codeList.c.code}),'%')",
                     "lower(code.description) like concat(lower(#{codeList.c.description}),'%')", 
                     "code.active = #{codeList.c.active}",
                     //"code.strActive = #{codeList.code.strActive}",
           private Code c = new Code();
           public CodeList() {
                this.setEjbql("select c from Code c");
                this.setOrder("c.type asc");
           public Code getC() {
                return c;
           public CodeType[] getCodeTypes() {
                return CodeType.values();
           public BooleanType[] getBooleanTypes() {
                return BooleanType.values();
           public List<Code> getEditionCodes() {
                return this.getEntityManager().createNamedQuery("c.findCodesByType")
                          .setParameter("type", CodeType.EDITION).getResultList();
           public List<Code> getMediumCodes() {
                return this.getEntityManager().createNamedQuery("c.findCodesByType")
                          .setParameter("type", CodeType.MEDIUM).getResultList();
           public String getOrder() {
                if (super.getOrder() == null) {
                     setOrder("c.type asc");
                return super.getOrder();

      The problem is when I try to sort on the enum. It is sorting based on the ordinal value and not the string value. I want to store the ordinal value within the database. Is there a way I can do this?