0

I want to render a nested 2-level navigation using a model file. The Navigation can change.

There is a Simple Bean NavigationItem which contains the title, target, icon and a list of possible sub items.

The Navigation is created very simple:

@ViewScoped
@Named
public class Navigation implements Serializable  {

    private List<NavigationItem> navigation = new ArrayList<>();

    public List<NavigationItem> getValues() {
        if (navigation == null || navigation.size() <= 0) {
            NavigationItem navA = new NavigationItem("A", "icon-gauge", "site_a");
            {
                List<NavigationItem> subNav = new ArrayList<>();
                subNav.add(new NavigationItem("1", "", "subsite_1"));
                subNav.add(new NavigationItem("2", "", "subsite_2"));
                subNav.add(new NavigationItem("3", "", "subsite_3"));
                navA.setSubItems(subNav);
            }

            NavigationItem navB = new NavigationItem("B", "icon-layout", "site_b");
            {
                List<NavigationItem> subNav = new ArrayList<>();
                subNav.add(new NavigationItem("4", "", "subsite_4"));
                subNav.add(new NavigationItem("5", "", "subsite_5"));
                navB.setSubItems(subNav);
            }

            NavigationItem navC = new NavigationItem("C", "icon-layout", "site_c");
            {
                List<NavigationItem> subNav = new ArrayList<>();
                subNav.add(new NavigationItem("6", "", "subsite_6"));
                navC.setSubItems(subNav);
            }

            navigation.add(navA);
            navigation.add(navB);
            navigation.add(navC);
            navigation.add(new NavigationItem("Test", "icon-gauge", "site_d"));
        }
        return navigation;
    }

}

And here is my JSF

<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://xmlns.jcp.org/jsf/facelets" xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:f="http://xmlns.jcp.org/jsf/core" xmlns:b="http://butterfaces.org/components" >

    <ul id="side-nav" class="main-menu navbar-collapse collapse">

        <b:repeat value="#{navigation.values}" var="nav" rendered="true">
            <li class="#{nav.hasSubItems()==false ? '' : 'has-sub'}">
                <h:link outcome="#{nav.target}">
                    <i class="#{nav.icon}"></i>
                    <span class="title">#{nav.title}</span>
                </h:link>

                <ui:fragment rendered="#{nav.hasSubItems()}">
                    <ul class="nav collapse">
                        <b:repeat value="#{nav.subItems}" var="subNav" rendered="true">
                            <li>
                                <h:link outcome="#{subNav.target}">
                                    <span class="title">#{subNav.title}</span>
                                </h:link>
                            </li>
                        </b:repeat>
                    </ul>
                </ui:fragment>

            </li>
        </b:repeat>
    </ul>

</ui:composition>

My expected result:

  • A
    • 1
    • 2
    • 3
  • B
    • 4
    • 5
  • C
    • 6
  • D

My actual result is:

  • A
    • 1
    • 2
    • 3
  • B
    • 1
    • 2
    • 3
  • C
    • 1
    • 2
    • 3
  • D

Is there something i miss or a fault? I am using Mojarra 2.2.8 on Tomcat 8

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Jukkales
  • 117
  • 2
  • 11
  • Uhhmmmm the title says `ui:repeat` but the code shows `b:repeat` (and a ui:composition, so the ui namespace is there). Please state what is actually used? is it a bootsfaces repeat? – Kukeltje Jul 28 '16 at 11:03
  • Oh, I see butterfaces, I removefd 'mojarra, and ui:repeat' and add butterfaces (you even should remove jsf and jsf-2, since it is not a problem specifically for these – Kukeltje Jul 28 '16 at 11:05
  • Oh damn - i'm blind. You are right. Its stupid, with ui:repeat everything works fine.- i feel like i searched me blind and didn't see the wrong namespace. Thanks! – Jukkales Jul 28 '16 at 11:16
  • Well, there **are** issues with `ui:repeat` in Mojarra, that is why e.g. PrimeFaces developed its own p:repeat, so there might be a reason why butterfaces did the same – Kukeltje Jul 28 '16 at 11:22
  • There are **serious** issues with `ui:repear` in Mojarra. I suggest using available equivalent. Both `p:repeat` and `a4j:repeat` are much better (I don't know ButterFaces). – Emil Sierżęga Jul 28 '16 at 12:11

1 Answers1

0

There a some serious issues with mojarra repeat component so we've created our own component in butterfaces (like primefaces, richfaces, etc.)

This seems to be a bug and I've created an issue: https://github.com/ButterFaces/ButterFaces/issues/63

Lars Michaelis
  • 559
  • 2
  • 6
  • 11
  • Hhhhhmmm... bad karma... Stating there are serious issues with the mojarra repeat and then having such a basic thing like nesting not work ;-). Never the less, ButterFaces componentsuite is not bad... Nice features in the showcase, the reaonly/required/label/etc.. things Some optimization in the showcase might help, e.g. setting the radiobox to enabled and having the full page reloaded feels a bit heavy (I know it is not the framework fault). – Kukeltje Jul 28 '16 at 18:34
  • We've build b:repeat for a specific problem with mojarra ui:repeat. Up to now it seems no one has used it nested. :) – Lars Michaelis Jul 28 '16 at 19:18