0 Replies Latest reply on Apr 15, 2009 11:33 AM by maxmustang

    Enum

    maxmustang

      Hello,

      I try to use folowing enum but cant handle to save the right values 2 or 4 on the db. I made a converter but it saves me 0 or 1 into the db. (I tried out http://brondsema.net/blog/index.php/2005/09/30/jsf_and_java_5_0_enums)

      I guess i must create a spezific converter am i right? Or is my enum wrong? Ideally in jsf as value i use "US_CAR" rsp. "JP_TYPE" but is this possible? It saves me 0 or 1. Many thanks for your help.


      <h:selectOneRadio value="#{car.carType}">
      <f:selectItem itemValue="US_CAR" itemLabel="US Car"/>
      <f:selectItem itemValue="JP_TYPE" itemLabel="Japanese Car"/>

      </h:selectOneRadio>


      public enum CarType
      {
      US_CAR(2), JP_TYPE(4);

      private int type;

      private CarType(int type)
      {
      this.type = type;
      }

      public int getType()
      {
      return type;
      }

      public static CarType valueOf(int type)
      {
      switch ( type )
      {
      case 2 :
      return US_CAR;
      case 4 :
      return JP_CAR;
      default :
      return US_CAR;
      }
      }

      }