【发布时间】:2014-01-17 16:15:15
【问题描述】:
以下代码显示使用<s:a> 的Struts 从1 到10 的链接。
<s:set var="currentPage" value="2"/>
<s:set var="begin" value="1"/>
<s:set var="end" value="10"/>
<s:iterator begin="%{begin}" end="%{end}" step="1" var="row" status="loop">
<s:if test="%{#currentPage eq #row}"> <!--???-->
<span><s:property value="%{#row}"/></span>
</s:if>
<s:else>
<s:url id="pageURL" action="someAction" escapeAmp="false">
<s:param name="currentPage" value="%{row}"/>
</s:url>
<s:a href="%{pageURL}" name="btnPage" cssClass="paging">
<s:property value="%{#row}"/>
</s:a>
</s:else>
</s:iterator>
当currentPage(即2)与条件表达式test="%{#currentPage eq #row}" 匹配时,它只会在<span> 中使用<s:property> 显示文本,而不是显示链接。没关系。
当我使用这些相同的标签但在其相应的操作类中使用适当的属性时,
<s:iterator begin="%{begin}" end="%{end}" step="1" var="row" status="loop">
<s:if test="%{currentPage eq #row}"> <!--???-->
<span class="current"><s:property value="%{#row}"/></span>
</s:if>
<s:else>
<s:url id="pageURL" action="someAction" escapeAmp="false">
<s:param name="currentPage" value="%{row}"/>
</s:url>
<s:a href="%{pageURL}" name="btnPage" cssClass="paging">
<s:property value="%{#row}"/>
</s:a>
</s:else>
</s:iterator>
在这种情况下,currentPage(和所有其他)是操作类中Long 类型的属性。在这里,关于前一个案例test="%{#currentPage eq #row}" 的条件测试被评估为false。
需要在currentPage之前省略#。因此,表达式变为test="%{currentPage eq #row}"(否则,它总是评估为假)。
我不明白为什么第一种情况需要test="%{#currentPage eq #row}" 而第二种情况需要test="%{currentPage eq #row}"?有什么我可能会丢失的吗?
【问题讨论】:
标签: jsp struts2 ognl valuestack