Struts2 和预填表单的表单验证
我正在使用 struts2 的 validate() 方法来验证表单输入。在我的 struts.xml
中,我可以定义一个名称为“input”的结果,如果验证失败,则会显示该结果。这是上下文:-)
现在我的问题:我想要验证的表单包含一个从数据库填写的选择框。第一次显示表单时一切正常。但是,如果我验证表单并显示“输入”结果,我会收到 IOException ,因为迭代器将数据库结果输出到我的选择框中。 struts2有解决方案吗?还是我必须使用插件或类似的东西?谢谢你!
I'm using the validate()
- method of struts2 to validate the form input. In my struts.xml
I can define a result with name "input" which is displayed if the validation fails. This for the context :-)
Now my question: the form I want to validate contains a selectbox which is filled out of a database. The first time the form is displayed everything works fine. But if I validate the form and the "input" - result is displayed, I get an IOException
because of the iterator which outputs the db-result into my selectbox. Is there a solution from struts2 or do I have to use a plugin or something like that? Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当验证失败时,通常需要“重新加载”表单页面的数据。有一个 FAQ 条目涵盖了验证后重新填充控件,主要详细介绍了
Preparable
接口(首选)以及
标签的使用(有一些微妙的地方)可能会出现这样的问题,但总的来说,这也没关系)。When validation fails, it's often necessary to "reload" data for the form page. There's a FAQ entry that covers repopulating controls after validation, mainly detailing the
Preparable
interface (preferred) and the use of the<s:action>
tag (there are some subtle gotchas that can pop up with this, but in general, it's also okay).