1 Reply Latest reply on Jun 6, 2007 5:40 AM by mustaghattack

    s:validateAll cumulates validation error messages when used

    petr.mk

      Hello,

      does anyone meet the same problem?

      When <s:validateAll> tag is used in form together with dispalying error messahes using <h:messages globalOnly="false"/>, then the same validation message for one input form is cumulated. After first submit (in form is only one input field!) can be seen:

      length must be between 10 and 255
      length must be between 10 and 255

      after second submit:

      length must be between 10 and 255
      length must be between 10 and 255
      length must be between 10 and 255

      etc.

      It looks like <s:validateAll> problem, because when <s:validate/> is used, all is O.K.

      Here is test example:

      BookDetailTest.xhtml:

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:s="http://jboss.com/products/seam/taglib">

      #{libraryMessages.border_facelets_library}
      <meta http-equiv="Content-type" content="text/html; charset=windows-1250" />
      <meta http-equiv="Content-Language" content="cs" />
      <meta http-equiv="Expires" content="0" />
      <meta http-equiv="Cache-Control" content="no-cache" />
      <meta http-equiv="Pragma" content="no-cache" />






      <f:view>
      <h:messages globalOnly="false" />
      <h:form id="saveform">
      <s:validateAll>
      <h:panelGrid columns="2" border="0" cellpadding="0" cellspacing="2">
      <f:facet name="header">
      <h:outputText id="bookDetail_book" value="#{libraryMessages.bookDetail_kniha}" />
      </f:facet>
      <f:facet name="aroundInvalidField">
      <s:span styleClass="error"/>
      </f:facet>
      <f:facet name="afterInvalidField">
      <h:outputText value=" *)" />
      </f:facet>
      <h:outputText id="bookDetail_author" value="#{libraryMessages.bookDetail_autor}" />
      <s:decorate id="author">
      <h:inputText type="text"
      label="#{libraryMessages.bookDetail_autor}"
      value="#{bookDetailBean.author}"
      required="true"
      size="30"
      maxlength="30" />
      </s:decorate>
      <f:facet name="footer">
      <h:panelGroup>
      <h:commandButton type="submit"
      id="savebutton"
      action="save"
      value="#{libraryMessages.bookDetail_ulozit}" />
      <h:commandButton type="submit"
      id="backbutton"
      action="back"
      immediate="true"
      value="#{libraryMessages.bookDetail_zpet}" />
      </h:panelGroup>
      </f:facet>
      </h:panelGrid>
      </s:validateAll>
      </h:form>
      </f:view>




      BookDetailTestBean.java:

      package cz.profinit.education.library.web.beans;

      import java.io.Serializable;

      import org.hibernate.validator.Length;
      import org.hibernate.validator.NotNull;
      import org.jboss.seam.annotations.Name;

      /**
      *
      * Book detail implementation class.
      *
      * @author $Author: pmarek $
      * @version $Revision: 1.0 $
      */

      @Name("bookDetailTestBean")
      public class BookDetailTestBean extends LibraryBaseBean implements Serializable {

      private static final long serialVersionUID = -1547896425866324414L;

      private String author;

      @NotNull
      @Length(min = 10, max = 255)
      public String getAuthor() {
      return author;
      }
      public void setAuthor(String author) {
      this.author = author;
      }

      /**
      * SaveBookListener.
      * @ cycle
      */
      public String save() {
      return "success";
      }

      }

        • 1. Re: s:validateAll cumulates validation error messages when u
          mustaghattack

          I have the same problem ... I'm using Sun JSF Impl
          After a look in the code I found the problem : UIValidateAll add the validator in the getChildren() method. During the restore phase the StateManager restore the component tree structure before restoring the state. So the getChildren() method of UIValidateAll is called BEFORE restoring the state, when the components validator list is EMPTY.
          During the restore state step all the previous ModelValidators are added. So each refresh will add a ModelValidator to the component resulting in duplicated validation during validation phase ...
          I don't know if this is a known problem ? A workaround is to not use messages tag or as you said validate instead of validateAll.
          Bruno