尽管ui:fragment rendering ="false",但仍对值表达式求值. [英] Value expressions still evaluated despite ui:fragment rendered="false"
问题描述
我有豆子:
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'} =假
但是我得到下一个例外:
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中的rendered = false属性,那么将不会处理此块.
<ui:fragment rendered>
阻止它呈现HTML输出,但不能阻止它最终出现在JSF组件树中并可以保存状态. /p>
改为使用<c:if test>
.它在视图构建时而不是视图渲染时运行,因此,整个过程根本不会出现在JSF组件树中.
或者,如果您在<ui:repeat var="property">
中拥有全部功能,并且正在使用Mojarra,则至少应升级到2.1.29或2.2.7,其中已修复此状态保存错误.
另请参见:
I have bean:
class Property{
private String type;
private Date value;
//getters and setters
}
also have block of code on page:
<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>
The condition #{property.type eq 'checkbox'} = false
But I get next exception:
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
I expect if the attribute rendered=false in ui:include, then this block will not be processed.
<ui:fragment rendered>
prevents it from rendering the HTML output, but it doesn't prevent it from ending up in JSF component tree and being eligible for state saving.
Use <c:if test>
instead. It runs during view build time instead of view render time and thus the whole bunch won't end up in JSF component tree at all.
Or, if you have this all inside an <ui:repeat var="property">
, and you are using Mojarra, then upgrade to at least 2.1.29 or 2.2.7 wherein this state saving bug was fixed.
See also:
- JSTL in JSF2 Facelets... makes sense?
- PropertyNotFoundException on conditionally rendered subclasses in ui:repeat
这篇关于尽管ui:fragment rendering ="false",但仍对值表达式求值.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!