【问题标题】:Java Server Faces Expression Language Evaluate EnumJava Server Faces 表达式语言评估枚举
【发布时间】:2013-06-28 02:14:05
【问题描述】:

我想在 JSF 中评估 EL 中的枚举。

枚举是

package com.divudi.data;

/**
 *
 * @author Buddhika
 */
public enum InvestigationItemValueType {
    Varchar,
    Memo,
    Double,
    Integer,
    List,
    Image,
    Line,
    Rectangle,
    Circle,

}

EL是

                                <h:inputText value="#{pv.strValue}" rendered="#{pv.investigationItem.ixItemValueType='Varchar'}" ></h:inputText>

例外是

type Exception report

message

descriptionThe server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: /lab_patient_report_dataentry.xhtml @40,139 rendered="#{pv.investigationItem.ixItemValueType='Varchar'}" Error Parsing: #{pv.investigationItem.ixItemValueType='Varchar'}
root cause

javax.faces.view.facelets.TagAttributeException: /lab_patient_report_dataentry.xhtml @40,139 rendered="#{pv.investigationItem.ixItemValueType='Varchar'}" Error Parsing: #{pv.investigationItem.ixItemValueType='Varchar'}
root cause

javax.el.ELException: Error Parsing: #{pv.investigationItem.ixItemValueType='Varchar'}
root cause

com.sun.el.parser.ParseException: Encountered "=" at line 1, column 39.
Was expecting one of:
    "}" ...
    "." ...
    "(" ...
    "[" ...
    ">" ...
    "gt" ...
    "<" ...
    "lt" ...
    ">=" ...
    "ge" ...
    "<=" ...
    "le" ...
    "==" ...
    "eq" ...
    "!=" ...
    "ne" ...
    "&&" ...
    "and" ...
    "||" ...
    "or" ...
    "*" ...
    "+" ...
    "-" ...
    "?" ...
    "/" ...
    "div" ...
    "%" ...
    "mod" ...

note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 3.1.2.2 logs.

【问题讨论】:

  • = 运算符是否列在预期运算符列表中?你为什么一直尝试使用它?
  • 谢谢。将 = 替换为 == 解决了问题。

标签: jsf el


【解决方案1】:

仔细查看异常消息。 = 在预期的运算符中吗?

不,不是。您正在寻找==,正是您用来比较纯Java 代码中的对象的运算符。此运算符的文本等效项是 eq。

请注意,如果两只手中的一只手是Object 而不是原语,EL 中的== 与Java 中的== 并不完全相同。然后它将与 Java 中的 Object#equals() 完全相同。在 Java 中,== 仅通过引用比较对象,而不是通过它们的内部值,你知道的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-05
    • 1970-01-01
    • 2015-11-05
    • 1970-01-01
    相关资源
    最近更新 更多