Tuesday, October 10, 2017

How to use ENUM in struts2 label tag to pass value and retrieve Value ?

<s:label value="%{@com.pkg.CommonStatusValues@fromBooleanValue(falseStatus).stringName}"

                                     key="pkg.status" />


Here CommonStatusValues is Enum 

public enum CommonStatusValues {
   
   ENABLE(1,true,"Enable","true"),
   DISABLE(0,false,"Disable","false");
   
   private int id;
   private boolean booleanValue;
   private String stringName;
   private String stringNameBoolean;
   
   private CommonStatusValues(int id, boolean booleanValue, String stringName, String stringNameBoolean){
      this.id = id;
      this.booleanValue = booleanValue;
      this.stringName = stringName;
      this.stringNameBoolean=stringNameBoolean;
   }

   public static CommonStatusValues fromValue(int id){
      if(ENABLE.id == id){
         return ENABLE;
      }else if(DISABLE.id == id){
         return DISABLE;
      }else{
         return null;
      }
   }
   public static CommonStatusValues fromBooleanValue(Boolean booleanValue){
      if(ENABLE.booleanValue == booleanValue){
         return ENABLE;
      }else if(DISABLE.booleanValue == booleanValue){
         return DISABLE;
      }else{
         return null;
      }
   }
   public int getId() {
      return id;
   }

   public void setId(int id) {
      this.id = id;
   }

   public boolean isBooleanValue() {
      return booleanValue;
   }

   public void setBooleanValue(boolean booleanValue) {
      this.booleanValue = booleanValue;
   }

   public String getStringName() {
      return stringName;
   }

   public void setStringName(String stringName) {
      this.stringName = stringName;
   }

   public String getStringNameBoolean() {
      return stringNameBoolean;
   }
     
   
}

No comments:

Post a Comment

Scrum and Scrum master

Scrum  Scrum is a framework which helps a team to work together.  It is like a rugby team (the scrum name comes from rugby game). Scrum enco...