Struts2 - параметр проверки и тайлов - PullRequest
2 голосов
/ 22 марта 2011

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

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

}

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

Ответы [ 2 ]

0 голосов
/ 14 апреля 2016

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

<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 голосов
/ 23 марта 2011

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

...