【发布时间】:2020-06-28 02:22:13
【问题描述】:
我在展示中扩展了 PF ViewExpiredException 处理示例......请参阅
https://www.primefaces.org/showcase/ui/misc/exceptionHandler.xhtml
我有一个简单的按钮,它执行 AJAX 请求,然后通过oncomplete 显示一个 PF 对话框。动作被执行,抛出异常,显示“会话过期对话框”,但刚刚单击的按钮也想显示一个对话框。
您得到的是异常对话框位于执行实际工作的对话框之下。
faces-config.xml:
<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.2"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
<application>
<action-listener>org.primefaces.application.DialogActionListener</action-listener>
<navigation-handler>org.primefaces.application.DialogNavigationHandler</navigation-handler>
<view-handler>org.primefaces.application.DialogViewHandler</view-handler>
<el-resolver>org.primefaces.application.exceptionhandler.PrimeExceptionHandlerELResolver</el-resolver>
</application>
<factory>
<exception-handler-factory>org.primefaces.application.exceptionhandler.PrimeExceptionHandlerFactory</exception-handler-factory>
</factory>
</faces-config>
XHTML:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:h="http://java.sun.com/jsf/html">
<f:view encoding="UTF-8">
<h:head>
<title>PrimeFaces Exception Handler Reload Test</title>
</h:head>
<h:body>
<p:ajaxExceptionHandler type="javax.faces.application.ViewExpiredException"
pdate="exception-handler-dialog-form"
onexception="PF('exceptionHandlerDialog').show();" />
<h:form id="test-form">
<p:commandButton value="Throw ViewExpiredException on dialog show!"
action="#{exceptionHandlerView.throwViewExpiredException}"
oncomplete="PF('someDialog').show();" />
</h:form>
<h:form id="some-dialog-form">
<p:dialog id="some-dialog"
widgetVar="someDialog"
header="Something to Do"
modal="true"
resizable="false"
closable="true"
closeOnEscape="true"
styleClass="text-center"
style="width: 300px !important; height: 200px !important;">
SEARCH DIALOG...
</p:dialog>
</h:form>
<h:form id="exception-handler-dialog-form">
<p:dialog id="exception-handler-dialog"
widgetVar="exceptionHandlerDialog"
header="Session Expired"
modal="true"
resizable="false"
closable="true"
closeOnEscape="true"
style="width: 300px !important; height: 200px !important; text-align: center;">
<p:ajax event="close"
process="@this"
update="#{updateIds}"
onstart="PF('reloadPageButton').jq.click();"
immediate="true" />
<h:outputText value="Your session has expired." />
<p:button widgetVar="reloadPageButton"
value="Reload page"
outcome="#{view.viewId}?includeViewParams=true" />
</p:dialog>
</h:form>
</h:body>
</f:view>
</html>
豆子:
@Named
@ViewScoped
public class ExceptionHandlerView implements Serializable
{
private static final long serialVersionUID = 1L;
public void throwViewExpiredException()
{
throw new ViewExpiredException( "A ViewExpiredException!", FacesContext.getCurrentInstance().getViewRoot().getViewId() );
}
public void throwNullPointerException()
{
throw new NullPointerException( "A NullPointerException!" );
}
public void throwWrappedIllegalStateException()
{
throw new FacesException( new IllegalStateException( "A wrapped IllegalStateException!" ) );
}
}
问题:
如何让异常对话框出现在真实对话框之后/之上?
【问题讨论】:
-
首先分析resutling client-side html(那里是显示的地方)和相应的html实验CSS,我想你可以学到很多东西(你会有相同的没有异常处理程序和两个模式对话框的问题...!!!
标签: primefaces jsf-2