Jsf dialogReturn事件上的detectUnsavedChanges
在我看来,我有一个禁用的Jsf dialogReturn事件上的detectUnsavedChanges,jsf,primefaces,Jsf,Primefaces,在我看来,我有一个禁用的p:inputText,显示一些地址信息。p:inputText的值由对话框return监听器onAdresseDialogReturn()设置。除了这个inputText,我还有几个其他输入字段(p:selectOneMenu,p:inputText) 每当我更改其他输入组件的一些值并试图离开页面时,就会从detectUnsavedChangesJavaScript中得到一个警告对话框 我现在的问题是,当对话框return侦听器更改inputText字段的值时,我也需要
p:inputText
,显示一些地址信息。p:inputText
的值由对话框return
监听器onAdresseDialogReturn()
设置。除了这个inputText,我还有几个其他输入字段(p:selectOneMenu
,p:inputText
)
每当我更改其他输入组件的一些值并试图离开页面时,就会从detectUnsavedChanges
JavaScript中得到一个警告对话框
我现在的问题是,当对话框return
侦听器更改inputText字段的值时,我也需要此警告消息,但这不会发生
所以我的问题是,我如何才能做到这一点
在这里,使用primefaces对话框框架使用带有p:commandButton
的p:inputText
:
<ui:composition>
<ui:define name="head">
<h:outputScript name="js/detectUnsavedChanges.js"/>
</ui:define>
<ui:define name="content">
<h:form id="form">
<p:panelGrid>
<p:row>
<p:column>
<p:commandButton id="save" value="Save" ajax="false" action="#{bean.save}"/>
</p:columns>
</p:row>
</p:panelGrid>
<p:panelGrid>
<p:row>
<p:column>
<p:inputText id="adresse" disabled="true" size="50"
value="#{bean.adresse}"/>
<p:commandButton id="adresseAuswahl"
title="Adresse bearbeiten"
process="@this"
actionListener="#{bean.showAdresseDialog}">
<p:ajax event="dialogReturn" update="adresse"
listener="#{bean.onAdresseDialogReturn}"/>
</p:commandButton>
</p:columns>
</p:row>
</p:panelGrid>
</h:form>
</ui:define>
</ui:composition>
下面是BalusC提到的JavaScript代码:
我的环境:Wildfly上的Primefaces 6.0-10.0.0.Final
任何提示欢迎-谢谢 尝试将
oncomplete
属性添加到p:ajax
中的commandButton
中。
我不知道是否可以将p:ajax
组件放入p:commandButton
中,但是在oncomplete属性中,应该调用setConfirmUnload(true),如下所示:
<p:commandButton id="adresseAuswahl"
title="Adresse bearbeiten"
process="@this"
actionListener="#{bean.showAdresseDialog}">
<p:ajax event="dialogReturn" update="adresse"
listener="#{bean.onAdresseDialogReturn}" oncomplete="setConfirmUnload(true)"/>
</p:commandButton>
尝试将
oncomplete
属性添加到p:ajax
中的commandButton
中。
我不知道是否可以将p:ajax
组件放入p:commandButton
中,但是在oncomplete属性中,应该调用setConfirmUnload(true),如下所示:
<p:commandButton id="adresseAuswahl"
title="Adresse bearbeiten"
process="@this"
actionListener="#{bean.showAdresseDialog}">
<p:ajax event="dialogReturn" update="adresse"
listener="#{bean.onAdresseDialogReturn}" oncomplete="setConfirmUnload(true)"/>
</p:commandButton>
默认情况下,p:commandButton
已经是ajaxified,如PrimeFaces showcase和Documentation中所述,我认为是这样。我会在对话框中使用p:ajax
组件来监听关闭事件。如下所示:
但是现在总是会出现确认对话框-即使在我的OnAddresseDialogReturn()
侦听器中changedBauvorhabenAdresse
为false。我尝试了oncomplete=“setConfirmUnload(#{bean.changedbauvorhabenadrese})”
但是changedbauvorhabenadrese
的getter在页面创建期间只调用一次,而在ajax事件发生时不会调用!如何解决这个问题?是的,当JSF创建HTML页面并评估所用组件的客户端属性时,它只调用一次。将按钮id添加到ajax更新(update=“adresse-adresseAuswahl”
)重新评估changedbauvorhabenadrese
,并按预期显示模具确认对话框-谢谢!正如PrimeFaces showcase和Documentation中提到的,默认情况下,p:commandButton
已经是ajaxified。我会在对话框中使用p:ajax
组件来监听关闭事件。如下所示:
但是现在总是会出现确认对话框-即使在我的OnAddresseDialogReturn()
侦听器中changedBauvorhabenAdresse
为false。我尝试了oncomplete=“setConfirmUnload(#{bean.changedbauvorhabenadrese})”
但是changedbauvorhabenadrese
的getter在页面创建期间只调用一次,而在ajax事件发生时不会调用!如何解决这个问题?是的,当JSF创建HTML页面并评估所用组件的客户端属性时,它只调用一次。将按钮id添加到ajax更新(update=“adresse-adresseAuswahl”
)重新评估changedbauvorhabenadrese
,并按预期显示模具确认对话框-谢谢!
<p:commandButton id="adresseAuswahl"
title="Adresse bearbeiten"
process="@this"
actionListener="#{bean.showAdresseDialog}">
<p:ajax event="dialogReturn" update="adresse"
listener="#{bean.onAdresseDialogReturn}" oncomplete="setConfirmUnload(true)"/>
</p:commandButton>