4 Replies Latest reply on Feb 7, 2008 10:21 AM by Stephane Epardaud

    Validation messages inside ui:repeat

    Stephane Epardaud Newbie


      I'm not sure whether this is a very silly question, or even whether it's related to seam at all and not specific to JSF broadly.

      I've got input fields inside a ui:repeat, and so their IDs get mangled and get pretty hard to find back. When I add a validation error with facesContext.addToControl(...) I cannot seem to get their ID right.

      Is there a way to disable ID mangling so that we know exactly what ID an element has, or an API to get the inverse mapping so I can ask how the ID 'foo' has been mangled so I can add a validation message ?

      Is there another way to do that ?

      Thanks for your help.

        • 1. Re: Validation messages inside ui:repeat
          Christian Bauer Master

          My guess is that it won't work with ui:repeat because it just renders the /same/ component several times, not creating new components in the tree. You probably need to use c:forEach, which generates several components in the tree. Read this article http://www.ilikespam.com/blog/c:foreach-vs-ui:repeat-in-facelets.

          • 2. Re: Validation messages inside ui:repeat
            Stephane Epardaud Newbie

            Sorry for the late answer, and thanks for your helpful answer.
            I've read this linked page and what I understand from it is that from a ui:repeat tag I should not be able to use custom tag handlers or ui:include and see the variable introduces by ui:repeat. Yet it works (mostly I was using it before I read and understood the page you pointed me to): I can use custom tag handlers and ui:include in ui:repeat, using the loop variable it introduces.

            At least it works in the view, the editing of things inside it is shakier.

            So is it something that changed since this page was posted, or is it just sheer luck that I can do some of the things the page says should not work ?

            But these questions are pretty far from my original post, to get back to it:

            I understand there's only one instance of an input field even if it's in a ui:repeat. The fact is that I'm only showing it once, because I can only edit one line at a time of the table I'm creating with ui:repeat.

            I'm not sure I understand the reason why I cannot add validation messages that would appear next to that input field, when it works outside of ui:repeat. I hope I'm not asking a really stupid question which was answered from the page you refer to, which I failed to see there :)

            Thanks for your help!

            • 3. Re: Validation messages inside ui:repeat
              Gavin King Master

              If you have a way to discover the client id of the control, you can add FacesMessages explicitly by client id (which is different for each rendered instance of the control), however, figuring out the client id can tend to be a bit tricky :-/

              • 4. Re: Validation messages inside ui:repeat
                Stephane Epardaud Newbie

                Yes, I don't understand why there isn't an API to do that...
                Thanks for your answer though :)