• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Want to display Enum in jsp using JSF??

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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();
}
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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().
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic