即使侦听器什么也不返回,也总是调用p:ajax事件的不完整

问题描述 投票:3回答:2

我有一个具有不同行的dataTable,当我选择特定行时,我不想在特定行上执行任何onClick事件。我想防止在oncomplete中调用show()方法。我尝试了不同的方法,但是我无法停止。

下面是我的代码。

<h:form id="availableBooksForm">
        <p:messages />
        <p:panel>
            <p:remoteCommand name="show" action="#{boAction.selectPromotion}" />

            <p:dataTable id="BooksTable" value="#{userProfile.availableBooks}"
                var="res" selectionMode="single" rowKey="#{res.promotionId}"
                rows="#{referenceData.recordsPerPage}" lazy="true"
                resizableColumns="true" paginator="true"
                paginatorTemplate="#{referenceData.paginatorTemplate}"
                paginatorPosition="bottom" paginatorAlwaysVisible="false"
                style="margin-top: 5px; text-overflow: ellipsis;">

                <p:ajax event="rowSelect" listener="#{boAction.onSelectPromotion}"
                    oncomplete="show()" />

                <p:column headerText="#{msg.promotionInfo}">
                    <p:panelGrid columns="2" columnClasses="pct50,"
                        style="font-size: 12px">

                        <h:outputText value="#{msg.promoCode}" />
                        <h:outputText value="#{res.promoCode}">
                            <f:convertNumber pattern="#{userProfile.displayStringFormat}" />
                        </h:outputText>

                        <h:outputText value="#{msg.promoName}" />
                        <h:outputText value="#{res.promoName}">
                            <f:convertNumber pattern="#{userProfile.displayStringFormat}" />
                        </h:outputText>
                    </p:panelGrid>
                </p:column>
            </p:dataTable>
        </p:panel>

这里我正在调用onSelectPromotion方法,不返回任何内容,如下所示:

public void onSelectPromotion(SelectEvent event) {

    String selectedType = ((AllBooks) event.getObject()).getPromoType();
    if(selectedType.equals(BookType.getBookType)) {
        return;
    }
}

此后show()方法正在调用boAction.selectPromotion操作。我不想调用此方法。如何通过从dataTable中选择特定的行来防止这种情况。

如果我从表中选择行,我不想执行此方法。

public String selectPromotion() {
    //some code is executing here
}
jsf events primefaces listener onselect
2个回答
2
投票

在您的Ajax侦听器中使用return不会阻止oncomplete的调用,它只会停止执行该方法。基本上,您的听众是无用的。参见:

但是您可以不同地解决您的问题。在p:dataTable中,使用selection属性保留对当前所选行的引用。例如,selection="#{userProfile.selectedBook}"(将selectedBook添加到您的bean中,并确保有getter和setter)。然后,在selectPromotion方法中,您可以简单地从bean中获取selectedBook并确定是否需要结束或继续处理其余代码。

您可以在陈列柜中see the selection attribute in action


0
投票

我已尝试使用xhtml文件中的以下代码段,但不允许选择该行。

selection

通过添加条件的disabledSelection,我不允许使用代码<p:dataTable id="BooksTable" value="#{userProfile.availableBooks}" var="res" selectionMode="single" rowKey="#{res.promotionId}" rows="#{referenceData.recordsPerPage}" lazy="true" resizableColumns="true" paginator="true" paginatorTemplate="#{referenceData.paginatorTemplate}" paginatorPosition="bottom" paginatorAlwaysVisible="false" style="margin-top: 5px; text-overflow: ellipsis;" disabledSelection="#{(res.promoName == 'Your String')}"> 在dataTable中选择特定行:>

© www.soinside.com 2019 - 2024. All rights reserved.