标签更改后,jsf中无法刷新数据表

Unable to refresh datatable in jsf after tab change

本文关键字:刷新 数据表 jsf 标签      更新时间:2023-09-26

这是我的要求。我应该添加一条记录,并在成功添加和单击"视图"选项卡后,数据表应该刷新,但表保持不变。我正在使用getter方法从后备bean中获取数据到数据表中。

内部数据表:

<p:dataTable id="ci_table" value="#{ciConfigBean.ciList}" var="cid" scrollable="true" selectionMode="single" selection="#{ciConfigBean.ciConfigSave}"
            rowKey="#{cid.ciConfigId}" editable="true" resizableColumns="true">

我甚至尝试使用javascript方法,从onTabChange事件调用它们。

第一个函数:

function onLoad() {
             alert("tab"); 
            var oTable;
            oTable = $('#ci_table').dataTable();
            oTable.fnClearTable( 0 );
            oTable.fnDraw();
        }

第二功能:

var oTable;
            $(document).ready(function() {
                    oTable = $('#ci_table').dataTable({
                        "bProcessing" : true,
                        "bServerSide" : true,
                        "sAjaxSource" : '${request.contextPath}'
                                + '/ciConfigBean/getCiList'
                        });
                        oTable.fnReloadAjax();
                });

制表符更改代码:

<p:tab id="ci" title="CI">
            <p:tabView id="insideCi" onTabChange="onLoad()"
                activeIndex="#{home.activeInner}">
                <p:tab id="ciList" title="CI List">
                    <ui:include src="ci/ciList.xhtml" />
                </p:tab>
                <p:tab id="newCi" title="New CI">
                    <ui:include src="ci/newCi.xhtml" />
                </p:tab>
            </p:tabView>
        </p:tab>

但是似乎什么都不起作用。对此有什么建议吗?

尝试在tabview标签上添加dynamic="true"。这应该做的伎俩,假设你的保存方法是工作的,我不能从你的帖子看到。

@Andre,当我刷新整个页面时,数据表将更新。但是当我更改选项卡时它不会更新。下面是我的bean中的Save方法:

public void saveCiConfig() throws SystemException {
    long ciId = CounterLocalServiceUtil.increment(CIConfig.class
                    .getName());
            ciConfigSave.setCiConfigId(ciId);
            ciConfigSave.setProjectId(0);
            ciConfigSave.setParentCIConfigId(0);
            ciConfigSave.setCreatedDate(new Date());
            ciConfigSave.setCreatedBy(FacesUtil.getUserId());
            ciConfigSave.setUpdatedDate(null);
            ciConfigSave.setUpdatedBy(0);
            if (enable == Boolean.TRUE) {
                ciConfigSave.setStatus(DataConstant.STATUS_ACTIVE);
            } else {
                ciConfigSave.setStatus(DataConstant.STATUS_INACTIVE);
            }
            ciConfigSave.setSetupComplete(Boolean.FALSE);
            try {
                  CIConfigLocalServiceUtil.addCIConfig(ciConfigSave);
                FacesMessageUtil
                        .addGlobalInfoMessage("ci.message.submitSuccess");
                new Home().setActiveOuter(0);
                new Home().setActiveInner(1);
                setEditMode(Boolean.FALSE);
                resetInit();
            } catch (SystemException e) {
                FacesMessageUtil
                        .addGlobalErrorMessage("ci.message.submitFailed");
                log.error("error while saving the CI Configuration", e);
            }

好吧,我猜没有合适的方法…因此,作为一种变通方法,我添加了一个命令按钮来手动刷新。