1 Reply Latest reply on Jun 25, 2015 5:34 PM by gesker

    Custom Validator Troubles

    gesker

      Hello Group:

       

      I seem to be having some trouble with custom validators in WildFly 9.0.0.CR2 and could really use a hint.


      My custom validators don't seem to fire/trigger/display to p:messages (I am using PrimeFaces) unless one of the standard validators also fires.

       

      For instance my validator is "structureTypeDuplicateName" and it's messages are displayed ONLY if "validateRequired" also is triggered/displayed.

       

      I've tried two scenarios and I'm seeing pretty much the same different behavior:

       

      Scenario 1:
      Using @FacesValidator and a nested tag of <f:validator for="name" validatorId="structureTypeDuplicateName"/>


      The forms (commandbutton) action does process "seemingly" ignoring my validation attempt.

      However, I can see the validator getting called by just adding a bit of logging to the validator class

      (Also, under this scenario my @EJB variable is null -- may be related)

       

       

      Scenario 2:

      Using @RequestScoped and @ManagedBean and a nested tag of <f:validator for="name" binding="#{structureTypeDuplicateName}"/>

      Again, the form (commandbutton) action does process "seemingly" ignoring my validation.

      And, I can still see the validator getting called via the logging to the validator class

      (Under this scenario my @EJB variable works fine -- but here it is a @ManagedBean so, OK, I guess.)

       

      I do use a -- ui:include -- tag to get my forms into my page but this doesn't seem to impact any other expected behavior in the form.


      Just for the heck of it I also tried putting my custom validator info into faces-config.xml but still no luck.

       

      Could someone point me in the right direction?


      Thanks,

      Dennis

        • 1. Re: Custom Validator Troubles
          gesker

          My apologies for this post. Just tired eyes I think.

           

           

          In my validator I was doing:

          context.getCurrentInstance().addMessage(component.getClientId(), new FacesMessage(FacesMessage.SEVERITY_ERROR, "Submitted NAME is already in the system.", "Submitted NAME is already in the system."));

           

           

          When I should have thrown a new ValidationException:

          throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Submitted NAME is already in the system.", "Submitted NAME is already in the system."));

           

          I hope my post tie anyone up.

           

          Thanks,

          Dennis

          1 of 1 people found this helpful