开发者

Struts2 - Validation & Tiles Parameter

开发者 https://www.devze.com 2023-02-18 06:33 出处:网络
So, my scene is below. The page show Article by call newInfo.action with articleId parameter The form action will call postComment.action

So, my scene is below.

  1. The page show Article by call newInfo.action with articleId parameter
  2. The form action will call postComment.action
  3. postComment.action will call validate()
  4. validate() return the validation error.
  5. * 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>
0

精彩评论

暂无评论...
验证码 换一张
取 消