11 Replies Latest reply on Sep 24, 2008 9:07 AM by Drew Kutchar

    UI Repeat

    guy bashan Apprentice


      I know this is more of a Facelets question...
      Is there a way of using ui repeat tag just as it was a simple indexed for loop?
      I mean, I don't want to create a bean and fill it with five items, in order to make a loop from 0 to 4...


        • 1. Re: UI Repeat
          Samuel Mendenhall Apprentice

          Not with ui:repeat but yes with c:forEach, see https://facelets.dev.java.net/nonav/docs/dev/docbook.html#taglib-available-jstl  so you can do:

          <c:forEach begin="0" end="4" varStatus="idx">

          • 2. Re: UI Repeat
            guy bashan Apprentice

            Weird, for some reason the c:forEach doesn't work for me. I added the namespace, run a simple loop, wrote some text in the loop and all I see is a single time the text it printed. I assume that facelets simply ignore this tag...

            But anyway, I am trying to use t:dataList (like ui:repeat) for now. I am generating a list on the server side. The list is being generated from a facelets component. I pass to the
            component a signle parameter:

            <n:ratingShow rating="#{video.rating}" />

            It seems like this parameter is not accessible on the server.
            This is my component:

            <span xmlns="http://www.w3.org/1999/xhtml"
              <t:dataList value="#{ratingList}" var="r" rowIndexVar="rowIndex">
                <h:graphicImage url="img/rating/small_#{r}.jpg" />

            This is the server side code:

            public class RatingAction
              public List<String> getRatingList()
                double rating = (Double)FacesUtil.getElValue("#{rating}");
                List<String> list = new ArrayList<String>();
                for (int i = 0; i < 5; i++)
                  if (rating >= i + 1)
                  else if (rating >= i + 0.5)
                return list;

            The rating is null. although when printing it from the component xml code, it returns a valid value.

            The code I am using to evaluate the expression:

              public static Object evalEl(String expression) {
                  String framedExpr = "#{" + expression + "}";
                  Object value = Expressions.instance().createValueExpression(framedExpr).getValue();
                  return value;

            • 3. Re: UI Repeat
              guy bashan Apprentice

              Sorry, I forgot to ask the final question... ;-)
              Is there a reason the rating is not being evaluated in the Java code? Should there be some other code to evaluate facelets parameter (if it does it will be a bit not comfortable...).

              One more thing the interests me:
              When calling the ratingList twice, it actually executes the getRatingList method twice. Is there a way to cause Seam to cache the result for the request and execute the getRatingList only once (I though that this is one of the benfits of using @Unwrap)?


              • 4. Re: UI Repeat
                Tomaz Cerar Master


                you can also try a4j:repeat it has index and everything you need...

                the difference between c:forEach and ui:repeat is that c:forEach is content handler and ui:repeat is component..


                • 5. Re: UI Repeat
                  guy bashan Apprentice

                  Is there any component allowing conditional flow rather than using rendered property?
                  Does anyone know how to evaluate facelet component parameter in java code?

                  • 6. Re: UI Repeat
                    Tony Herstell Master

                    <s:fragment> for conditional stuff in your xhtml pages.

                    • 7. Re: UI Repeat
                      Tony Herstell Master


                      <s:fragment rendered="#{!(identity.loggedIn and s:hasRole('ADMINISTRATOR'))}">
                           <div class="centre text_important">
                                <h:outputText value="#{messages.status_arena_status}" />
                                <s:fragment rendered="#{!(identity.loggedIn and s:hasRole('ADMINISTRATOR'))}">
                                     <span class="italic small_text">
                                                    (<h:graphicImage alt="#{messages.status_open}" url="#{basePath}/images/tick.gif" height="10"/><h:outputText value="#{messages.status_open}" />
                                          <h:graphicImage alt="#{messages.status_closed}" url="#{basePath}/images/cross.gif" height="10"/><h:outputText value="#{messages.status_closed}" />)

                      • 8. Re: UI Repeat
                        guy bashan Apprentice

                        Nice thing, though I don't see here any special properties that I cannot do using simple h:panelGroup.

                        • 9. Re: UI Repeat
                          guy bashan Apprentice

                          Sorry, couldn't find any index property in a4j:repeat...

                          • 10. Re: UI Repeat
                            Alexander Seitz Newbie

                            what is the difference between <s:fragment> and <s:div> or <s:span> (except for the block and inline type)?

                            • 11. Re: UI Repeat
                              Drew Kutchar Newbie

                              <s:div> conditionally renders its contents wrapped in HTML <div>

                              <s:span> conditionally renders its contents wrapped in HTML <span>

                              <s:fragment> conditionally renders its contents without wrapping them in any HTML element