I want to change tab from backing bean , how can I do that?
<h:form id=form>
<p:growl id="growl" showDetail="true" />
<p:tabView id="tabView" dynamic="true" widgetVar="detailsTab">
<p:ajax event="tabChange" listener="#{bean.onTabChange}" update=":form:growl"/>
<p:tab title="Tab1" id="emp">
<h:panelGrid columns="2" cellpadding="10">
</h:panelGrid>
</p:tab>
<p:tab title="Tab 2 " id="schedule1">
<h:panelGrid columns="2" cellpadding="10">
</h:panelGrid>
</p:tab>
<p:tab title="Tab 3" id="schedule2">
<p:schedule value="#{bean.eventModel}" slotMinutes="15"
resizable="false" widgetVar="schdule" initialDate="#{bean.dates}" draggable="true" styleClass="#{bean.selDates}"
>
<p:ajax event="dateSelect" listener="#{bean.onDateSelect}"
update="dialogBox" oncomplete="patScheduleDialog.show()"/>
<p:ajax event="eventSelect" listener="#{bean.onEventSelect}"
update="dialogBox :form:growl" oncomplete="#{bean.pevent}"/>
<p:ajax event="eventMove" listener="#{bean.onEventMove}"
update="dialogBox, :form:growl" />
</p:schedule>
<p:dialog id="dialogBox" header="Patient's Appointment Details" widgetVar="patScheduleDialog" resizable="true"
showEffect="explode" hideEffect="explode">
<h:panelGrid id="eventDetails" columns="2">
<h:outputLabel for="title" value="Title:" />
<p:inputText id="title" value="#{bean.event.title}" required="true"/>
<h:outputLabel for="from" value="From:" />
<p:inputMask id="from" value="#{bean.event.startDate}" mask="99/99/9999">
<f:convertDateTime pattern="dd/MM/yyyy" />
</p:inputMask>
<h:outputLabel for="to" value="To:" />
<p:inputMask id="to" value="#{bean.event.endDate}" mask="99/99/9999">
<f:convertDateTime pattern="dd/MM/yyyy" />
</p:inputMask>
<h:outputLabel for="allDay" value="All Day:" />
<h:selectBooleanCheckbox id="allDay" value="#{bean.event.allDay}" />
<p:commandButton type="reset" value="Reset" />
<p:commandButton value="Save" actionListener="#{bean.addEvent}" oncomplete="schdule.update();dialogBox.hide();"/>
</h:panelGrid>
</p:dialog>
</p:tab>
</p:tabView>
public void onEventSelect(ScheduleEntrySelectEvent selectEvent){
// what should I need to do here to set "Tab 2" if click on any event.
}
First, you need to set the
activeIndexattribute of your<p:tabView>, like this:<p:tabView activeIndex="#{bean.selectedTab}">. It’s anInteger.Second, in your bean method, whenever you want to change the active tab, set
selectedTabto the tab you want to be selected.Third, remember to update the
<p:tabView>.You could also do that using JavaScript. Just set the
widgetVarattribute of your<p:tabView>, like this:<p:tabView widgetVar="myTabView">.Then use the JavaScript function
myTabView.select(tabIndex), wheretabIndexis the index of the tab you want to select.You can do that at any javascript event, for example:
<p:commandButton oncomplete="myTabView.select(1)" />would select the second tab after the action of the commandButton completed.Make sure you read PrimeFaces docs.