2 Replies Latest reply on May 12, 2009 8:45 PM by Brandon Simpson

    Need help! I'm fighting validation!

    Brandon Simpson Newbie
      Here's the background of the problem: I have a complex data entry screen with about 20 input fields and 8 data tables. The data tables allow records to be added/removed via button presses. All of this worked great until I added Hibernate validation.

      With validation enabled, if the user clicks the Save button and a validation error occurs, it breaks the functionality of the dynamic data tables. I've tried various combinations of immediate="true" and action/value change listeners but I just can't get normal behavior after a validation error occurs.

      Either the add/remove buttons stop working completely, or the data tables "forget" any data entered by the user when an add/remove button is pressed.

      With validation off, I can understand that probably my underlying model is being updated on each button press. With validation on and after a validation error, I'm guessing the underlying model is not updated, but also it seems that the data table rows aren't retaining any user input and revert back to whatever values they originally had. Is this a bug or JSF deficiency?

      One other side effect is that after a validation error, any add/remove button press removes the validation error messages.

      What I'd really like is for validation to only occur when the save button is pressed and for the rest of the user interactions to not be affected by validation. Is there any way to manually kick off the validation process in user code so that I could put this logic only in my save method? I'm already doing some validation there myself to highlight invalid values in the data table rows since this doesn't appear to be handled properly by JSF currently. I'm really really hoping I don't have to completely disable validation and do it all on my own but I have to make this screen work properly. Any ideas?

      One other thing, several times when I've tried to post here, the post just seems to get eaten. I get the little dynamic graphic in the bottom left corner, but it stays there forever. The only thing that seems to help is to select "Let me type some plain text, not markup" before saving. Anyone know what's up with that?
        • 1. Re: Need help! I'm fighting validation!
          Francisco Jose Peredo Noguez Master

          Brandon Simpson wrote on Apr 29, 2009 17:53:


          Here's the background of the problem: I have a complex data entry screen with about 20 input fields and 8 data tables. The data tables allow records to be added/removed via button presses. All of this worked great until I added Hibernate validation.



          In my experience Hibernate validation is only useful for simple stuff, and AFAIK JSR 303 will not help much in that regard unless it validates transactionally. Please vote for EJB-419



          With validation enabled, if the user clicks the Save button and a validation error occurs, it breaks the functionality of the dynamic data tables. I've tried various combinations of immediate="true" and action/value change listeners but I just can't get normal behavior after a validation error occurs.



          I have been replacing my Hibernate/JSF validation with jQuery based validation for anything that requires client side UI interaction. And, since for complex database related validations Hibernate validation is not recommended (no queries allowed in validation), I had to build my own validation engine from scratch, guess you will have to do the same.


          Either the add/remove buttons stop working completely, or the data tables forget any data entered by the user when an add/remove button is pressed.

          With validation off, I can understand that probably my underlying model is being updated on each button press. With validation on and after a validation error, I'm guessing the underlying model is not updated, but also it seems that the data table rows aren't retaining any user input and revert back to whatever values they originally had. Is this a bug or JSF deficiency?

          One other side effect is that after a validation error, any add/remove button press removes the validation error messages.


          Maybe jGrowl messages can help you with keep validation messages after other UI interactions.


          What I'd really like is for validation to only occur when the save button is pressed and for the rest of the user interactions to not be affected by validation. Is there any way to manually kick off the validation process in user code so that I could put this logic only in my save method? I'm already doing some validation there myself to highlight invalid values in the data table rows since this doesn't appear to be handled properly by JSF currently. I'm really really hoping I don't have to completely disable validation and do it all on my own but I have to make this screen work properly. Any ideas?



          This is, AFAIK a JSF limitation. JSF needs something like ASP.NET validation groups. I am thinking about requesting somthing like this in RichFaces JIRA... would you vote for it?





          • 2. Re: Need help! I'm fighting validation!
            Brandon Simpson Newbie

            Thanks for the response. I somehow missed it until today. I ended up growing my own validation and it works very well for my situation. It only kicks in when I want it to and doesn't lose it's state (FacesMessages) between page interactions. I will definately vote on validation improvements. Thanks again for your input...it helped me decide what course of action to take.