3 Replies Latest reply on Aug 27, 2010 4:44 PM by jgreene

    Still can't get selectedTab dynamic binding to work


      Hello -

      Can someone please clarify a couple of specific issues I have with dynamically setting the selected tab for a rich:tabPanel component?  I believe I have tried everything I've seen in the forums, and have considered the JIRA ticket that describes this problem that was supposedly fixed in 3.3.2.GA.  I've tried using the examples I've seen as a guide, but for some reason I still can't get it to work.


      First, I want the tab Panel to be ajax switched.  Is that possible?


      Also, when I bind the selectedTab attribute - e.g., selectedTab="#{myBean.tabValue}", does this value have to correspond to the "label" attribute, or does it correspond to the "name" attribute of the rich:tab?  I've seen different examples that indicate it should bind to "label", and other examples that indicate it should bind to "name".  Which is it?


      In case it matters, here is the basic operation for purposes of my example.  I start out with a rich:tabPanel with 2 tabs.  The content of one of the tabs has a link.  When the link is clicked (a4j:commandLink), a bean value is set so that when the tabPanel is rerendered, a 3rd tab is added using its "rendered" boolean attribute, and I am hoping the selectedTab attribute will then cause this tab to be selected by using the correct binding.  I know the 3rd tab isn't in the DOM all the time, so perhaps the biggest question is...Can the selectedTab binding work if the tab that you want to be selected is not in the DOM until the content of the rich:tabPanel is rerendered?


      One more thing - I have also tried using the "selectTab" javascript function as the oncomplete event handler, and it does not work for me either.  I know I must be doing something wrong, but if I can get these basic questions clarified, maybe I can get closer to getting it to work.


      Finally, which version of Richfaces definitely has this fix?  I've tried 3.3.2.GA and 3.3.3.Final.


      Thank you all for any help.

        • 1. Re: Still can't get selectedTab dynamic binding to work

          I'm not sure about which issue you talking.. and just decided to show example which seems show the answer to the questions listed



          <rich:tabPanel switchType="ajax" selectedTab="#{userBean.name}" id="tp">
          <rich:tab label="First tab" name="first">
          Here is tab #1
          <rich:tab label="Second tab" name="second">
          Here is tab #2
          <rich:tab reRender="#{userBean.thirdRendered}" name="third" label="Third">
          Here is tab #3
          <a4j:commandButton value="switch To 2" reRender="tp">
          <a4j:actionparam name="sec" value="second" assignTo="#{userBean.name}"/>
          <a4j:commandButton value="switch to 3 and make it rendered" reRender="tp">
          <a4j:actionparam name="thiR" value="#{true}" assignTo="#{userBean.thirdRendered}"/>
          <a4j:actionparam name="thiird" value="third" assignTo="#{userBean.name}"/>


          clicking to the first button - TP switched to second tab. and to the third one - third tab became rendered and switched to. the whole panel switched in ajax mode if controls used.

          • 2. Re: Still can't get selectedTab dynamic binding to work

            Thanks for the reply, Ilya.  However, one difference that I think is important with what I described is that for my example, the 3rd tab will not exist until the link is clicked, which will set a bean property on the back end.  In the same action method, a string property is set to reference the name of the 3rd tab.  Then when the component rerenders, the 3rd tab will be included (because I use its "rendered" attribute) in the TP, and it will be selected.  All of this works for me except the tab does not change.  The content for the 3rd tab is rendered, but the 3rd tab is not at the front.


            I hope this makes sense.

            • 3. Re: Still can't get selectedTab dynamic binding to work

              Ilya -

              I want to try using the undocumented Richfaces.switchTab function to switch the tab on the "oncomplete" event.  Here's an example I found on how to use it:




              In this example, it says to use the tab "name", but the example markup uses the "label" attribute, while the "name" attribute is not even used. Can you please clarify exactly how to use this javascript function, and which attribute values to pass in to the function?  Thank you.


              - Joe