EL 改善了代碼的可都性,在上面的例子中WW 調(diào)用Action的getGuessBean() 然后調(diào)用bean的 getNumGuesses() 。現(xiàn)在來(lái)比較這些精簡(jiǎn)的符號(hào)與第二個(gè)JSP列表. WW方式是更精簡(jiǎn),易于閱讀,表達(dá)得更清楚,我們不用擔(dān)心范圍、類、方法等,頁(yè)面設(shè)計(jì)者不應(yīng)該厭煩這些信息。 條件判定范例: ? WW方式 ? <webwork:if test="guessBean/sUCcess==true"/> ? Congratulations! You got it. ? And after just <webwork:property value="guessBean/numGuesses"/> tires.<p> ? Not sure what to do here? ? Care to <a href="<webwork:url page="numguess.action?begin=true"/>">try again</a>? ? </webwork:if>
? 普通JSP 方式 ? <% if (numguess.getSuccess()) { %> ? Congratulations! You got it. ? And after just <%= numguess.getNumGuesses() %> tries. <p> ? <% numguess.reset(); %> ? Not sure what to do here? ? Care to <a href="<%=response.encodeURL(numguess.jsp)%>"/>">try again</a>? ? <% } %>
? 可以計(jì)算兩個(gè)操作數(shù)的條件表達(dá)式Y(jié)ou can evaluate conditionally with two Operands. 例子中,假如if條件為true,就執(zhí)if的主體。 ? <webwork:if test="′hello′ == ′hello′"> ? <b>Success</b> ? </webwork:if>
? You can set precedence when evaluating conditional expressions with (). In this example, we group conditional expressions together. Note that the operands are themselves value expressions. ? <webwork:if test="bool(′true′) == true && (bool(′false′) == true settings[′foo′] == ′bar′)"> ? <b>Success</b> ? </webwork:if>