【问题标题】:Struts2 - Validation & Tiles ParameterStruts2 - 验证 & Tiles 参数
【发布时间】:2011-03-22 19:24:13
【问题描述】:

所以,我的场景在下面。

  1. 页面通过调用 newInfo.action 和 articleId 参数显示文章
  2. 表单操作将调用 postComment.action
  3. postComment.action 将调用 validate()
  4. validate() 返回验证错误。
  5. * 问题就在这里,我如何返回到 tile 并得到验证错误?

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

}

当前,页面结果是文章页面,有“字段错误”,但页面没有显示任何字段错误。 那么,有什么解决方案可以解决吗?

【问题讨论】:

    标签: validation struts2 tiles


    【解决方案1】:

    将 type="redirect" 更改为 type="chain",详情请参阅:http://struts.apache.org/2.0.14/docs/result-types.html

    【讨论】:

      【解决方案2】:

      试试这个:

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

      【讨论】:

        猜你喜欢
        • 2013-08-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-12-04
        • 2013-10-07
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多