我有一个像这样的PrimeFaces 3.5 accordionPanel:
<p:accordionPanel cache="false">
<p:ajax event="tabChange" listener="#{pPRBean.onChangeTab}" />
<p:tab title="Item">
<h:outputText value="#{pPRBean.counter}"/>
</p:tab>
<p:tab title="Item">
<h:outputText value="#{pPRBean.counter}"/>
</p:tab>
<p:tab title="Item">
<h:outputText value="#{pPRBean.counter}"/>
</p:tab>
<p:tab title="Item">
<h:outputText value="#{pPRBean.counter}"/>
</p:tab>
</p:accordionPanel>
像这样的支持bean:
package com.gecolsa.test.view;
import javax.ejb.Stateless;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import org.primefaces.component.tabview.Tab;
import org.primefaces.event.TabChangeEvent;
@Stateless
@ManagedBean
@RequestScoped
public class PPRBean {
private int counter = 0;
private String firstName;
public String getFirstName(){
return firstName;
}
public void setFirstName(String firstName){
this.firstName = firstName;
}
public int getCounter() {
return counter;
}
public void setCounter(int counter) {
this.counter = counter;
}
public void onChangeTab(TabChangeEvent event){
Tab activeTab = event.getTab();
if(!activeTab.getTitle().endsWith("[Pressed]")){
activeTab.setTitle(activeTab.getTitle() + " [Pressed]");
}
System.out.println(activeTab.getTitle());
counter = counter + 1;
}
}
我的问题是:如何使用计数器的新值更改标题?它只显示“Item”,虽然选项卡返回一个新值...(我想在运行时更新选项卡的标题,无论用户点击它,还有其他信息,如小时和点击的用户)。我正在使用glassfish 3.1.2。
答案 0 :(得分:3)
您可以通过从监听器更新accordionPanel来更新选项卡,如下所示:
public void onChangeTab(TabChangeEvent event){
Tab activeTab = event.getTab();
if(!activeTab.getTitle().endsWith("[Pressed]")){
activeTab.setTitle(activeTab.getTitle() + " [Pressed]");
}
System.out.println(activeTab.getTitle());
counter = counter + 1;
RequestContext.getCurrentInstance().update("panel");
}
其中,panel是<p:accordionPanel id="panel">
由于标签没有渲染器,您必须更新整个面板而不是标签。