Java struts 从索引获取属性
我的任务是改进页面上的表单验证。
该站点使用 .jsp/bean/struts 等。当前页面顶部有一个循环将错误打印到屏幕上:
<nested:iterate id="currentError" property="wizard.errors" type="java.lang.String" indexId="counter">
<tr>
<td valign="top" class="wizardErrorText" width="2%">
>
</td>
<td class="wizardErrorText">
<span errorId="">
<bean:write name="currentError"/>
</span>
</td>
</tr>
</nested:iterate>
现在,当验证失败时,我稍微更改了现有方法以指示失败字段的 id验证以及错误消息。然后,我设置了一个类似的循环,将验证失败的字段的 id 打印到由 JavaScript 读取的区域,并相应地突出显示这些字段。
我不想使用另一个循环,而是使用 indexId 来查找数组中的值并将其包含在 errorId 中。
有人可以建议如何做到这一点吗?
我尝试过 jsp.getProperty 和其他一些方法,但没有成功。
谢谢 加里
I have been tasked with improving the form validation on a page.
The site uses .jsp/bean/struts etc. Currently there is a loop at the top of the page to print errors to the screen:
<nested:iterate id="currentError" property="wizard.errors" type="java.lang.String" indexId="counter">
<tr>
<td valign="top" class="wizardErrorText" width="2%">
>
</td>
<td class="wizardErrorText">
<span errorId="">
<bean:write name="currentError"/>
</span>
</td>
</tr>
</nested:iterate>
Now when validation fails I have changed the existing method slightly to indicate the id of the field that has failed validation as well as the error message. I have then set up a similar loop to print the id's of the fields that have failed validation to an area which is read by JavaScript and highlights the fields accordingly.
Rather than having another loop I would like to use the indexId to look up the value in the array and include it in the errorId.
Could anybody advise how to do this please?
I have tried jsp.getProperty and a few other methods but with no luck.
Thanks
Gary
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该能够执行以下操作:
或者,完整示例:
可以在此处找到更多信息: https://struts.apache.org/1.x/struts-taglib/indexedprops.html
You should be able to something like this:
Or, full example:
More information can be found here: https://struts.apache.org/1.x/struts-taglib/indexedprops.html