jsf - 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="  " />
<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="  " />
<p:commandButton id="saveButton" value="#{i18n.save}"
action="#{AdminController.updateUsedUnits}" />
</h:panelGroup>
</h:panelGrid>
</h:panelGrid>
这种行为背后的原因是什么?
解决方案
您得到不同结果的原因是因为您正在进行不同的更新。您panel
可以通过远程命令和pickList
按钮进行更新。
在您的按钮上使用update="panel"
以获得相同的结果。这也将为您节省一个 Ajax 请求(和一些服务器负载)。
推荐阅读
- r - 如何根据字符串绑定R中的行?
- c++ - 运算符重载;必须是二元运算符(带 3 个参数)
- php - Firefox 量子(版本-68.0.1)上传一个文件然后自动重新加载选项卡并多次上传同一个文件时出现问题
- php - 类中的函数未捕获的错误
- jquery - 如何将此代码的当前 url 链接附加到 COPY THS TEXT?
- flutter - 在 Flutter 应用中支持自定义文件扩展名(在 Flutter 中打开扩展名为 .abc 的文件)
- javascript - 在 Android 运行时访问浏览器的 DOM 内容
- excel-formula - 数组式搜索功能中结果的怪异
- python-3.x - 将 DataFrame 中的每个值附加到 np 向量,按列分组
- python - 运行 numpy select 时出现 TypeError