2011-03-22 57 views
2

所以,我的场景如下。Struts2 - 验证和瓷砖参数

  1. 页面显示文章的呼叫newInfo.action与条款ArticleID参数
  2. 形式的行动将调用postComment.action
  3. postComment.action将调用的validate()
  4. 的validate()返回验证错误。
  5. *问题是在这里,我如何返回到瓷砖并获取验证错误?

我在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."); 

} 

目前,该页面产生的文章页面,为 “现场错误”,但页面犯规显示任何领域的错误。 那么,有没有解决方案来解决它?

回答

0

试试这个:

<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>