在sessioncoped bean的会话清理后,不会重置变量值

时间:2010-11-21 18:04:03

标签: session jsf scope actionlistener

<h:form>
<h:commandButton value="Buy" styleClass="button-buy" actionListener="#{basketCount.incrementBasketCount}" immediate="true">
</h:commandButton>
</h:form>

jsf2 part:

 <li class="basket">    
  #{basketCount.basketCount}
 </li>

面-配置:

 <managed-bean>
  <managed-bean-name>basketCount</managed-bean-name>
  <managed-bean-class>main.BasketCount</managed-bean-class>
  <managed-bean-scope>session</managed-bean-scope>
 </managed-bean>

用于行动倾听的简单bean:

package main;

import java.io.Serializable;

    public class BasketCount implements Serializable {

     private static final long serialVersionUID = -4576074045587545642L;

     int inBasketCount = 0;

     public void incrementBasketCount(javax.faces.event.ActionEvent event) {
      inBasketCount++;
     }

     public int getBasketCount() {
      return inBasketCount;
     }

    }

用例:
1。点击“购买”按钮
2。篮子的内容增加了
3。点击FF中的Shift-Ctrl-Del(清除cookie和缓存)并刷新
4。篮子的柜台保持不变

据我所知,会话范围指定此计数器(步骤 2 )将仅在会话范围内递增,并且在cookie之后,应重置缓存清理?

问题是,它没有。

1 个答案:

答案 0 :(得分:1)

通过提供持久性cookie解决