Java primefaces 3.2 menuItem bean变量未在操作上设置

Java primefaces 3.2 menuItem bean变量未在操作上设置,java,jsf,primefaces,Java,Jsf,Primefaces,我有一个xhtml页面,其中包含primefaces的菜单和选项卡控件(带有datatable)。datatable根据“type”变量(在bean中)获取值。单击每个菜单项,就会触发一个操作(onType(“param”)),并在bean中设置类型变量(如下所示)。但是现在,当我在tabView中选择一个选项卡时,类型变量再次设置为null。为什么会发生这种情况 xhtml代码: <h:form id="frm"> <p:menu> <p:me

我有一个xhtml页面,其中包含primefaces的菜单和选项卡控件(带有datatable)。datatable根据“type”变量(在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>

....                        
.....
bean代码:

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;
      }
    }
public void onType(字符串类型)
{
this.type=type;
}
公共void onChange(TabChangeEvent事件){
exchange=event.getTab().getTitle();
}
公共列表getScripList(){
if(type!=null)
{
if(类型:相等信号情况(“失败者”))
{
scripList=newArrayList();
scripList=GetScripByPriceloser(交换);
返回抄写员;
}
else if(类型.equalsIgnoreCase(“增益方”))
{
scripList=newArrayList();
scripList=GetScripByPriceloser(交换);
返回抄写员;
}
其他的
{
scripList=newArrayList();
scripList=getScripByVolumeType(交换);
返回抄写员;
}
}
其他的
{
scripList=newArrayList();
scripList=getScripByVolumeType(交换);
返回抄写员;
}
}
我哪里做错了

编辑(web.xml)

    <context-param>
    <param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
    <param-value>true</param-value>
</context-param>

javax.faces.PARTIAL_STATE_保存
真的

声明为
@ViewScoped
的bean有时行为类似于
@RequestScoped
bean,并在每次请求或回发时重新创建。原因在这篇优秀的博文中有描述:


在参考文章中,列出了一些可能的解决方案。您还可以将该值保存在会话范围中,并仅将其注入到视图/请求范围的bean中。

我使bean的视图范围仍然是无效的。您是否检查了在更改选项卡时是否重新创建了bean。在bean的构造函数中设置一个断点/日志消息来验证它。是的,每次选项卡更改都会调用构造函数。awesome blog,但没有解决我的问题。它提供了添加代码以删除部分回发并通过web.xml(在我的问题中编辑的web.xml代码)保存viewstate的解决方案,我这样做了,但问题仍然存在。我错在哪里?我不会改变国家储蓄机制。正如巴卢斯克所描述的,它有缺点。您是否确定导致此问题的标记处理程序?在会话中保存变量不是选项吗?谢谢!会话对我来说很有效(虽然只在requestScope中,不在viewScope中,我不知道为什么)。再次感谢你是救世主伴侣:)