Java 将枚举值作为参数从JSF传递
我正在尝试将现有代码迁移到使用Enum,由于缺乏使用Enum的经验,我遇到了一些问题。首先是我的结构。在我的Java 将枚举值作为参数从JSF传递,java,jsf,enums,el,Java,Jsf,Enums,El,我正在尝试将现有代码迁移到使用Enum,由于缺乏使用Enum的经验,我遇到了一些问题。首先是我的结构。在我的EJB中,除了实体之外,我还有一个enum类(不确定它是否是一个类) 在我的托管beanmyBean.java,我有 @ManagedBean(name="myBean") @SessionScoped public class myBean { private Type type; public myBean() { } public Type ge
EJB
中,除了实体之外,我还有一个enum类(不确定它是否是一个类)
在我的托管beanmyBean.java
,我有
@ManagedBean(name="myBean")
@SessionScoped
public class myBean {
private Type type;
public myBean() {
}
public Type getType() {
return type;
}
public void setType(Type type) {
this.type = type;
}
public void Test(Type t){
System.out.println(t);
}
}
然后在我的JSF上
<h:commandButton value="Test" action="#{myBean.Test(myBean.type.PROFILE_COMMENT)}" />
在EL中不能访问这样的枚举。然而,JSF为EL内置了枚举转换器。您可以将枚举名称用作字符串
<h:commandButton value="Test" action="#{myBean.Test('PROFILE_COMMENT')}" />
在我的情况下帮助了我
简单地将枚举与其值进行比较。EL在验证xhtml时识别它并检查该值是否存在
<c:if test="#{requestManager.selectedRequestType == 'ItemCreate' or requestManager.selectedRequestType == 'ItemChange'}"></c:if>
@BalusC:虽然这在我使用glassfish时有效,但在迁移到tomcat 7后失败了,您能指出原因吗?下面是详细信息的链接:
<h:commandButton value="Test" action="#{myBean.Test('PROFILE_COMMENT')}" />
<c:if test="#{requestManager.selectedRequestType == 'ItemCreate' or requestManager.selectedRequestType == 'ItemChange'}"></c:if>