在struts2中验证失败时重新填充控件
我是这个框架的新成员。在我的页面中,我有一个下拉列表和一个文本框。如果出现任何错误,drop将不再可用。如何解决这个问题 Struts.xml:在struts2中验证失败时重新填充控件,struts2,Struts2,我是这个框架的新成员。在我的页面中,我有一个下拉列表和一个文本框。如果出现任何错误,drop将不再可用。如何解决这个问题 Struts.xml: <action name="*DropDown" class="com.mmm.ehspreg2.web.action.DropdownListAction" method="{1}" /> <action name="addComment" method="add" class="
<action name="*DropDown"
class="com.mmm.ehspreg2.web.action.DropdownListAction" method="{1}" />
<action name="addComment" method="add"
class="com.mmm.ehspreg2.web.action.product.CommentAction">
<result name="input" type="tiles">addComment</result>
<result name="error" type="tiles">addComment</result>
<result name="success" type="tiles">reloadList</result>
</action>
添加注释
添加注释
重新加载列表
第页:
:
:
:
以及CommentAction validation.xml启用的验证。我可以想到以下几个选项: 将下拉列表对象放入会话中 在
dropdownlistation
中填充下拉列表时,请在会话中对其进行引用。这样,如果验证失败,您可以在JSP上使用它。此解决方案的最后一步是在成功执行CommentAction
后将其从会话中清除
动作链接
您可以使用用于输入结果的。这将允许您在验证错误时自动调用DropDownStaction
<action name="addComment" method="add" class="com.mmm.ehspreg2.web.action.product.CommentAction">
<result name="input" type="chain">addCommentDropDown</result>
<result name="error" type="tiles">addComment</result>
<result name="success" type="tiles">reloadList</result>
</action>
添加注释下拉列表
添加注释
重新加载列表
问题是,这可能会扰乱输入字段的填充。你必须尝试一下。你有几个选择,我可以考虑:
将下拉列表对象放入会话中
在dropdownlistation
中填充下拉列表时,请在会话中对其进行引用。这样,如果验证失败,您可以在JSP上使用它。此解决方案的最后一步是在成功执行CommentAction
后将其从会话中清除
动作链接
您可以使用用于输入结果的。这将允许您在验证错误时自动调用DropDownStaction
<action name="addComment" method="add" class="com.mmm.ehspreg2.web.action.product.CommentAction">
<result name="input" type="chain">addCommentDropDown</result>
<result name="error" type="tiles">addComment</result>
<result name="success" type="tiles">reloadList</result>
</action>
添加注释下拉列表
添加注释
重新加载列表
问题是,这可能会扰乱输入字段的填充。你必须尝试一下。我找到了解决这个问题的最佳方法
操作应实现ValidationErrorRaware接口,该接口涉及覆盖ActionErrorOccursed函数
您只需粘贴所需的代码,如下面示例中的下拉方法,并返回输入而不是成功。我找到了解决此问题的最佳方法
操作应实现ValidationErrorRaware接口,该接口涉及覆盖ActionErrorOccursed函数
您只需粘贴所需的代码,如下面示例中的下拉方法,并返回输入而不是成功。您是否尝试了第一种方案?您还可以使用Prepare拦截器使其工作:@Pat,但在chain request中,您如何处理验证消息,@PunitPatel这是一个很好的观点-您必须使用类似Message Store拦截器的东西来确保验证消息在多个HTTP请求中幸存:@Pat Message Store拦截器也适用于重定向操作,那么为什么要使用操作链接,struts2文档也不推荐它,请参阅:您尝试了第一个场景吗?您还可以使用Prepare拦截器使其工作:@Pat,但在chain request中,您如何处理验证消息,@PunitPatel这是一个很好的观点-您必须使用类似Message Store拦截器的东西来确保您的验证消息在多次HTTP请求中幸存:@Pat Message Store拦截器也适用于重定向操作,所以为什么要使用操作链接,struts2文档也不推荐它,请参阅:Hi Jothi,请参阅:Hi Jothi,参考: