3 Replies Latest reply on Oct 25, 2009 4:47 AM by clerum

    Seam Validator Not Working

      I have a Validator class

      import javax.faces.application.FacesMessage;
      import javax.faces.component.UIComponent;
      import javax.faces.context.FacesContext;
      import javax.faces.validator.ValidatorException;

      import org.jboss.seam.annotations.Logger;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Scope;
      import org.jboss.seam.annotations.faces.Validator;
      import org.jboss.seam.annotations.intercept.BypassInterceptors;
      import org.jboss.seam.log.Log;
      import org.jboss.seam.ScopeType;

      @Name("amountValidator")
      @BypassInterceptors
      @Scope(ScopeType.CONVERSATION)
      @Validator

      public class amountValidator implements javax.faces.validator.Validator,
                java.io.Serializable {

           @Logger
           private Log logger;

           private static final long serialVersionUID = 1L;

           public void validate(FacesContext context, UIComponent cmp, Object value)
                     throws ValidatorException {

                String cmpId = cmp.getId();
                
                value = replaceNull((String)value);

                if(value.equals("")){
                     throw new ValidatorException(new FacesMessage("value null"));

                }
                logger.info("validate(): cmpId = " + cmpId);

           }
      I am trying to use no input text field

      <h:inputText value="" validator="#{amountValidator}"/>

      I have a submit button

      <s:button id="backButton" alt="Back button" value="#{messages['button.back']}" action="#{amountChangeFacade.submit}" />

      When I click the button the validation is not getting called.

      It only gets called when I use a regular JSF Command Button

      but I need to use a SEAM button.

      Am I missing anything?
        • 1. Re: Seam Validator Not Working
          cosmo

          Yes, s:button and s:link don't submit the form.

          • 2. Re: Seam Validator Not Working
            asookazian

            The following is a strange implementation:


            I am trying to use no input text field
            
            <h:inputText value="" validator="#{amountValidator}"/>
            
            I have a submit button
            
            <s:button id="backButton" alt="Back button" value="#{messages['button.back']}" action="#{amountChangeFacade.submit}" />



            I have never used <h:inputText> without EL expression in action attribute.  When you click a link or button, typically something happens, right?  Why must it be a Seam button?  Seam links and buttons issue HTTP GET requests, not HTTP POST request to submit forms.  And we're talking about form validation, correct?

            • 3. Re: Seam Validator Not Working
              clerum

              Also @Logger won't work because the interceptors are being bypassed.