我使用数据表来显示一些记录。用户可以使用名为 actionsDialog 的对话框添加/更改记录。在保存记录之前,会显示一个名为 reasonDialog 的模式对话框,用户必须输入当前操作的一些原因。在我的逻辑中,我在将数据保存到数据库后将原因设置为 null。
当我重复操作时出现问题。原因包含先前的值。我已经调试了代码并注意到会发生这种情况,因为原因是分配了 inputTextarea 的本地值。我怎样才能摆脱本地的值(value)?我正在使用 PrimeFaces 3.0、Mojara 2.0.4、Tomcat 7。
我的原因对话框facelet是:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.prime.com.tr/ui">
<p:dialog header="#{label.reason}" widgetVar="reasonDialog"
showEffect="fade" hideEffect="explode" modal="true" dynamic="true">
<h:panelGrid columns="2">
<p:inputTextarea rows="5" cols="40" autoResize="false"
value="#{recordsBean.reason}" maxLength="1024" />
<f:facet name="footer">
<p:outputPanel layout="block">
<p:commandButton value="ok" update="genericRecords msgs"
action="#{recordsBean.execute}"
oncomplete="reasonDialog.hide();actionsDialog.hide()" />
</p:outputPanel>
</f:facet>
</h:panelGrid>
</p:dialog>
</ui:composition>
操作对话框如下所示:
<p:dialog id="actionsDialog" widgetVar="actionsDialog" dynamic="true"
resizable="false" height="600" showEffect="fade" hideEffect="fade" modal="true">
<ui:include src="/WEB-INF/flows/genericRecord.xhtml"/>
<f:facet name="footer">
<p:outputPanel layout="block">
<p:commandButton value="save" onclick="reasonDialog.show()" />
<p:commandButton value="cancel" immediate="true"
oncomplete="actionsDialog.hide()" />
</p:outputPanel>
</f:facet>
</p:dialog>
最佳答案
您需要在显示之前更新/刷新对话框的内容。在 update
属性中引用其(相对)客户端 ID,并将 show()
从 onclick
移动到 oncomplete
以便它发生在更新之后。
<p:commandButton value="save" update="reasonDialog" oncomplete="reasonDialog.show()" />
否则它当然仍会显示关闭前的旧内容。您是通过 ajax/JS 与完全相同的页面交互,而不是新页面左右。
关于java - PrimeFaces 对话框保留以前的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11930065/