首页 > 解决方案 > p:remoteCommand 更新属性 VS p:commandButton 更新属性?

问题描述

我有以下代码块,当我从 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”中使用“更新”属性时,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>

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

标签: jsfprimefaces

解决方案


您得到不同结果的原因是因为您正在进行不同的更新。您panel可以通过远程命令和pickList按钮进行更新。

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


推荐阅读