【问题标题】:Value expressions still evaluated despite ui:fragment rendered="false"尽管 ui:fragment rendering="false" 仍然计算值表达式
【发布时间】:2015-04-18 06:12:03
【问题描述】:

我有豆子:

class Property{
 private String type;
 private Date value;
 //getters and setters
}

页面上还有代码块:

<ui:fragment rendered="#{property.type eq 'checkbox'}">
    <ui:include src="checkbox.xhtml">
        <ui:param name="property" value="#{property}"/>
    </ui:include>
</ui:fragment>

checkbox.xhtml:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core">
    <body>
        <ui:composition>
            <h:selectBooleanCheckbox value="#{property.value}"/>
        </ui:composition>
    </body>
</html>

条件#{property.type eq 'checkbox'} = false

但我得到下一个例外:

javax.servlet.ServletException: checkBox.xhtml value="#{property.value}": Cannot convert 01.11.02 0:00 of type class java.util.Date to class java.lang.Boolean

我希望如果 ui:include 中的属性 render=false,那么这个块将不会被处理。

【问题讨论】:

    标签: jsf conditional-rendering


    【解决方案1】:

    &lt;ui:fragment rendered&gt; 阻止它呈现 HTML 输出,但它不会阻止它在 JSF 组件树中结束并有资格进行状态保存。

    请改用&lt;c:if test&gt;。它在视图构建时间而不是视图渲染时间运行,因此整个组件根本不会出现在 JSF 组件树中。

    或者,如果您将这一切都包含在 &lt;ui:repeat var="property"&gt; 中,并且您正在使用 Mojarra,则至少升级到 2.1.29 或 2.2.7,其中修复了此状态保存错误。

    另见:

    【讨论】:

    • 谢谢。我在 ui:repeat 中使用这个块。我会尝试更新 Mojarra。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-06
    • 1970-01-01
    相关资源
    最近更新 更多