2

Let's say there are two tabs. I want to show a button below p:tabView if the user is on the first page and on the other hand I want to not to render that button if the user is on the second page. How can I ahieve this functionality? My code:

<h:form id="fr">
    <p:tabView id="tabV" activeIndex="#{mngr.tabIndex}">
        <p:ajax event="tabChange" listener="#{mngr.onTabChanged}" update=":fr:button"/>
        <p:tab>
            Tab one
        </p:tab>

        <p:tab>
            Tab two
        </p:tab>
    </p:tabView>
    <p:commandButton id="button" rendered="#{mngr.tabIndex == 0}"/>
</h:form>

Button is rendered whether you are on first or second tab, however things get differet if you manually refresh the page, then button rendering is working as intended. How can I update that button on tab change event?

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
Benas
  • 2,106
  • 2
  • 39
  • 66
  • did you try update="button"? It should work. – Johny T Koshy Dec 30 '13 at 13:10
  • thank you for your reply, but it can not find element with id "button". – Benas Dec 30 '13 at 13:12
  • 2
    I dint see the rendered attribute.. You should wrap your commandbutton inside another element which is always available and use its ID. – Johny T Koshy Dec 30 '13 at 13:16
  • 1
    This answer will give a clearer idea. http://stackoverflow.com/questions/4573190/jsf-primefaces-update-attribute-does-not-update-component – Johny T Koshy Dec 30 '13 at 13:21
  • Does this answer your question? [Ajax update/render does not work on a component which has rendered attribute](https://stackoverflow.com/questions/14790014/ajax-update-render-does-not-work-on-a-component-which-has-rendered-attribute) – Jasper de Vries Aug 09 '22 at 06:30

1 Answers1

1

For me, the item was just not being rendered at the time that I was trying to update. You could simply update whatever container is holding the other control (or add one to update as the comment above stated).

This post is similar and has information on this as well.

ConfusedUbuntist
  • 135
  • 1
  • 10