从 JSF 传递 Enum 值作为参数(重访)
从 JSF 传递 Enum 值作为参数
问题已经涉及这个问题,但是提议的解决方案对我不起作用。我在支持 bean 中定义了以下枚举:
public enum QueryScope {
SUBMITTED("Submitted by me"), ASSIGNED("Assigned to me"), ALL("All items");
private final String description;
public String getDescription() {
return description;
}
QueryScope(String description) {
this.description = description;
}
}
然后我将其用作方法参数
public void test(QueryScope scope) {
// do something
}
并通过 EL 在我的 JSF 页面中使用它
<h:commandButton
id = "commandButton_test"
value = "Testing enumerations"
action = "#{backingBean.test('SUBMITTED')}" />
到目前为止一切顺利 - 与原始问题中提出的问题相同。但是,我必须处理 javax.servlet.ServletException: Method not find: %complete_qualified_package_name%.BackingBean.test(java.lang.String)
。
所以看来 JSF 正在解释方法调用,就好像我想调用一个以 String 作为参数类型的方法(当然不存在) - 因此不会发生隐式转换。
是什么因素导致该示例中的行为与上述示例不同?
Passing a Enum value as a parameter from JSF
This question already deals with this issue, however the proposed solution has not worked for me. I define the following enumeration in my backing bean:
public enum QueryScope {
SUBMITTED("Submitted by me"), ASSIGNED("Assigned to me"), ALL("All items");
private final String description;
public String getDescription() {
return description;
}
QueryScope(String description) {
this.description = description;
}
}
Then I use it as a method parameter
public void test(QueryScope scope) {
// do something
}
And use it via EL in my JSF page
<h:commandButton
id = "commandButton_test"
value = "Testing enumerations"
action = "#{backingBean.test('SUBMITTED')}" />
So far so good - identical to the problem posed in the original question. However I have to deal with a javax.servlet.ServletException: Method not found: %fully_qualified_package_name%.BackingBean.test(java.lang.String)
.
So it seems that JSF is interpreting the method call as if I would like to call a method with String as parameter type (which of course does not exist) - therefore no implicit conversion takes place.
What could be the factor that makes the behavior differ in this example from the aforelinked?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的
backingBean
中,您可能已经编写了带有enum
参数的方法:但是,
建议的解决方案
不使用枚举,而是使用字符串。那是因为 EL 根本不支持枚举:
In your
backingBean
, you may have written a method with theenum
parameter:But, the
proposed solution
does not use enum, it usesString
. That's because EL doesn't support enum at all: