Недавно мы перешли на PrimeFaces 11 и изменили наш код, чтобы открывать и закрывать диалог согласно https://primefaces.github.io/primefaces/11_0_0/#/core/dialogframework.
Открытие диалогового окна с кнопками «ОК» и «Отмена» работает нормально, но при нажатии кнопки «ОК» или «Отмена» внутри диалогового окна диалоговое окно не закрывается, и в приложении, а также в журнале сервера нет ошибок.
Пример кода выглядит следующим образом:
Шаблон Dialog.xhtml
<?xml version = "1.0" encoding = "UTF-8"?>
<!DOCTYPE html>
<html xmlns = "http://www.w3.org/1999/xhtml" xmlns:h = "http://java.sun.com/jsf/html" xmlns:f = "http://java.sun.com/jsf/core"
xmlns:ui = "http://java.sun.com/jsf/facelets" xmlns:p = "http://primefaces.org/ui">
<!-- HEAD -->
<h:head>
<h:outputScript library = "js" name = "growl_updater.js" />
<h:outputScript library = "js" name = "spear.js" />
<title><h:outputText value = "#{dialogTitle}" /></title>
</h:head>
<!-- /HEAD -->
<h:body class = "dialog-body">
<div class = "dialog-wrapper">
<s:tooltip />
<!-- CONTENT include -->
<p:outputPanel id = "dialog_content">
<ui:insert name = "dialog_content">
<ui:include src = "content.xhtml" />
</ui:insert>
</p:outputPanel>
<!-- /CONTENT include -->
<h:form id = "dialog_conversation_form" rendered = "#{not empty killCid and not empty conversationModel}">
<p:remoteCommand name = "handleClose" actionListener = "#{conversationModel.endConversation}" async = "false" />
</h:form>
<!-- Widgets -->
<p:blockUI widgetVar = "content_blocker" block = "dialog_content">
<ui:include src = "/templates/blockui/loading.xhtml" />
</p:blockUI>
<ui:insert name = "exception_handler">
<ui:include src = "exception-handler.xhtml" />
</ui:insert>
<ui:insert name = "messages">
<p:growl id = "dialog_warn_messages" for = "dialog_warn_messages" widgetVar = "dialog_warn_messages_widget" globalOnly = "true" sticky = "true" severity = "warn" redisplay = "false" />
<p:growl id = "dialog_error_messages" for = "dialog_error_messages" widgetVar = "dialog_error_messages_widget" globalOnly = "true" sticky = "true" severity = "error,fatal" >
<p:autoUpdate />
</p:growl>
<p:growl id = "dialog_info_messages" for = "dialog_info_messages" widgetVar = "dialog_info_messages_widget" globalOnly = "true" sticky = "false" severity = "info" >
<p:autoUpdate />
</p:growl>
<p:growl id = "warn_messages" widgetVar = "warn_messages_widget" globalOnly = "true" sticky = "true" severity = "warn" redisplay = "false" />
<p:growl id = "error_messages" widgetVar = "error_messages_widget" globalOnly = "true" sticky = "true" severity = "error,fatal" >
<p:autoUpdate />
</p:growl>
<p:growl id = "info_messages" widgetVar = "info_messages_widget" globalOnly = "true" sticky = "false" severity = "info" >
<p:autoUpdate />
</p:growl>
</ui:insert>
</div>
</h:body>
</html>
TestDialog.xhtml
<!DOCTYPE html>
<html xmlns = "http://www.w3.org/1999/xhtml" xmlns:h = "http://java.sun.com/jsf/html" xmlns:f = "http://java.sun.com/jsf/core"
xmlns:ui = "http://java.sun.com/jsf/facelets" xmlns:p = "http://primefaces.org/ui">
<ui:composition template = "/templates/dialog/dialog.xhtml">
<ui:param name = "dialogTitle" value = "#{testMsg}" />
<ui:define name = "dialog_content">
<h:form id = "test_form">
<p:panel>
<p:panelGrid id = "test_group" columns = "2">
<h:panelGroup>
<p:focus context = "test_group" />
<p:outputLabel for = "test_value" value = "#{testMsg.testValue}" />
</h:panelGroup>
</p:panelGrid>
<p:toolbar>
<p:toolbarGroup>
<p:commandButton value = "#{testMsg.okayBtn}" actionListener = "#{testActions.acceptAndClose()}">
</p:commandButton>
<p:commandButton value = "#{testMsg.cancelBtn}" actionListener = "#{testActions.cancel()}"
partialSubmit = "true" process = "@this">
</p:commandButton>
</p:toolbarGroup>
</p:toolbar>
</p:panel>
</h:form>
</ui:define>
</ui:composition>
</html>
TestAction.java
@Named
@RequestScoped
public class TestAction {
public static final Map<String, Object> POPUP_OPTIONS;
public static final String URL = "/popup/TestDialog.xhtml";
static {
Map<String, Object> map = new HashMap<String, Object>();
map.put("modal", Boolean.TRUE);
map.put("draggable", Boolean.FALSE);
map.put("resizable", Boolean.FALSE);
POPUP_OPTIONS = map;
}
private BigDecimal value;
public void acceptAndClose() {
PrimeFaces.current().dialog().closeDynamic(value);
}
public void cancel() {
PrimeFaces.current().dialog().closeDynamic(null);
}
}
На странице main.xhtml есть кнопка «Проверить», которая открывает диалоговое окно.
<p:commandButton id = "value_btn" value = "#{buttonMsg.valueBtn}"
action = "#{mainAction.openValueAction}" process = "@form"
disabled = "#{mainAction.testValueButtonDisabled}" onstart = "PF('content_blocker').show()"
oncomplete = "PF('content_blocker').hide()" update = "@form">
<f:param name = "cid" value = "#{mainModel.conversationId}" />
<p:ajax event = "dialogReturn" listener = "#{mainAction.valueListener}" update = "@form" />
</p:commandButton>
MainAction.java
@Named
@RequestScoped
@ExceptionsReported
public class MainAction {
public void openValueAction() {
Map<String, List<String>> params = new HashMap<String, List<String>>();
params.put("cid", Arrays.asList(new String[] { model.getConversationId().toString() }));
PrimeFaces.current().dialog().openDynamic(TestAction.URL, TestAction.POPUP_OPTIONS, params);
}
public void valueListener(SelectEvent event) {
// get value from Okay or Cancel from Dialog
}
}
Тот же код работает со старой версией простых лиц, использующих RequestContext.getCurrentInstance().openDialog
и RequestContext.getCurrentInstance().closeDialog
.
Я пробовал различные решения и прошел https://github.com/primefaces/primefaces/issues, но не смог найти проблему.
обнаружили проблему, у нас есть собственный файл .js в удаленной системе, который переопределяет открытие и закрытие диалоговых функций, что приводит к этой проблеме.
Мы обновляем этот пользовательский файл .js в соответствии с Primefaces 11, после чего открытие и закрытие диалогового окна снова работает.