【发布时间】:2014-05-07 01:51:11
【问题描述】:
鉴于以下enum。
package util;
public enum IntegerConstants
{
DATA_TABLE_PAGE_LINKS(10);
private final int value;
private IntegerConstants(int con) {
this.value = con;
}
public int getValue() {
return value;
}
}
这里给出的常量应该在 XHTML 页面上检索,如下所示。
<ui:composition template="/WEB-INF/admin_template/Template.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:o="http://omnifaces.org/ui">
<ui:define name="title">Test</ui:define>
<ui:define name="content">
<h:form id="form" prependId="true">
<o:importConstants var="const" type="util.IntegerConstants"/>
DATA_TABLE_PAGE_LINKS : #{const.DATA_TABLE_PAGE_LINKS.value}
</h:form>
</ui:define>
</ui:composition>
这适用于在 GlassFish 4.0 上运行 JSF 托管 bean 的企业应用程序。
但在使用 Spring (4.0 GA)、JSF 2.2.6、PrimeFaces 5.0 final、PrimeFaces Extensions 2.0.0 final 在 Tomcat 8.0.3.0 上运行的项目中,同样的事情不起作用。
这应该与 Spring 无关。
给定的enum 位于应用程序构建文件夹下的WEB-INF/classes 文件夹中(其类文件)。
很难找出问题的实际原因,因为没有抛出错误或异常。浏览器上的页面只是空白,在服务器终端上什么也看不到。
OmniFaces 版本是 1.7。
尝试使用OmniFaces 1.8-SNAPSHOT,但问题仍然存在。
部分回答:
当我将 <o:importConstants> 的 var 属性的值从 const 更改为不同的值时,这有效,如下所示。
<o:importConstants var="literal" type="util.IntegerConstants"/>
DATA_TABLE_PAGE_LINKS : #{literal.DATA_TABLE_PAGE_LINKS.value}
显然,const 的值似乎已被保留在某个地方,但这太难以置信了,因为具有 const 值的相同内容在上述另一个应用程序中也能正常工作!
【问题讨论】:
标签: jsf tomcat el jsf-2.2 omnifaces