Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将枚举值作为参数从JSF传递_Java_Jsf_Enums_El - Fatal编程技术网

Java 将枚举值作为参数从JSF传递

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

我正在尝试将现有代码迁移到使用Enum,由于缺乏使用Enum的经验,我遇到了一些问题。首先是我的结构。在我的
EJB
中,除了实体之外,我还有一个enum类(不确定它是否是一个类)

在我的托管bean
myBean.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>