3
c:if如果测试总是失败,并且它永远不会进入循环。我使用下面的命名空间有条件检查c:如果总是失败
xmlns:fn="http://java.sun.com/jsp/jstl/functions"
xmlns:c="http://java.sun.com/jstl/core"
字符串(“数组”)被分割为“汤姆和杰里是GAP1朋友”
<s:decorate template="/layout/display-text.xhtml">
<c:set var="array" value="#{_mybean.value}"/>
<c:set var="space" value="#{fn:split(array, ' ')}"/>
<c:set var="len" value="#{fn:length(space)}"/>
<h:outputText value="total length = #{len}"/><br/>
<c:forEach begin="0" end="5" var="index">
<h:outputText value="index = #{index}, value = #{space[index]}"/><br/>
<c:set var="val" value="#{space[index]}"/>
<c:if test="#{fn:startsWith(val, 'GAP')}">
<h:outputText value="Found keyword parameter GAP" /><br/>
</c:if>
</c:forEach>
</s:decorate>
我对我的代码xmlns进行了以下更改:c =“http://java.sun.com/jsp/jstl/core 所有调试语句(h:outputText)都为我输出空值。当然,如果所有的fn:函数在我这里都能正常工作,我还有什么不足呢? – Achaius 2010-01-19 13:02:33
阅读http://www.ilikespam.com/blog/c:foreach-vs-ui:repeat-in-facelets。至于BalusC如上所述,删除c:forEach和c:if,它们在构建视图时进行评估,而不是在将值应用于页面时进行评估。 – mtpettyp 2010-01-20 14:50:56