使用枚举时,Jexl3无法解决的属性异常

时间:2016-03-17 13:17:17

标签: jexl

此代码过去在jexl2下工作

    <h:form>
        <p:panelGrid id="grid1">
            <p:inputText required="true" id="inp1" value="#{test.value1}"/>
            <p:inputText required="true" id="inp2" value="#{test.value2}"/>
            <p:commandButton action="#{test.someAction()}" value="validation"  update="@form"/>
        </p:panelGrid>
    </h:form>
    <h:form>
        <p:panelGrid>
            <p:inputText required="true" id="inp3" value="#{test.value3}"/>
            <p:inputText required="true" id="inp4" value="#{test.value4}"/>
            <p:inputText required="true" id="inp5" value="#{test.value5}"/>
            <p:commandButton  action="#{test.someAction()}" value="validation" update="@form"/>
        </p:panelGrid>
    </h:form>

但在jexl3下会引发异常:

public enum Gender { MALE, FEMALE};

public static void main( String[] args ) throws ClassNotFoundException {
    JexlEngine jexl = new JexlEngine();
    Record r = new Record();
    r.setHeader(new RecordHeader());
    JexlContext jc = new MapContext();
    jc.set("r", r );
    jc.set("com.sytrue.objects.Gender", Gender.class );
    Expression e = jexl.createExpression( "r.header.gender=com.sytrue.objects.Gender.FEMALE" );
    System.out.println( e.evaluate(jc) );
}

例外是:

public static void main( String[] args ) throws ClassNotFoundException {
    JexlEngine jexl = new JexlBuilder().create();
    Record r = new Record();
    r.setHeader(new RecordHeader());
    JexlContext jc = new MapContext();
    jc.set("r", r );
    jc.set("com.sytrue.objects.Gender", Gender.class );
    JexlExpression e = jexl.createExpression( "r.header.gender=com.sytrue.objects.Gender.FEMALE" );
    System.out.println( e.evaluate(jc) );
}

我使用valueOf方法使其工作:

Exception in thread "main" org.apache.commons.jexl3.JexlException$Property: com.sytrue.objects.record.app.JexlTestApp.main@1:42 unsolvable property 'FEMALE'

似乎我再也无法访问jexl3中的枚举类型了。 有什么理由不再起作用或者它是一个错误

1 个答案:

答案 0 :(得分:0)

事实证明这是一个错误: 我在JIRA上发布了这个问题: https://issues.apache.org/jira/browse/JEXL-191 它将在版本3.1中修复