开发者

JSF datatable refresh on page load

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 wi开发者_运维问答th 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜