2016-03-22 32 views
2

Wildfly 8,JSF 2.2EL-条件运算符:在复合材料部件的意外行为

如果复合材料部件条件运算? :c:foreach循环使用列表,其行为是不正确的。例如文件的

输出是

eng germ ital 

和未如预期

eng eng germ germ ital ital 

如果复合部件被重写为ui:includetaglib然后预期的结果来。

文件(test.xhtml):

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" 
    xmlns:ui="http://java.sun.com/jsf/facelets" 
    xmlns:fn="http://java.sun.com/jsp/jstl/functions" xmlns:my="http://java.sun.com/jsf/composite/myComp" 
    xmlns:c="http://java.sun.com/jsp/jstl/core"> 

<h:body> 
    <my:testConditionalOperator languagesList="#{['eng', 'germ', 'ital']}"></my:testConditionalOperator> 
</h:body> 
</html> 

复合组分(testConditionalOperator.xhtml):

<!DOCTYPE html> 
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:a="http://xmlns.jcp.org/jsf/passthrough" 
    xmlns:of="http://omnifaces.org/functions" xmlns:f="http://xmlns.jcp.org/jsf/core" 
    xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:o="http://omnifaces.org/ui" xmlns:h="http://xmlns.jcp.org/jsf/html" 
    xmlns:ui="http://xmlns.jcp.org/jsf/facelets" xmlns:fn="http://xmlns.jcp.org/jsp/jstl/functions" 
    xmlns:cc="http://java.sun.com/jsf/composite"> 
    <cc:interface> 
     <cc:attribute name="languagesList"></cc:attribute> 
    </cc:interface> 
    <cc:implementation> 
     <c:forEach var="language" items="#{cc.attrs.languagesList}" > 
      #{fn:length(cc.attrs.languagesList) gt 1 ? language : "a"} 
      <c:if test="#{fn:length(cc.attrs.languagesList) gt 1}"> 
       #{language} 
      </c:if> 
     </c:forEach> 
    </cc:implementation> 
</html> 

回答

2

这似乎是一个钻嘴鱼科错误,这确实在MyFaces的不明显。

解决的办法是,在end属性中设置大小,并利用varStatus来获取它。

<cc:implementation> 
    <c:forEach var="language" items="#{cc.attrs.languagesList}" end="#{cc.attrs.languagesList.size()}" varStatus="loop"> 
     #{loop.end gt 1 ? language : "a"} 
     <c:if test="#{loop.end gt 1}"> 
      #{language} 
     </c:if> 
    </c:forEach> 
</cc:implementation> 

注意只使用的size()代替fn:length()

+0

的EL 2.2能力谢谢!这是一个奇怪的错误。应该在莫哈拉报道吗? – Tony

+0

现在我有趣的感觉是在复合组件中使用条件。 – Tony

+0

是的,请。它与JSTL生命周期相关。它可以与''正常工作。 – BalusC