相关疑难解决方法(0)

如何使用PrimeFaces消息组件堆叠消息?

我有一个关于p:messages组件的问题.

首先,这是我的配置:

  • PrimeFaces:4.0.3(精英)
  • JSF:MyFaces 2.0.2
  • 服务器:WebSphere 8.5.0.2

然后,我的代码:

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)

ajax jsf messages primefaces

7
推荐指数
1
解决办法
5828
查看次数

将FacesMessage传递到下一页

我正在寻找一种优雅的JSF方式来做到这一点,并想知道是否有任何普遍接受的做法.

当我从一个页面导航到另一个页面时,我希望新页面在h:message组件中显示一个FacesMessage (实际上是p:message,但它应该是同一个东西)从最后一页传输.

例如,如果用户单击"创建文档"按钮,则会在成功时导航到新页面,并在新页面上显示成功消息.我希望我的所有数据库更改操作都以这种方式运行.

似乎FacesContext清除了导航上的所有消息,因此我最接近的解决方案如下所示:

  1. 将FacesMessage对象存储在会话bean中.
  2. 在消息bean中创建一个方法checkMessage,它调用FacesContext.getCurrentInstance().addMessage(..)并从消息bean中删除消息.
  3. 在目标页面中为checkMessage添加 EL引用.
  4. 在目标页面中放置一条p:消息.

这似乎有点被迫 - 有更好的方法吗?

jsf-2

4
推荐指数
1
解决办法
5146
查看次数

标签 统计

ajax ×1

jsf ×1

jsf-2 ×1

messages ×1

primefaces ×1