Search code examples
sessionjsfscopeactionlistener

Variable value is not reset after session cleanup for sessionscoped bean


<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>

faces-config:

 <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>

simple bean for action listening:

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;
     }

    }

use case:
1. click on "Buy" button
2. content of basket is incremented
3. click Shift-Ctrl-Del (clean cookie and cache) in FF and Refresh
4. counter of basket remained same

As I understand, session scope specifies,that this counter (step 2) will be incremented in session scope only, and after cookies,cache clean up should be resetted?

The problem,that it does not.


Solution

  • Resolved by providing persistent cookies