• Post Reply Bookmark Topic Watch Topic
  • New Topic

Want to display Enum in jsp using JSF??

 
Nirav Sanghavi
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have one field of String in database with length 1.
it has values (1,2,3,4)
I have 1 Enum
public enum BatchTypeGroup {

INV("Invoice", 1L),
CALENG("Calculation Engine", 2L),
VALENG("Validation Engine",3L),
INVENG("Invoice Generation Engine",4L);

private String desc;
private Long i;

BatchTypeGroup(String desc, Long i){
this.desc = desc;
this.i = i;
}


now i want to display its description in jsp if values coming from database is 1.

So my question is how to display Enum in jsp file using JSF ???
[ August 23, 2007: Message edited by: Nirav Sanghavi ]
 
Basker Ganesan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a geter method to return the Enum value as String in your bean and display that in your jsp.

Ex-
/**
* @return the status
*/
public ConfigStatusEnum getStatus()
{
return status;
}

// Use this method in your jsp

/**
* @return the status
*/
public String getStatusAsString()
{
return status.getValue();
}
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSF 1.2 supports enums. It has a built in EnumConverter.

If you're using JSF 1.1 or older, you'll have to write your own EnumConverter based on javax.faces.converter.Converter. It's fairly straighforward: in the getAsString() you returns enum's name() and in getAsObject() you use enum's valueOf().
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!