【问题标题】:EL conditional statment in an input value results in Illegal Syntax for Set Operation输入值中的 EL 条件语句导致集合操作的非法语法
【发布时间】:2012-03-18 14:33:22
【问题描述】:

我最近将我的 Web 应用程序升级到 JSF 2.0 (MyFaces 2.0.9) 并使用 tomcat 6(Servlet 2.5 容器)。

以前(在升级到 JSF 2 之前)在 JSP 文件中我有如下声明:

    <h:selectOneMenu id="country"
           value="#{myBean.countrySelectionControl ? (empty myBean.restrictedCountry ? '' : myBean.restrictedCountry)  : myBean.countryCode}"
           onchange="submit()"
           disabled="#{myBean.countrySelectionControl}">
            <f:selectItem itemValue="" itemLabel="------------------Select-----------------" />
            <f:selectItem itemValue="here" itemLabel="Here" />
            <f:selectItem itemValue="there" itemLabel="There" />
    </h:selectOneMenu>

但自从升级以来,此类语句导致错误如下:

错误:org.ajax4jsf.webapp.BaseXMLFilter - 过滤器链中的异常 javax.servlet.ServletException: /jsp/CrudUser.jsp(79,9) '#{myBean.countrySelectionControl ? (empty myBean.restrictedCountry ? '' : myBean.restrictedCountry) : myBean.countryCode}' Set 操作的非法语法

现在我知道我可以将逻辑移回 Backbean,但在此之前,我想检查一下是否还有其他选择,并了解在这种情况下什么是“最佳实践”。

【问题讨论】:

  • 请不要将JSTLEL 混淆。
  • 尝试升级到更新版本,比如 2.0.12,因为表达式应该可以工作

标签: jsf el


【解决方案1】:

一般的经验法则是在你的 java 代码(模型 + 控制器)中保留尽可能多的逻辑,而不是在模板(视图)中保留逻辑。您在 xhtml 中有相当复杂的逻辑,因此将其迁移到 bean 将符合此规则。

【讨论】:

    猜你喜欢
    • 2013-08-20
    • 2013-01-10
    • 1970-01-01
    • 1970-01-01
    • 2011-06-04
    • 2017-07-02
    • 2017-02-21
    • 2023-03-10
    相关资源
    最近更新 更多