页面加载时刷新JSF数据表 [英] JSF datatable refresh on page load

查看:108
本文介绍了页面加载时刷新JSF数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在JSF中有一个数据表,当用户选择一个下拉菜单时,该表就会被填充.该表显示的列表来自备用Bean.该支持bean在会话范围内.因此,当用户单击网页的其他链接并返回此页面时,它仍然显示具有先前选择的数据列表中的数据.

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.

我无法将后备bean放入请求范围,因为这将导致无法拥有购物车类型的应用程序.

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

推荐答案

将数据模型保留在会话范围的bean中,添加一个请求范围的bean,该bean复制来自会话范围的bean的引用,并使表单提交到该请求范围的bean并让视图使用请求范围的Bean代替.您可以在每个托管属性注入下从请求范围的bean内部访问会话范围的bean.例如

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>

其中的ShowCart可能类似于:

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

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

,而视图使用#{showCart.show}代替.

这篇关于页面加载时刷新JSF数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆