使用 Struts2 突出显示表中的行
我正在预处理用户上传的一些数据,我想告诉他们数据中是否有任何行无效。我认为检查每一行是有意义的,如果有错误,则将该行号添加到错误行的哈希集中,然后在输出时检查当前索引是否在哈希集中,并突出显示该行。
这是相关的jsp:
<table>
<tr>
<s:iterator value="prettyNames">
<th><s:property /></th>
</s:iterator>
</tr>
<s:iterator value="importList" status="stat">
<tr class="class="${lineErrors.contains(%{#stat.index}) ? 'highlight' : ''}"">
<s:iterator>
<td><s:property /></td>
</s:iterator>
</tr>
</s:iterator>
</table>
其中突出显示将背景颜色设置为红色。但是我在 Eclipse 中收到一条警告,提示“test”不支持运行时 表达式”,页面返回 500 错误,“根据标签文件中的 TLD 或属性指令,属性测试不接受任何表达式”。
突出显示表中任意行的正确方法是什么?
I'm preprocessing some data that users upload, and I want to tell them if any lines of the data are invalid. I figured it'd make sense to check each line, if there are errors add that line number to a hashset of errorlines, then when outputting check if the current index is in the hashset, and highlight that row.
Here's the relevant jsp:
<table>
<tr>
<s:iterator value="prettyNames">
<th><s:property /></th>
</s:iterator>
</tr>
<s:iterator value="importList" status="stat">
<tr class="class="${lineErrors.contains(%{#stat.index}) ? 'highlight' : ''}"">
<s:iterator>
<td><s:property /></td>
</s:iterator>
</tr>
</s:iterator>
</table>
Where highlight sets the background color red. However I get a warning in Eclipse saying ""test" does not support runtime
expressions" and the page returns a 500 error, "According to TLD or attribute directive in tag file, attribute test does not accept any expressions".
What is the correct way to highlight arbitrary lines in a table?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您看到此错误的原因是您正在尝试计算 Struts2 标记属性内的标准 JSP EL 表达式,在本例中为“test”。您需要将 OGNL 表示法与 S2 标记一起使用,如下所示(假设 lineErrors 针对 ValueStack 进行解析):
当然,更短的方法是这样,您将 S2 属性标记嵌套在类属性内,但这不太可读:
The reason you're seeing this error is because you're trying to evaluate a standard JSP EL expression inside of a Struts2 tag attribute, in this case "test". You need to use the OGNL notation with S2 tags, like so (assuming lineErrors resolves against the ValueStack):
Of course the shorter way would be something like this, where you nest the S2 property tag inside the class attribute, but this is less readable:
你的方式不是有效的 XHTML。您不能在任意位置开始
标记。我会将其重写为类似于
Facelets 之类的内容,因此 EL 在 struts 中的工作方式可能相同。我不确定我是否理解正在发生的
%{#...
疯狂现象The way you have it is not valid XHTML. You cannot have the
<tr>
tag started where ever you please. I would re-write this as something likeThat's what I would do in something like Facelets, so probably the EL works the same way in struts. I'm not sure I understand the
%{#...
maddness that's happening