从JSF传递枚举值作为参数 [英] Passing a Enum value as a parameter from JSF

查看:132
本文介绍了从JSF传递枚举值作为参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我现有的代码迁移到使用Enum,而且由于我缺乏Enum的经验,我遇到了一些问题。首先这是我的结构。在我的 EJB 中,与实体一起,我有一个枚举类(不知道如果它是一个类)。

I am trying to migrate my existing code to using Enum and I run into some problems due to my lack experience with Enum. First of all here is my structures. In my EJB, alongs with Entity, I have a enum class (not sure if it even a class).

public enum Type {
    PROFILE_COMMENT,
    GROUP_COMMENT
} 

在我的托管bean myBean.java ,我有

At my managed bean myBean.java, I have

@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, p>

then at my JSF,

<h:commandButton value="Test" action="#{myBean.Test(myBean.type.PROFILE_COMMENT)}" />

我有 java.lang.ClassNotFoundException:类型不是一个类

我有的原因键入在我的EJB中,以便我可以为我的实体创建一个枚举类型,所以我的查询看起来像这样

The reason I have Type in my EJB so that I can create an enumerated type for my Entity, so my query would look like this

select c from X c where c.type = Type.PROFILE_COMMENT


推荐答案

您不能访问EL中的枚举。 JSF内置了EL的内置枚举转换器。您可以使用枚举名称作为字符串。

You can't access enums like that in EL. JSF has however builtin enum converters for EL. You can just use the enum name as string.

<h:commandButton value="Test" action="#{myBean.Test('PROFILE_COMMENT')}" />

这篇关于从JSF传递枚举值作为参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆