【发布时间】:2012-05-25 05:31:28
【问题描述】:
我有一个带有primefaces 的菜单和选项卡控件(带有数据表)的xhtml 页面。数据表根据“类型”变量(在 bean 中)获取值。单击每个菜单项时会触发一个操作(onType("param")),并且在 bean 中设置类型变量(如下所示)。但是现在当我在 tabView 中选择一个选项卡时,类型变量再次设置为 null。为什么会这样。
xhtml代码:
<h:form id="frm">
<p:menu>
<p:menuitem value="price losers" action='#{equityBean.onType("losers")}'/>
<p:menuitem value="price gainers"/>
<p:menuitem value="price volume"/>
</p:menu>
<p:tabView activeIndex="#{equityBean.activeIndex}">
<p:ajax event="tabChange" listener="#{equityBean.onChange}" update=":frm"/>
<p:tab title="NSE">
<p:dataTable value="#{equityBean.scripList}" var="scrip">
....
</p:dataTable>
</p:tab>
<p:tab title="BSE">
<p:dataTable value="#{equityBean.scripList}" var="scrip">
.....
</p:dataTable>
</p:tab>
</p:tabView>
</h:form>
豆码:
public void onType(String type)
{
this.type=type;
}
public void onChange(TabChangeEvent event) {
exchange=event.getTab().getTitle();
}
public List<MasterScrip> getScripList() {
if(type!=null)
{
if(type.equalsIgnoreCase("losers"))
{
scripList=new ArrayList<MasterScrip> ();
scripList=getScripByPriceLosers(exchange);
return scripList;
}
else if(type.equalsIgnoreCase("gainers"))
{
scripList=new ArrayList<MasterScrip> ();
scripList=getScripByPriceLosers(exchange);
return scripList;
}
else
{
scripList=new ArrayList<MasterScrip> ();
scripList=getScripByVolumeType(exchange);
return scripList;
}
}
else
{
scripList=new ArrayList<MasterScrip> ();
scripList=getScripByVolumeType(exchange);
return scripList;
}
}
我哪里错了?
已编辑(web.xml):
<context-param>
<param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
<param-value>true</param-value>
</context-param>
【问题讨论】:
-
我让 bean viewscoped 仍然无法正常工作
-
您是否检查过 bean 是否在选项卡更改时重新创建。在 bean 的构造函数中设置断点/日志消息来验证它。
-
是的,每次选项卡更改都会调用构造函数。
标签: java jsf primefaces