Spring/JSF项目中的OmniFaces无法检索枚举属性

Spring/JSF项目中的OmniFaces无法检索枚举属性,jsf,tomcat,el,jsf-2.2,omnifaces,Jsf,Tomcat,El,Jsf 2.2,Omnifaces,给定以下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; } } 这

给定以下
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>
<o:importConstants var="literal" type="util.IntegerConstants"/>
DATA_TABLE_PAGE_LINKS : #{literal.DATA_TABLE_PAGE_LINKS.value}

显然,值
const
似乎被保留在某个地方,但这太难相信了,因为与值
const
相同的东西在上面提到的另一个应用程序中也可以正常工作

这与EL比与JSF/Spring/OmniFaces更相关。Tomcat使用的ApacheEL实现对于保留关键字来说确实是相当严格的。例如,
{bean.class.name}
(例如,print
bean.getClass().getName()
)可以在GlassFish使用的Oracle EL实现中实现,但不能在Tomcat使用的Apache EL实现中实现。您应该将其写成
#{bean['class'].name}
。的第1.17章中未列出的中列出的所有其他Java关键字也被Apache EL实现阻止。
const
就是其中之一

另一方面,建议以大写字母开头常量
var
。此约定允许更好地区分EL范围中的托管bean实例和常量引用。它还可以立即解决您的问题,因为
Const
Const
不同

<o:importConstants var="Const" type="util.IntegerConstants" />
DATA_TABLE_PAGE_LINKS : #{Const.DATA_TABLE_PAGE_LINKS.value}
<o:importConstants type="util.Const" />
DATA_TABLE_PAGE_LINKS : #{Const.DATA_TABLE_PAGE_LINKS.value}