【发布时间】:2014-06-01 04:13:02
【问题描述】:
鉴于以下enum。
public enum Constants
{
PAGE_LINKS(10);
//Other constants as and when required.
private final int value;
private Constants(int value){
this.value = value;
}
public int getValue(){
value;
}
}
这个enum 像这样放置在应用程序范围的bean 下,
@ManagedBean
@ApplicationScoped
public final class ConstantsBean
{
private Constants constants;
public ConstantsBean() {}
public Constants getConstants() {
return constants;
}
}
如何在EL中获取PAGE_LINKS的值?
<p:dataGrid pageLinks="#{}".../>
#{}应该写什么?有可能吗?
编辑:
通过以下方式修改bean,
@ManagedBean
@ApplicationScoped
public final class ConstantsBean
{
public ConstantsBean() {}
public int getValue(Constants constants) {
return constants.getValue();
}
}
然后像这样在EL中访问,
<p:dataGrid pageLinks="#{constantsBean.getValue('PAGE_LINKS')}".../>
不知何故可行,但我不相信这种丑陋的方式。
【问题讨论】:
-
#{constantsBean.constants.value}应该适合你。 -
那行不通,@SazzadurRahaman