Struts2 — параметр проверки и плитки

Итак, моя сцена ниже.

  1. Страница показывает статью по вызову newInfo.action с параметром articleId
  2. Действие формы вызовет postComment.action
  3. postComment.action вызовет validate()
  4. validate() возвращает ошибку проверки.
  5. * Проблема здесь, как я могу вернуться к плитке и получить ошибку проверки?

Мои распорки.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>

КомментарийController.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.");

}

Текущая страница приводит к странице статьи с «ошибкой поля», но страница не показывает никаких ошибок поля. Итак, есть ли решения, чтобы исправить это?


person thang.nguyen    schedule 22.03.2011    source источник


Ответы (2)


Измените type="redirect" на type="chain", см.: http://struts.apache.org/2.0.14/docs/result-types.html для получения более подробной информации.

person Quaternion    schedule 22.03.2011

Попробуй это:

<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>
person manu    schedule 14.04.2016