java - How to create a drop down menu from an enum? -


how display values of enum structure in jsp? use spring mvc implement project.

many thanks!

public enum projectstatusenum {     initial(0,"initial"),ongoing(1,"ongoing"),closed(2,"closed");      private int value;     private string key;      projectstatusenum(int value , string key){         this.value=value;         this.key = key;     }     public int getvalue() {         return value;     }      public void setvalue(int value) {         this.value = value;     }       public string getkey() {         return key;     }     public void setkey(string key) {         this.key = key;     }  } 

add enum values in attribute of request:

// projectstatusenum.values() return array of projectstatusenum request.setattribute("enum", projectstatusenum.values()); 

and finally, within jsp:

<ul class="dropdownmenu">     <c:foreach items="${enum}" var="entry">         <li>${entry.key} (${entry.value})</li> <!-- example -->     </c:foreach> </ul> 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -