未呈现选项卡内容时调用 Rich TabPanel 的 getter [英] Rich TabPanel's getters invoked when tab content not rendered

查看:61
本文介绍了未呈现选项卡内容时调用 Rich TabPanel 的 getter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于 RichFace (3.3.3) TabPanel 的问题.我参与了两个使用 TabPanel 的项目.在每个项目中,我注意到不可见的选项卡上的组件仍然调用了它们的getter"方法.

I have a question about RichFace's (3.3.3) TabPanel. I have worked on two projects that have used the TabPanel. On each project, I have noticed that components that are on tabs that are not visible still have their "getter" methods called.

例如,第一个选项卡上有一个数据表,并且任何时候都从绑定的 bean 的任何其他 选项卡(包括 ajax 请求)发出请求到第一个选项卡上的数据表仍然调用了它的 getter.

For example, the first tab has a datatable on in and any time requests are made from any of the other tabs (including ajax requests) the bean that is bound to the datatable on the first tab still has its getter called.

我假设会发生这种情况(即使选项卡当前未在 UI 中呈现),因为组件仍在组件层次结构中?换句话说,所有组件都是父选项卡面板的子组件,因此会根据每个请求进行处理......即使它们不可见.

I assume this happens (even though the tab is currently not rendered in the UI) because the component is still in the component hierarchy? In other words, all components are children of the parent tab panel and so are processed on each request..even if they aren't visible.

好的...如果我的假设是真的,那么我需要一种方法来为未使用的选项卡调用数据检索逻辑.我已经阅读了关于延迟加载数据(没有将数据检索逻辑放在 getter 中)的帖子,因为 getter 可能会被多次调用.我正在尽我所能坚持这一点;我看到的问题是,即使我绑定到使用请求范围定义的表(在第一个选项卡上)的 bean 并且 getter 延迟加载表的数据,bean 被实例化,并且数据在每个来自 其他 标签的 ajax 请求上(懒惰地)拉取.

Ok...if my assumption is true, then I need a way to not have data retrieval logic invoked for tabs that aren't being used. I've read the postings about lazily loading data (not putting data retrieval logic in the getter) because the getters may be called many times. I'm doing my best to adhere to that; the problem that I'm seeing is that even though I have the bean that is bound to the table (on tab one) defined with request scope and the getter is lazily loading the data for the table, the bean gets instantiated, and the data pulled (lazily), on each ajax request from other tabs.

必须有办法解决这个问题,即从 RichFace 的 TabPanel 中提取所有内容并滚动我自己的内容.

There's got to be a way around this short of pulling all content out of the RichFace's TabPanel and rolling my own.

我尝试使bean绑定到表会议范围和缓存"getter返回表的数据,但问题有没有生命周期方法绑定到选项卡再次呈现时(通过手动单击选项卡或以编程方式选择选项卡).

I tried making the bean bound to the table session scoped and "caching" the data that the getter returns to the table, but the problem there is that there is no lifecycle method to bind to for when the tab gets rendered again (either via manually clicking the tab or programmatically selecting the tab).

如果您有任何建议,我将不胜感激.

I'd appreciate any suggestions.

推荐答案

tabPanel 有一个名为 selectedTab 的属性,每次选择一个选项卡时都会调用一个 getter/setter.您可以使用 setter 方法在选择特定选项卡时刷新数据.您还可以通过将选项卡的内容包装在 c:if 元素中来防止在每个选项卡中调用 getter 方法,如果测试返回 false,它将停止该 html 段.例如:

The tabPanel has an attribute called selectedTab that calls a getter/setter every time a tab is selected. You could use the setter method to refresh the data when a specific tab is selected. You could also prevent the calling of getter methods within each tab by wrapping the content of the tab within a c:if element, which stops that segment of the html if the test returns false. For example:

<ui:composition 
    xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:rich="http://richfaces.org/rich
    xmlns:c="http://java.sun.com/jstl/core">
    <rich:tabPanel selectedTab="#{pageScopedBean.selectedTab}">
        <rich:tab id="particularTab" label="A Tab">
            <c:if test="#{pageScopedBean.selectedTab eq 'particularTab'}">
                <!-- tab contents -->
            </c:if>
        </rich:tab>
    </rich:tabPanel>
</ui:composition>

然后在 Java 中,在 pageScopedBean 上创建 getter 和 setter 方法:

Then within the Java, create getter and setter methods on pageScopedBean:

@Name("pageScopedBean")
@Scope(ScopeType.PAGE)
public class PageScopedBean {
    private String selectedTab = "";
    public String getSelectedTab() {
        return selectedTab;
    }
    public void getSelectedTab(String selectedTab) {
        this.selectedTab = selectedTab;
        if (this.selectedTab == "particularTab") {
            // refresh table
        }
    }

这篇关于未呈现选项卡内容时调用 Rich TabPanel 的 getter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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