【问题标题】:p:remoteCommand update attribute VS p:commandButton update attribute?p:remoteCommand 更新属性 VS p:commandButton 更新属性?
【发布时间】:2020-12-23 13:18:24
【问题描述】:

我有以下代码块,当我从 p:remoteCommand 更新“pickList”时,它会更新。

            <h:panelGrid columns="1">
            <p:panel id="panel" header="Units"
                style="margin-bottom:10px; background:#F3F2F2; margin-bottom:0px">

                <p:pickList id="pickList"
                    value="#{AdminController.unitsPickListAll}" var="selectedUnit"
                    itemLabel="#{selectedUnit}" itemValue="#{selectedUnit}" />

            </p:panel>

            <h:panelGrid columns="1" styleClass="right-alignment">
                <h:panelGroup>
                    <p:commandButton id="refereshButton" value="#{i18n.refresh}"
                        immediate="true" action="#{AdminController.getAllUnits}"
                        oncomplete="rc()" />
                    <h:outputText value="&#160;&#160;" />
                    <p:commandButton id="saveButton" value="#{i18n.save}"
                        action="#{AdminController.updateUsedUnits}" />
                        
                </h:panelGroup>
            </h:panelGrid>
        </h:panelGrid>

        <p:remoteCommand name="rc" update="panel" />

但是当我在“refereshButton”中使用“update”属性时,pickList 没有得到更新。

下面是相同的代码,但没有 p:remoteCommand 并且在 refereshButton 中有更新属性。

        <h:panelGrid columns="1">
            <p:panel id="panel" header="Units"
                style="margin-bottom:10px; background:#F3F2F2; margin-bottom:0px">

                <p:pickList id="pickList"
                    value="#{AdminController.unitsPickListAll}" var="selectedUnit"
                    itemLabel="#{selectedUnit}" itemValue="#{selectedUnit}" />

            </p:panel>

            <h:panelGrid columns="1" styleClass="right-alignment">
                <h:panelGroup>
                    <p:commandButton id="refereshButton" value="#{i18n.refresh}"
                        immediate="true" action="#{AdminController.getAllUnits}"
                        update="pickList" />
                    <h:outputText value="&#160;&#160;" />
                    <p:commandButton id="saveButton" value="#{i18n.save}"
                        action="#{AdminController.updateUsedUnits}" />
                        
                </h:panelGroup>
            </h:panelGrid>
        </h:panelGrid>

这种行为背后的原因是什么?

【问题讨论】:

    标签: jsf primefaces


    【解决方案1】:

    您获得不同结果的原因是您进行了不同的更新。您可以通过远程命令更新panel,并通过按钮更新pickList

    在您的按钮上使用update="panel" 以获得相同的结果。这也将为您节省 Ajax 请求(以及一些服务器负载)。

    【讨论】:

    • 我都试过了,从commandbutton更新面板,从remoteCommand更新pickList,第一个不起作用,第二个起作用。
    猜你喜欢
    • 2017-06-26
    • 1970-01-01
    • 2016-05-20
    • 2015-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多