Struts2 - 验证和验证瓷砖参数
所以,我的场景如下。
- 页面通过调用带有articleId参数的newInfo.action来显示文章
- 表单操作将调用postComment.action
- postComment.action将调用validate()
- validate()返回验证错误。
- * 问题就在这里,我如何返回图块并收到验证错误?
我的struts.xml
<action name="newInfo" class="org.blog.controller.NewInfo">
<result type="tiles" name="success">NewInfo</result>
</action>
<action name="postComment" class="org.blog.controller.CommentController">
<result type="redirectAction" name="success">newInfo?id=${articleId}</result
<result type="redirect" name="input">newInfo.action?id=${articleId}</result>
</action>
CommentController.java
public void validate() {
if(getName().length() == 0)
addFieldError("name", "Name is required");
if(getEmail().length() == 0)
addFieldError("email", "Email is required");
if(getCurrentURL().length() == 0)
addFieldError("website", "Website is required");
if(hasFieldErrors())
System.out.println("Field error.");
}
当前,页面结果为文章页面,有“字段错误”,但页面没有显示任何字段错误。 那么,有什么解决方案可以解决吗?
So, my scene is below.
- The page show Article by call newInfo.action with articleId parameter
- The form action will call postComment.action
- postComment.action will call validate()
- validate() return the validation error.
- * The problem is here, how can i return to tile and getting validation error?
My struts.xml
<action name="newInfo" class="org.blog.controller.NewInfo">
<result type="tiles" name="success">NewInfo</result>
</action>
<action name="postComment" class="org.blog.controller.CommentController">
<result type="redirectAction" name="success">newInfo?id=${articleId}</result
<result type="redirect" name="input">newInfo.action?id=${articleId}</result>
</action>
CommentController.java
public void validate() {
if(getName().length() == 0)
addFieldError("name", "Name is required");
if(getEmail().length() == 0)
addFieldError("email", "Email is required");
if(getCurrentURL().length() == 0)
addFieldError("website", "Website is required");
if(hasFieldErrors())
System.out.println("Field error.");
}
Current, the page result the article page, with "field error", but the page doesnt show any field error.
So, is there any solutions to fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将 type="redirect" 更改为 type="chain" 请参阅: http:// /struts.apache.org/2.0.14/docs/result-types.html 了解更多详细信息。
Change type="redirect" to type="chain" see: http://struts.apache.org/2.0.14/docs/result-types.html for more details.
试试这个:
Try this: