File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes Want to display Enum in jsp using JSF?? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSF
Reply Bookmark "Want to display Enum in jsp using JSF??" Watch "Want to display Enum in jsp using JSF??" New topic
Author

Want to display Enum in jsp using JSF??

Nirav Sanghavi
Greenhorn

Joined: Aug 23, 2007
Posts: 1
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

Joined: Feb 28, 2003
Posts: 2
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

Joined: Oct 08, 2006
Posts: 2458
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().


Code depot of a Java EE / JSF developer | JSF / Eclipse / Tomcat kickoff tutorial | DAO kickoff tutorial | I ♥ Unicode
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Want to display Enum in jsp using JSF??
 
Similar Threads
mysql enum to java string
mysql enum to java string
Using Enum with html:select
Storing enums in database
Best way to compare string param to enum list to perform correct action