JSF 2 Pass enum value as parameter

Taken from http://stackoverflow.com/questions/3916871/passing-a-enum-value-as-a-parameter-from-jsf .
In short :
//this is your enum
public enum Type {
    PROFILE_COMMENT,
    GROUP_COMMENT
} 
//this is your managed bean
@ManagedBean
@SessionScoped
public class myBean {
    private Type type;
    // getter and setter
    public void Test(Type t){
        System.out.println(t);
    }
}
In facelet, we pass the enum as string:


add this to the faces-config.xml so that enum conversion can be handled by jsf

   java.lang.Enum
   javax.faces.convert.EnumConverter


0 comments:

Post a Comment