struts2 迭代器标签中包含 contains
我有以下代码似乎不起作用。 我不明白为什么这行不通。
<s:iterator value=%{questions} id="question">
<s:if test='%{incorrectQs.contains("#question.questionId")}'>
Print something here
</s:if>
</s:iterator>
在上面的代码中,基本上我在操作类中有一个名为 getQuestions 的方法。 该列表包含 Exam 类的对象,该类具有获取/设置 QuestionId。 我还有不正确的 Qs 列表,其中包含字符串。 我正在检查不正确的Qs是否包含questionId。 如果是的话我想打印一些文本。 尽管上面的代码不起作用,但下面的代码随机可以正常工作。 有时它有效,有时它不起作用...:(
<s:iterator value=%{questions}>
<s:if test='%{incorrectQs.contains("${questionId}")}'>
Print something here
</s:if>
</s:iterator>
任何人都可以对此提供一些见解吗?
I have the following code which does not seem to work. I fail to see why this wont work.
<s:iterator value=%{questions} id="question">
<s:if test='%{incorrectQs.contains("#question.questionId")}'>
Print something here
</s:if>
</s:iterator>
In the above code, basically I have a method called getQuestions in the action class. This list contains objects of Exam class which has a get/set questionId. I also have incorrectQs list which contains strings. I am checking if incorrectQs contains a questionId. if it does i want to print some text. Eventhough, the above code does not work, the code below works fine randomly. Sometimes it works and sometimes it does not...:(
<s:iterator value=%{questions}>
<s:if test='%{incorrectQs.contains("${questionId}")}'>
Print something here
</s:if>
</s:iterator>
can anyone provide some insight in this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定你的
Action
类是什么样子,但你可以尝试这样的事情。 当您位于s:iterator
标记内时,我认为每个%{foo}
表达式将尝试访问您正在迭代的特定实例(问题,而不是列表)的问题)。注意:可能有一种方法使用
#
从s:iterator
标记内引用父对象。 我只是还没有这样做,所以不能确定它是否会对您有所帮助。然后在您的 JSP 中:
I'm not sure what your
Action
class looks like, but you can try something like this. When you're inside thes:iterator
tag, I think each%{foo}
expression will attempt to access the specific instance you are iterating (the question, not the List of questions).Note: There may be a way using
#
to reference the parent object from within thes:iterator
tag. I just haven't done it, so can't say for sure if it would help you here.And then in your JSP: