问题描述
我正在尝试将我现有的代码迁移到使用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传递枚举值作为参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!