JSF 2:在渲染属性中使用枚举 [英] JSF 2: Using enums in the rendered attribute

查看:111
本文介绍了JSF 2:在渲染属性中使用枚举的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法以声明方式检查枚举是否具有指定的值。例如:

 < h:graphicImage name =error.pnglibrary =images
rendered = #{viewController.current.status == Status.ERROR}/>

在管理的beand中定义一个方法,对每个枚举值进行检查是有点乏味,例如

  public boolean isStateIsError(){
return current.getStatus()== Status.ERROR;
}

有更短的/更好的方法吗?

解决方案

直到EL 3.0 ,无法在EL范围中导入枚举。但是,您可以将它们与字符串进行比较,比如枚举常数值必须如下所示。

 < h: graphicImage name =error.pnglibrary =images
rendered =#{viewController.current.status eq'ERROR'}/>


Is there any way to check declaratively whether an enum has a specified value. For example:

<h:graphicImage name="error.png" library="images" 
  rendered="#{viewController.current.status == Status.ERROR}" />

It's a little bit tedious to define a method in the managed beand that checks this for every enum value, e.g.

public boolean isStateIsError() {
  return current.getStatus() == Status.ERROR;
}

Is there a shorter/better way of doing this?

解决方案

Until EL 3.0 it's not possible to import enums in EL scope. You can however just treat and compare them like strings, i.e. the enum constant value must be quoted like below.

<h:graphicImage name="error.png" library="images" 
  rendered="#{viewController.current.status eq 'ERROR'}" />

这篇关于JSF 2:在渲染属性中使用枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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