简体   繁体   中英

primefaces dynamic tab render

I have some tabs and rendered attiributes. My problem is how can i set this tab's rendered attiributes to false when i close the tab. I set with setRendered method but the problem is renderTab1 variable still holds True. What i want to do is; setting renderTab1 variable to "False". By the way i have many tabs like 20-25. If you have any better solution you can share.

my xhtml;

   <p:ajax event="tabClose" listener="#{myController.onTabClose}"/>

   <p:tab id="firstTab" closable="true" 
   rendered="#{myController.renderTab1}"/>

my tabclose method;

public void onTabClose(TabCloseEvent event) {
    event.getTab().setRendered(false);
}

I was find a solution and i need to did this to solve my problem.

My solution not only did with rendered, i needed to use one variable to render tab, and one to send you to position that will be my tab inside of my tabView some like this.

in the tabView set parameters like this...

<p:tabView id="idTabView" widgetVar="tabView" dynamic="true" cache="false">
   in tab
   <p:tab rendered="#{mb.valiable == 1}"><!--the number 1 is an example-->
   </p:tab>
</p:tabView>

On commandButton where i suppose is on the first tab i put this:

<p:commandButton
actionListener="mb.activeTab()"
update="@form"
oncomplete="PF('tabView').select(1);" <!--this line send to tab that you are rendering with your flag in mb "variable" if you are render TAB in position three you need to put PF('tabView').select(2);-->

on my MAnagedBean method:

mb{
   private int valiable;

   public voi activeTab(){
            setValiable(1);
   }

   //setter y getters
}

i hope help you my solution. regards

The rendered property of a JSF component is resolved multiple times throughout the JSF lifecycle, so setting it manually on an event is unlikely to work by the time JSF actually begins rendering. The rendered attribute however can take the following values:

  1. A boolean property: Eg. rendered="#{myController.booleanProperty}"

  2. A method that returns a boolean: Eg. rendered="#{myController.doStuffAndReturnBoolean()}"

  3. An EL expression that resolves to a boolean value: Eg. rendered="#{myController.intValue gt 3}"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM