14 Replies Latest reply on Apr 5, 2011 8:25 AM by Michal Huniewicz

    RichFaces 4 validation, stuff disappears

    Michal Huniewicz Newbie

      Hi, I'm playing with RichFaces 4 and what I want is a registration form that uses

      • a managed bean with JSR 303 annotations
      • a4j:ajax on one of the h:inputText's to check if the input is unique

       

      So I created this:

       

      <h:form>
              <rich:panel>
                  <h:panelGrid columns="3">
                      <h:outputText value="Email:" />
                      <h:inputText id="email" value="#{registration.email}">
                          <rich:validator />
                      </h:inputText>
                      <h:panelGroup>
                          <rich:message for="email" />
                      </h:panelGroup>
      
                      <h:outputText value="Name:" />
                      <h:inputText id="name" value="#{registration.name}"> 
                          <a4j:ajax event="keyup" listener="#{registration.checkName}"
                              render="@none" execute="@none" />
                          <rich:validator />
                      </h:inputText>
                      <h:panelGroup>
                          <rich:message for="name" ajaxRendered="true" />
                      </h:panelGroup>
      
                      <a4j:commandButton value="Register"
                          action="#{registration.register}" render="length" />
                  </h:panelGrid>
              </rich:panel>
          </h:form>
      

       

      But a4j:ajax screws it all up. Validation messages from the email field disappears once I enter the name field. Perhaps 2 requests are sent because I have a4j:ajax rich:validator under one h:inputText?

       

      In any case, how can I achieve what I want? I'm on 4.0.0.Final, JBoss 6.

      Thanks for help

        • 1. RichFaces 4 validation, stuff disappears
          Ilya Shaikovsky Master

          you could remove a4j:ajax and move #{registration.checkName} code to the validator method of the input.

          • 2. RichFaces 4 validation, stuff disappears
            Michal Huniewicz Newbie

            Hi Ilya, thanks for your quick answer.

             

            Could you please confirm my idea as of what to causes the problem (multiple requests on one field)?

             

            My goal is to have a field (user name) with standard validators on it, but also have additional (custom) validation that will check the uniqueness against the database. Because that may take a while, I'm using a4j:ajax in the first place to be able to provide a4j:status (to have a message/gif indicating that polling is being made). Perhaps there's a way to satisfy those requirements?

             

            Cheers.

            • 3. RichFaces 4 validation, stuff disappears
              Ilya Shaikovsky Master

              https://issues.jboss.org/browse/RF-10731

               

              yes.. caused by the fact that currently if there are two submitting behaviors are present - only one is actually called.

              • 4. RichFaces 4 validation, stuff disappears
                Ilya Shaikovsky Master

                and if you will use validator as I described status should be triggered also as ajax fallback for validator should be processed by indication components in the same way as a4j:ajax.

                • 5. RichFaces 4 validation, stuff disappears
                  Michal Huniewicz Newbie

                  Aha, sweet. I'll try it out then, thanks a lot, mate!

                  • 6. RichFaces 4 validation, stuff disappears
                    Michal Huniewicz Newbie

                    Ilya Shaikovsky wrote:

                     

                    you could remove a4j:ajax and move #{registration.checkName} code to the validator method of the input.

                    How can I do it though? I.e. how can I have custom validation combined with standard JSR 303 validation per input? I'm looking at http://richfaces-showcase.appspot.com/richfaces/component-sample.jsf?demo=graphValidator&skin=blueSky and that doesn't seem to be it, really...

                    • 7. RichFaces 4 validation, stuff disappears
                      Ilya Shaikovsky Master

                      I do not mean to use graphValidator. I mean just register f:validator at input or create custom JSR 303 constraint and it's impl. then rich:validator will validate all the default constrains at client side and if them are ok will fire ajax request to perform that validation additionally.

                      • 8. RichFaces 4 validation, stuff disappears
                        Michal Huniewicz Newbie

                        I thought custom validators were not supported yet for client side? It seems to suggest so here:

                        http://richfaces-showcase.appspot.com/richfaces/component-sample.jsf?demo=clientValidation&skin=blueSky

                        • 9. Re: RichFaces 4 validation, stuff disappears
                          Michal Huniewicz Newbie

                          Hi, I tried that but where do I put the status attribute so that it only applies to this field? I tried on the richvalidator itself and on the inputText, but it only works if I DON'T put in anywhere as an attribute.

                           

                                          <h:outputText value="Name:" />
                                          <h:inputText id="name" value="#{registration.name}">
                                              <rich:validator />
                                          </h:inputText>
                                          <rich:message for="name" />
                          
                                          <a4j:status id="nameStatus" startText="Checking name..."
                                              startStyle="background-color: FFA500" />
                          
                          • 10. Re: RichFaces 4 validation, stuff disappears
                            Michal Huniewicz Newbie

                            Sorry for my third response in a row, but I tried this and it displays the status message for the wrong field (the first one, and not the second one)!

                             

                            <h:panelGrid columns="3">
                                            <h:outputText value="Email:" />
                                            <h:inputText id="email" value="#{registration.email}">
                                                <rich:validator />
                                            </h:inputText>
                                            <rich:message for="email" />
                            
                                            <h:outputText value="Name:" />
                                            <a4j:region id="nameRegion">
                                                <h:inputText id="name" value="#{registration.name}"
                                                    status="nameStatus">
                                                    <rich:validator />
                                                </h:inputText>
                                                <a4j:status for="nameRegion" startText="Checking name..."
                                                    startStyle="background-color: FFA500" />
                                            </a4j:region>
                                            <rich:message for="name" />
                            
                                            <a4j:commandButton value="Register"
                                                action="#{registration.register}" render="length" />
                                        </h:panelGrid>
                            

                            I also tried without naming the region - didn't help... Any ideas? Thanks!

                            • 11. Re: RichFaces 4 validation, stuff disappears
                              Ilya Shaikovsky Master

                              Original problem:

                              I thought custom validators were not supported yet for client side?

                              Yes, but that is what I wanted you to use:

                              <h:inputText value="#{validationBean.name}" id="name">

                                    <rich:validator />

                              </h:inputText>

                              and

                              @Size(min=3, max=12)

                              @UniqueName

                              private String name = null;

                               

                              where @UniqueName - your custom validator. Then:

                               

                              • size will be checked by rich:validator on the client side
                              • if size returned valid - Ajax request will be automatically send by the same rich:validator in order to perform validation for @UniqueName which has no clienty impl.

                               

                              All that will be done as expected on validation phase and by using only validation stuff and not actions/listeners and so on.

                               

                              new problems:

                               

                              1) status now do not attached to regions. (That was actually not a good design in 3.3.x as it doesnt clear why UI indication component are bound to utility limiting processing one). Now you could use at view level(placed outside of all forms without name), form level(in form without name) or referenced:

                              <a4j:status name="stat">

                              ...

                              <h:inputText value="#{validationBean.email}" id="email" validatorMessage="bad email">

                                                                                <rich:validator status="stat"/>

                                                                      </h:inputText>

                              ...

                              2) you should realize that status will nto be triggered if there were no ajax requests(if all the validators has proper client implementations - validation will be on the client and status will be never shown). In your case I believe you using Hibernate validator for @email. And it's not available in CSV module currently. We implemented only standard JSR 303 ones and using @Pattern for our demo.

                              • 12. Re: RichFaces 4 validation, stuff disappears
                                Michal Huniewicz Newbie

                                Hi Ilya, thanks for your reply, once again.

                                 

                                What I want is I want one status per one field that potentially takes a while to validate. It should be placed next to the field, not somewhere above/below. What's my best call?

                                Cheers.

                                • 13. Re: RichFaces 4 validation, stuff disappears
                                  Ilya Shaikovsky Master

                                  As I already written:

                                   

                                  1) status now do not attached to regions. (That was actually not a good design in 3.3.x as it doesnt clear why UI indication component are bound to utility limiting processing one). Now you could use at view level(placed outside of all forms without name), form level(in form without name) or referenced:

                                  <a4j:status name="stat">

                                  ...

                                  <h:inputText value="#{validationBean.email}" id="email" validatorMessage="bad email">

                                                                                    <rich:validator status="stat"/>

                                                                          </h:inputText>

                                  ...

                                   

                                   

                                  But it will be shown only when the ajax request called and not in case of pure client side validation(which anyway will not take noticeable time)

                                  • 14. Re: RichFaces 4 validation, stuff disappears
                                    Michal Huniewicz Newbie

                                    HI Ilya, I replaced id with name on a4j:status and it works as expected now. Thanks!