2

I would like to dynamically add <p:tab> components to <p:wizard> component in a loop.

I tried using <ui:repeat> inside and outside <p:wizard> component.

<p:wizard>
    <ui:repeat value="#{tabBean.tabs}" var="tab">
        <p:tab title="#{tab.tabname}">
    </ui:repeat>
</p:wizard>
<ui:repeat value="#{tabBean.tabs}" var="tab">
    <p:wizard>
        <p:tab title="#{tab.tabname}">
    </p:wizard>
</ui:repeat>

None of both attempts work. How can I achieve my requirement?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
surya
  • 23
  • 4

1 Answers1

8

The <p:wizard> only understands <p:tab> children. It doesn't understand an <ui:repeat> child. You need to create physical <p:tab> children in the JSF component tree as immediate child of the <p:wizard> component.

The <c:forEach> taghandler is capable of doing that.

<p:wizard>
    <c:forEach items="#{tabBean.tabs}" var="tab">
        <p:tab title="#{tab.tabname}">
    </c:forEach>
</p:wizard>

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • 1
    But keep in mind that you cannot add a tab while in the process of executing a wizard. The `c:foreach` loop is executed once, at viewbuildtime. So 'dynamically adding' is more 'dynamically creating once' – Kukeltje Jun 26 '15 at 11:18
  • 1
    @Kukeltje: Just rebuild the view after doing that. Can be done by `setViewRoot(getViewId())`. – BalusC Jun 26 '15 at 11:22
  • 1
    Isn't that the same as not doing ajax? Just a full page refresh? That is most of the time not what (imo) people mean by dynamically adding. Though this case may differ… – Kukeltje Jun 26 '15 at 11:28
  • 1
    @Kukeltje: Nope, it's entirely server side. Only view scoped beans will die and get recreated, but that's a different problem :) A full page reload can also, but you know, it's clumsy. – BalusC Jun 26 '15 at 11:32
  • 1
    :-)... But you still get all tabs transferred as html (whole page I assume, or is e.g. an `update="wizardId"` still honoured?) That is more what I meant to imply. – Kukeltje Jun 26 '15 at 11:38
  • 1
    @Kukeltje: As said, it's entirely server side. Basically just the JSF component tree (and state) gets refreshed. That's it. Navigation/rendering/ajax-updates etc remain unaffected. – BalusC Jun 26 '15 at 11:43