2

I need to have a list of links generated by JSF and displayed in Facelets. The bean would contain all of the links and where they need to point to, and then I assume some method would run to disperse all of them which could be called by some JSF attribute in the Facelets page.

I'm kind of clueless. How can I achieve this?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Luc
  • 87
  • 5

1 Answers1

2

You can use ui:repeat tag:

<ui:repeat value="#{bean.links}" var="link" varStatus="status">
    <h:outputLink value="#{link.url}">
        <h:outputLabel value="#{link.name}"/>
    </h:outputLink>
    <h:outputText value=", " rendered="#{not status.last}"/>
</ui:repeat>

bean is managed bean that have getLinks method. getLinks method returns list of links. Every link is an object with name and url properties. All links are separated by commas.

Mikita Belahlazau
  • 15,326
  • 2
  • 38
  • 43
  • 1
    Just to add to your answer, also take a look at this http://stackoverflow.com/questions/4317684/when-should-i-use-houtputlink-instead-of-hcommandlink to see when to use outputLink and when to use commandLink – Ravi Kadaboina Jun 20 '12 at 14:39
  • Remember that the link.url must evaluate to a defined navigation rule or, in JSF2, to a page's name to use implicit navigation. – Fritz Jun 20 '12 at 14:47
  • Oh nice! Very convenient. Thanks much! – Luc Jun 20 '12 at 15:01