5 Replies Latest reply on Jan 26, 2007 4:16 AM by toni

    How to postpone validation?

    toni

      Hi,

      I'm trying to set the values of an enity bean of which one value has to be chosen/set from a different page. The user gets to the page by clicking on a link whose link text displays the current value. The link is contained inside the same form, which contains the other input fields and the save button to persist the entiy.

      The problem I ran into is that all the other values get validated, when the user clicks on the link. The result is that the current page is redisplayed with error messages showing on the invalid input fields.

      Instead, I would like the user to be able to fill out the form of which some values are constrained (ie have to be valid). Then the user may click on the link to setup this special value, without his current input being validated and thereby lost, even if it's partly invalid.

      After picking the special value from the other page he gets sent back to page from which he came and should see (as mentioned above) all the other values of which some may be invalid.

      The page should only be redisplayed, if the user entered invalid input AND clicks on the Save button to persist the entity. Otherwise he should be forwarded to the page to set the special value an the current input should be displayed, after he is done.

      I tried to set immediate="true" on the the link, which one has to click to setup this one special value. If I do so, then the user can proceed to the other page, but all the values which the user had entered previously are lost, when the original page is redisplayed.

      I haven't figured out how to do this. Is it possible at all?

        • 1. Re: How to postpone validation?
          gavin.king

          Use s:validate on particular fields, instead of s:validateAll.

          • 2. Re: How to postpone validation?
            toni

            I tried it, but it does not make to seem a difference. And why would it?

            The fields which do not have any validation annotations aren't validated anyway.

            And the once which do should be validated, but only after the user clicked on the "Save" button.

            However, validation occurs always when he clicks the link. Do avoid this the only option is to use immediate="true", but then I loose the user's input.

            No matter if it's valid or invalid.

            Any other suggestions?

            • 3. Re: How to postpone validation?

              If you can design your interaction so that you only use one view, then JSF will preserve your unvalidated/unconverted form data. I believe it only discards the data when you write to another view. If you think about it, it kind of makes sense. Where is it supposed to store that unconverted/unvalidated string data? Unless your model only uses raw string values, there's no place for the data there. If you also discard your view, that data is lost.

              • 4. Re: How to postpone validation?
                gavin.king

                Oh, I misunderstood. Norman is right.

                • 5. Re: How to postpone validation?
                  toni

                  Ok, thats a solution.

                  The thing is that I use the page several times and I don't want copy and paste the code. That's why I made a second page.

                  But you actually got me on something. Maybe I could just inherit from that class, which sets the special value?