简体   繁体   English

p:remoteCommand 更新属性 VS p:commandButton 更新属性?

[英]p:remoteCommand update attribute VS p:commandButton update attribute?

I have the following block of code, when i update the "pickList" from the p:remoteCommand it gets updated.我有以下代码块,当我从 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" />

But when I use "update" attribute in the "refereshButton", the pickList does not get updated.但是当我在“refereshButton”中使用“update”属性时,pickList 没有得到更新。

Below is the same code but without p:remoteCommand and with update attribute in refereshButton.下面是相同的代码,但没有 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>

What this reason behind this behavior?这种行为背后的原因是什么?

The reason you are getting different results is because you are doing different updates.您得到不同结果的原因是因为您正在进行不同的更新。 You update panel from the remote command and pickList from the button.您可以通过远程命令更新panel并通过按钮更新pickList

Use update="panel" on your button to get the same result.在您的按钮上使用update="panel"以获得相同的结果。 This will also save you an Ajax request (and some server load).这还将为您节省 Ajax 请求(和一些服务器负载)。

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

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