简体   繁体   English

更改选项卡后无法刷新jsf中的数据表

[英]Unable to refresh datatable in jsf after tab change

This is my requirement. 这是我的要求。 I am supposed to add a record and upon successful addition and clicking on the 'View' tab, the datatable should refresh, but the table remains unchanged. 我应该添加一条记录,添加成功后单击“查看”选项卡,数据表应该刷新,但表保持不变。 I am fetching the data into the datatable from a backing bean using the getter method. 我正在使用getter方法将数据从支持bean提取到datatable中。

Inside datatable: 内部数据表:

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

I even tried using javascript methods by calling them from onTabChange event. 我什至尝试通过onTabChange事件调用它们来使用javascript方法。

1st function: 第一个功能:

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

2nd function: 第二功能:

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

Tab change code: 制表符更改代码:

<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>

But nothing seems to work. 但是似乎没有任何作用。 Any suggestions on this? 有什么建议吗?

Try adding dynamic="true" on the tabview tag. 尝试在tabview标签上添加dynamic =“ true”。 That should do the trick, assuming your save method is working, which I can't see from your post. 假设您的save方法正在工作,那应该可以解决问题,我从您的帖子中看不到。 No JavaScript is needed. 不需要JavaScript。

@Andre, the datatable will update when I refresh the whole page. @Andre,当我刷新整个页面时,数据表将更新。 But it does not update when I change the tab. 但是当我更改选项卡时它不会更新。 Here is the Save method in my bean: 这是我的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);
            }

好的,猜想没有正确的方法...因此,作为一种解决方法,我添加了一个命令按钮来手动刷新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM