2011-03-22 42 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>