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