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 valida开发者_开发知识库tion 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?
Change type="redirect" to type="chain" see: http://struts.apache.org/2.0.14/docs/result-types.html for more details.
Try this:
<action name="postComment" class="org.blog.controller.CommentController">
<interceptor-ref name="store">
<param name="operationMode">STORE</param>
</interceptor-ref>
<interceptor-ref name="defaultStack" />
<result type="redirectAction" name="success">newInfo?id=${articleId}</result
<result type="tiles" name="input">NewInfo</result>
</action>
精彩评论