tags:

views:

535

answers:

1

I have a data table in JSF which gets populated when user selects a drop-down menu. The list that table shows comes from a backing bean. This backing bean is in the session scope. So when user clicks on other links of the webpage and comes back to this page, it still shows the data from the data list with the previous selections.

Question is - how to make sure, that data gets reset when user leaves the page so that when user comes back in, they can see a fresh page with no data in it.

I can not put the backing bean in request scope as that will make it impossible to have a cart type application.

+3  A: 

Keep the datamodel in the session scoped bean, add a request scoped bean which copies the reference from the session scoped bean and let the form submit to that request scoped bean and let the view use the request scoped bean instead. You can access the session scoped bean from inside a request scoped bean by under each managed property injection. E.g.

<managed-bean>
    <managed-bean-name>cart</managed-bean-name>
    <managed-bean-class>com.example.Cart</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
</managed-bean>

<managed-bean>
    <managed-bean-name>showCart</managed-bean-name>
    <managed-bean-class>com.example.ShowCart</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
    <managed-property>
        <property-name>cart</property-name>
        <value>#{cart}</value>
    </managed-property>
</managed-bean>

wherein the ShowCart can look like:

public class ShowCart {
    private Cart cart;
    private Cart show;
    // +getters+setters

    public String submit() {
        show = cart;
        // ...
    }
}

and the view uses #{showCart.show} instead.

BalusC
Thanks BalusC for the solution. I shall use it, I hope this is available in JSF 1.1 as well.
Shamik
Truly, it is :)
BalusC