【发布时间】:2020-01-02 01:24:02
【问题描述】:
我有一个表单 (frmAddPax) 来添加一些用户数据。这些数据可以手动提交,也可以通过条形码阅读器提交。当按下“Escanear”按钮时,此按钮将调用另一个表单 (frmScan) 的对话框。
此表单从条形码阅读器读取一些数据,这些数据在托管 bean 中进行处理。数据创建了一个以原始形式 (frmAddPax) 使用的对象。
问题是所有表单都有样式,因为上面没有任何数据,所有必填字段都有 required="true" 属性。
如果我再次按下“Escanear”按钮并扫描相同的数据,它会很好地显示表单。
我认为这可能是因为在表单中的数据准备好更新之前发生了验证过程,但正如我在某些问题中看到的那样 action 和 actionListener 事件发生在更新过程之前,所以我不知道。
这是表单的代码:
<h:form id="frmAddPax"
rendered="#{MB.renderStatus.isRenderFormAddPax()}">
<p:panelGrid styleClass="no-border">
<p:row>
<p:column>
<h:outputText
value="#{label['manageVipLoungeEntrance.addPassenger.firstName']} />
</p:column>
<p:column>
<p:inputText required="true"
value="#{manageVipLoungeEntranceExtMB.passenger.firstName}"
style="text-transform: uppercase;" converter="upperCaseConverter">
<f:ajax event="blur" update="@this" render="@this" />
</p:inputText>
</p:column>
...
...
<!-- BOTON ESCANEAR AGREGAR PASAJERO -->
<p:column>
<p:commandButton inmediate="true"
value="#{label['manageVipLoungeEntrance.addPassenger.button.scan']}"
onclick="showLocalDate()" update=":frmScan"
actionListener="#{manageVipLoungeEntranceExtMB.clear}"
oncomplete="{wgvScan.show()}" />
</p:column>
<!-- BOTON ESCANEAR AGREGAR PASAJERO -->
</p:row>
</p:panelGrid>
这是产生“Escanear”按钮的调用代码:
<p:commandButton inmediate="true"
value="#{label['manageVipLoungeEntrance.addPassenger.button.scan']}"
onclick="showLocalDate()" update=":frmScan"
actionListener="#{manageVipLoungeEntranceExtMB.clear}"
oncomplete="{wgvScan.show()}" />
这是处理条形码读取并使用处理过的数据更新原始表单的小部件的代码。
<p:dialog widgetVar="wgvScan" modal="true" showEffect="fade"
closeOnEscape="true" resizable="false">
<h:form id="frmScan">
<p:graphicImage value="../resources/images/barCode.png"
rendered="#{manageVipLoungeEntranceExtMB.showTablePassenger!=true}" />
<p:inputText id="itbarcode"
rendered="#{manageVipLoungeEntranceExtMB.showTablePassenger!=true}"
value="#{manageVipLoungeEntranceExtMB.barCode}" onfocus="true"
autocomplete="off" styleClass="insertData"
style="background:#ffffff; position:absolute;left:-7000;" />
<p:commandButton id="cmdReadBarcode" style="display:none"
onclick="showLocalDate()"
actionListener="#{manageVipLoungeEntranceExtMB.readBarCode}"
update=":frmAddPax :growl">
</p:commandButton>
<p:defaultCommand target="cmdReadBarcode" />
...
</h:form>
[编辑] @alibttb 回答让我找到解决方案。
我在调用对话框以监听扫描仪的按钮之前添加了一个 remoteCommand。
<p:remoteCommand name="refreshForm" process=":frmAddPax" update=":frmAddPax" />
<p:commandButton
value="#{label['manageVipLoungeEntrance.addPassenger.button.scan']}"
onclick="showLocalDate()" process="@this" update=":frmScan"
actionListener="#{manageVipLoungeEntranceExtMB.clear}"
oncomplete="{wgvScan.show()}" />
</p:column>
在处理条形码的表单对话框中,我添加了一个调用remoteCommand 的onHide 属性。 我按照建议将对话框表单的外壳更改为表单对话框。
<h:form id="frmScan">
<p:dialog widgetVar="wgvScan" modal="true" showEffect="fade"
closeOnEscape="true" resizable="false" onHide="refreshForm()">
【问题讨论】:
-
嗨,下次请创建一个minimal reproducible example。缩小到一两个输入,没有对话框,没有 css,没有面板,没有 i18n vua 包等。为我们检查事情更容易(也许你甚至自己找到解决方案。另见 stackoverflow.com/tags/jsf/info
-
感谢您的反馈,我将编辑帖子以使其更具可读性。给您带来不便深表歉意。
标签: primefaces jsf-2