[英]How to convert this Struts2 to displaytag (date comparison)
I had Struts2 code to show a button based on the result of a date comparison like this (note that this is a simplified example of what I actually have): 我有Struts2代码根据这样的日期比较结果显示一个按钮(请注意,这是我实际拥有的简化示例):
<s:iterator value="myList">
<s:if test="%{getDate().compareTo(getNow()) > 0}">
// Show the item
</s:if>
</s:iterator>
I have since converted the display of the result set to use displaytag. 此后,我将结果集的显示转换为使用displaytag。 How would I do the above using display tag. 我将如何使用显示标签执行上述操作。 This is what I've tried. 这就是我尝试过的。
<display:table name="myList" pagesize="50" id="row">
<display:column title="Item">
<s:if test="%{#attr.row.endDt.compareTo(#attr.row.now()) > 0}"><%--does NOT work--%>
</display:column>
</display:table>
What is the correct syntax of the <s:if>
statement? <s:if>
语句的正确语法是什么?
Or can this not be done using displaytag + Struts2? 还是使用displaytag + Struts2无法做到这一点?
Using the #attr.row
as index to reference the element in the list should work: 使用#attr.row
作为索引来引用列表中的元素应该可以工作:
<display:table name="myList" pagesize="50" id="row">
<display:column title="Item">
<s:if test="myList[%{#attr.row_rowNum - 1}].endDt.compareTo(myList[%{#attr.row_rowNum - 1}].now()) > 0}">
<span>Let's rock</span>
</s:if>
</display:column>
</display:table>
Note: is getNow()
a function coming from the iterated object ? 注意: getNow()
是来自迭代对象的函数吗?
This seems strange to me, shouldn't it be a common function, from the baseAction from example ? 这对我来说似乎很奇怪,这不是从example的baseAction中获取的通用函数吗?
Another way would be use a displaytag decorator. 另一种方法是使用displaytag装饰器。
public String getLink()
{
YourObject yourObject = (YourObject) getCurrentRowObject();
//Do your checks....
return "<a href="#">your link</a>";
}
There are likely multiple solutions but, this ended up working for me: 可能有多种解决方案,但这最终为我工作:
<display:table name="myList" pagesize="50" id="row">
<display:column title="Item">
<s:set name="endDt" value="#attr.row.endDt"/>
<s:set name="now" value="now" />
<s:if test="%{#endDt.compareTo(#now) > 0}">
<span>w00 h00!</span>
</s:if>
</display:column>
</display:table>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.