我有一个关于p:messages组件的问题.
首先,这是我的配置:
然后,我的代码:
test.xhtml
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:fn="http://java.sun.com/jsp/jstl/functions">
<h:head>
<f:facet name="first">
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</f:facet>
<meta http-equiv="cache-control" content="no-store,no-cache" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="expires" content="0" />
</h:head>
<h:body>
<div id="content">
<h:form id="form1">
<p:tooltip/>
<p:messages id="messages" showDetail="true" />
<p:remoteCommand async="true" autoRun="true" process="@this" partialSubmit="true" action="#{testBean.checkA}" />
<p:remoteCommand async="true" autoRun="true" process="@this" partialSubmit="true" action="#{testBean.checkB}" />
</h:form>
</div>
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)
Test.java
import java.io.Serializable;
import javax.faces.application.FacesMessage;
import …Run Code Online (Sandbox Code Playgroud) 我正在寻找一种优雅的JSF方式来做到这一点,并想知道是否有任何普遍接受的做法.
当我从一个页面导航到另一个页面时,我希望新页面在h:message组件中显示一个FacesMessage (实际上是p:message,但它应该是同一个东西)从最后一页传输.
例如,如果用户单击"创建文档"按钮,则会在成功时导航到新页面,并在新页面上显示成功消息.我希望我的所有数据库更改操作都以这种方式运行.
似乎FacesContext清除了导航上的所有消息,因此我最接近的解决方案如下所示:
这似乎有点被迫 - 有更好的方法吗?