2 Replies Latest reply on Jun 10, 2010 4:48 PM by Vir Booster

    How to reset to null objects in backing bean after form validation errors.

    Vir Booster Newbie


      I have a problem of consistency between the backing bean object and the value displayed in the front-end.

      Particulary, I have a rich:calendar binded to a date in the backing bean.

      <rich:calendar id="valueDate" 
           <a4j:support event="onchanged" 
                           ajaxSingle="true" />
           <a4j:support event="oninputchange" 

      The problem is: if you select a correct date value everything works fine, the value is binded to the backing bean. Then if you change the value to something that doesn't follow the date pattern (ex. ssss) the validation fails, but my backing bean still holds the old value.

      My question is: Is there any way to set the backing bean object to null if the validation in the front-end fails???

      Otherwise you see a wrong date in the fron-end but you keep the old value in the backing bean....
      So, if you achieve another business validation after this.... God help you!

      I will appreciate any help from you.


        • 1. Re: How to reset to null objects in backing bean after form validation errors.
          Nikos Paraskevopoulos Novice


          This behavior is correct as per the JSF spec. Actually if a validation error occurs the server-side processing is interrupted, i.e. the model is not updated and actions are not called. This guarantees model consistency. Could you explain why does it cause you trouble?

          • 2. Re: How to reset to null objects in backing bean after form validation errors.
            Vir Booster Newbie

            Hello Nikos, thanks for responding quickly.

            I know is the correct JSF behavior and and every failed validation interrupts the processing.

            The problem is: if you previously set a correct value to the date, that correct value was binded to the backing bean. If after that you change the same date but with and incorrect string, of course validation fails and stop every other processing. The backing bean holds the correct value and the visual interface holds the incorrect one.

            I think the problem is that, additionally to this validation, another business validation is achieved in the backing bean in this method:


            in order to display error messages and disabled a next button.

            Since that date is included as part of the business validation, if the backing bean holds the old correct date, the business validation will pass without any trouble. But the visual interface is still displaying the wrong String.

            So, basically I want to know if there is some way to unificate the fact that: if I have a wrong visual value I want to be able to reset the date to null to make the business validation fail.

            I found a link where is happening the same but with different values: http://stackoverflow.com/questions/368137/jsf-reset-value-on-failed-validation

            My question is if this can be done.
            Otherwise I should find another way to achive what I need in this particular case.

            Anyway thank you very much for your help.