在struts 2中显示验证消息
我的应用程序中有一个表单,我想在其中验证用户输入。它有一个从数据库表填充的组合框。所以我必须首先转到操作类来填充它(例如:populateFormAction)。然后就会跳转到form.jsp页面。
但问题出在验证的时候。我已将 populateFormAction 设置为输入结果,如下所示
<result name="input" type="redirect">/populateFormAction</result>
但是当它返回到 form.jsp 时,它不会显示验证错误。我认为这是因为在 Action 处理程序和 form.jsp 之间使用了 populateFormAction。
I have a form in my application in which I want to validate the user inputs. It has a combo box which is populated from db table. So I have to go to the action class first to populate it(for eg: populateFormAction). Then it will go to form.jsp page.
But the problem is at the time of validation. I have set populateFormAction as input result as follows
<result name="input" type="redirect">/populateFormAction</result>
But when it returned to form.jsp, it doesn't show the validation errors. I think it is because of the use of populateFormAction in between Action handler and form.jsp.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的问题有两种解决方案
调用正在填充的方法
返回 INPUT 之前的组合(如果
存在任何验证错误)。和
那么不要使用类型重定向,而是
直接移至您的 form.jsp。的
当然,如果
你有填充组合并且
在同一操作中验证方法
类。
将操作错误作为参数传递给 populateFormAction
如下。这里看看
我不是确定
actionError
后面是否会有 's',所以两者都尝试一下There are two solutions to your problem
Call the method which is populating
the combo, efore returning INPUT (if
there is any validation error). And
then dont use type redirect, instead
directly move to your form.jsp. Of
course, this would be possible if
you have the populate combo and
validate methods in the same action
class.
Pass your action errors as parameters to the populateFormAction
as follows.Take a look here
I m not sure whether there will be 's' after
actionError
or not, so try both您可以使用“MessageStoreInterceptor”来保存消息。
you can use "MessageStoreInterceptor“ to preserve the messages.