参见
http://stackoverflow.com/questions/2524420/jsf-testing-for-enum-equality
If you have the enum
public enum Status {
YES, NO
}
you can reference the enums in your jsf pages like so:
<h:outputText value="text" rendered="#{myBean.status == 'YES'}"/>
I'm not so sure about the String evaluation, due to something I stumbled upon while refactoring some code to use enums: if you have a typo in your status String, ie:
<h:outputText value="text" rendered="#{myBean.status == 'YESSIR'}"/>
you will actually get a runtime error when you hit the page because the EL parser will try to coerce 'YESSIR' into a Status enum and fail.
本文讨论了在JSF页面中使用表达式语言(EL)进行枚举与字符串比较的方法。当试图将字符串与枚举进行比较时,需要注意字符串的准确性,否则会导致运行时错误。文章还提供了一个具体的示例来说明这一问题。
2万+

被折叠的 条评论
为什么被折叠?



