比较 Struts 2 嵌套迭代器
假设我有两个具有相同属性名称的对象,我正在使用 Struts 2 对其进行迭代。
class Book {
// assume that there is a public getter and setter
public String title;
public List<Chapter> chapterList;
}
class Chapter {
public String title;
}
在我的 JSP 页面中,我想要迭代 Book 和 Chapter。迭代时,当书名与章节标题相同时,如何显示特殊消息?
<s:iterator value="bookList">
<s:iterator value="chapterList">
<s:if test="book.title.equals(chapter.title)">
Same title
</s:if>
</s:iterator>
</s:iterator>
如何修复上面代码片段中的 s:if 标记以将书名与章节标题进行比较?
谢谢!
注意:这与以下 stackoverflow 问题非常相似(但在该问题中,他们仅打印属性名称而不进行比较,并且父对象和子对象上的属性名称不同):
Suppose that I have two objects with the same property name that I am iterating over with Struts 2.
class Book {
// assume that there is a public getter and setter
public String title;
public List<Chapter> chapterList;
}
class Chapter {
public String title;
}
In my JSP page, I want to iterate over the Book and Chapter. While iterating, how would I display a special message when the Book's title is the same as the Chapter's title?
<s:iterator value="bookList">
<s:iterator value="chapterList">
<s:if test="book.title.equals(chapter.title)">
Same title
</s:if>
</s:iterator>
</s:iterator>
How would I fix the s:if tag in the above snippet to compare the book title with the chapter title?
Thanks!
Note: This is very similar to the following stackoverflow question (but in that question they only print the property name without doing a comparison and the property name is differently on the parent and child objects):
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用标准 EL 运算符 < code>== 或
eq
来测试(字符串)值是否相等:或(对 XHTML 更友好)
You can use the standard EL operators
==
oreq
to test the (String) values for equality:or (a bit more XHTML friendly)