JSF PrimeFaces DataTable行无法使用确认对话框删除

时间:2016-08-03 14:31:41

标签: primefaces datatable jsf-2.2

我的问题是我要删除Datatable第二页的最后一行(数据)。删除成功后,Datatable页面将更改为上一页。之后我无法从第一页删除该行,因为页面更改自动发生。

我认为当从第二页删除最后一行时,未设置数据表组件页面。

如果我手动将页面从第2页更改为第1页,我可以删除第一页上的记录。

请找到数据表的代码:

<p:outputPanel id="associatetable">
     <p:dataTable first="#{masterBean.first}" 
    value="#{myBean.AssociationDtoList}"
    var="itasc" id="ascTable"
    currentPageReportTemplate="{currentPage} / {totalPages}"
    rowKey="#{itasc}" rows="20" paginator="true"
    paginatorPosition="bottom" rowIndexVar="idx"
    paginatorTemplate=" {FirstPageLink} {PreviousPageLink} {PageLinks}   {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
    rowsPerPageTemplate="20,50,100"
    emptyMessage="#{msg['pds.no_records_found']}"
     styleClass="">
    <p:column headerText="#" styleClass="width-10">
        <h:outputText value="#{idx+1}" />
    </p:column>

    <p:column headerText="#{msg['pds.code']}"
        styleClass="text-left">
        <h:outputText value="#{itasc.code}" />
    </p:column>

    <p:column headerText="#{msg['pds.name']}"
        styleClass="text-left">
        <h:outputText
            value="#{masterBean.processLength(itasc.name,20)}" />
    </p:column>
    <p:column headerText="#{msg['pds.profile']}"
        styleClass="text-left">
        <h:outputText value="#{itasc.profile}" />
    </p:column>

    <p:column headerText="#{msg['pds.select']}"
        styleClass="associate">
        <p:commandButton value="#{msg['pds.remove']}"
            id="rmv"
            class="btn btn-info cus-btn btn-sm btn-delete"
            immediate="true"
            disabled="#{myBean.action eq 'View'}"
            action="#{myBean.setAssociationDto(itasc)}">
            <f:setPropertyActionListener value="#{itasc}"
                for="rmv"
                target="#{myBean.AssociationDto}" />
            <p:ajax />
            </p:commandButton>
        </p:column>
    </p:dataTable>
</p:outputPanel>        

这是我的对话框:

<p:dialog header="#{msg['pds.confirm_del']}" widgetVar="removeDlg"
    modal="true" position="center" resizable="false"
    styleClass="cus-model-popup">
    <h:form>
        <h5>#{msg['pds.remove_msg']}</h5>

        <h:commandButton
            styleClass="pull-right btn btn-info btn-sm left-mspace"
            value="#{msg['pds.no']}" onclick="PF('removeDlg').hide();">
            <f:ajax />
        </h:commandButton>
    <h:commandButton class="blue-button pull-right btn btn-info btn-sm"
        value="#{msg['pds.yes']}"
        action="#{myBean.deAssociateProfiles}"
        onclick="PF('removeDlg').hide();">
        <f:ajax />
    </h:commandButton>

    </h:form>
</p:dialog>

这是我的Bean代码:Bean是sessionScoped

public String setAssociationDto(AssociationDto dto) {
    log.info("AssociationDto Called " + dto);
    AssociationDto = new AssociationDto();
    AssociationDto.setId(dto.getId());
    RequestContext context = RequestContext.getCurrentInstance();
    context.execute("PF('removeDlg').show();");
    return null;
}

public void deAssociateProfiles() {

    log.info("deAssociateProfiles Called "
            + AssociationDto);
    int keyLocation = AssociationDtoList
            .indexOf(AssociationDto);
    AssociationDtoList.remove(keyLocation + 0);
    AssociationDto = new AssociationDto();
    RequestContext.getCurrentInstance().update("form:form:associatetable");
}

datatable

请帮我换页(自动)或建议其他方式。 提前谢谢。

0 个答案:

没有答案