5 Replies Latest reply on Nov 12, 2012 8:49 AM by Radim Hanus

    rich:validator question

    Sergey Morenets Novice

      Hi, all

       

      I want to enable client-side validation for my form as explained here

      http://showcase.richfaces.org/richfaces/component-sample.jsf?demo=notify&skin=blueSky

       

      However I encountered two issues which I coudn't resolve.

       

      1) Here is simplified example

       

                  <rich:validator event="change">
                      <h:outputText value="Name:" />
                      <h:inputText label="Name" id="name" value="#{account.username}" required="true"
      requiredMessage="#{msg['profile.login.required']}" >
                      </h:inputText>
                      <rich:message for="name" ajaxRendered="true" />
                  </rich:validator>
                  <rich:notifyMessages stayTime="2000" nonblocking="true" />

      <a4j:commandButton value="Ajax Validate" />

       

      This sample works fine if I use validation <f:validateLength minimum="3" maximum="50" />

      If I specify required="true" it doesn't work at all. I have to click "Ajax Validate" button to show error message.

      The only solution is to put <a4j:ajax event="change" /> inside each input component. However it is not a good workaround concerning scalability.

       

      2) The notification pop-up message is not displayed in any case. Even if validation message appears.

      I don't see any error messages in the browser console/error log.

       

      Please, advice.

        • 1. Re: rich:validator question
          Radim Hanus Expert

          facelet snippet here works for me well

          use f:validateRequired since it's prefered kind of validation

          1 of 1 people found this helpful
          • 2. Re: rich:validator question
            Sergey Morenets Novice

            Hi, Radim

             

            Thank you for the small hint. This is useful solution. However I have to update all my input components and embed this validator.

            What is worse the validation message is not customizable. I specified requiredMessage attribute before and it was displayed upon validation error.

            Now it is ignored.

             

            If I want to achieve the same result now I have either to override JSF message bundles or write my own validator which will generate message with necessary text.

            Not big piece of work but another one in the long list TODOs in the JSF2 migration process ...

            • 3. Re: rich:validator question
              Radim Hanus Expert

              I specified requiredMessage attribute before and it was displayed upon validation error.

              Now it is ignored.

              attribute requiredMessage is connected with attribute required

              you should use attribute validatorMessage (and converterMessage in case of invalid data type as described in link above)

              If I want to achieve the same result now I have either to override JSF message bundles or write my own validator which will generate message with necessary text.

              BTW message bundles are very usefull since you may easily provide multilingual applications

              1 of 1 people found this helpful
              • 4. Re: rich:validator question
                Sergey Morenets Novice

                Thank you, Radim.

                 

                It's weird that requiredMessage is not used. What I see from the JSF sources(RequiredValidator class)

                 

                        if (component instanceof UIInput) {
                            requiredMessageStr = ((UIInput) component).getRequiredMessage();
                        }

                 

                Anyway validatorMessage works for me. However what if I use several validators?

                Will they all use the validatorMessage attribute in case of error?

                • 5. Re: rich:validator question
                  Radim Hanus Expert

                  Anyway validatorMessage works for me. However what if I use several validators?

                  Will they all use the validatorMessage attribute in case of error?

                  yep they will

                  you may also supply converterMessage if you want a custom message to handle illegal data of given type