如何指定消息应显示在p:growl还是p:messages中? [英] How to specify whether the message should show up in p:growl or p:messages?

查看:147
本文介绍了如何指定消息应显示在p:growl还是p:messages中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在"Facelets"页面中,我有以下内容:

In my Facelets page I have this:

<p:growl id="msg1" life="1500"/>

和另一个

<p:messages id="msg2"/>

我需要以下消息仅显示在<p:messages>中.

I need the following message to show up in <p:messages> only.

FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("veillez saisir les champs obligatoires (*)", null));

但它也会显示在<p:growl>中.

如何指定消息显示的位置?

How do I specify where the message should show up?

推荐答案

摘录自primefaces手册.页面282.

Extracted from primefaces manual. Page 282.

可定位的邮件

有时您可能需要将一则或多则消息定位到特定消息 组件,例如,假设您在同一页面上有咆哮声和消息,并且您需要 在咆哮中显示一些消息,在消息中显示一些消息.用于属性关联消息 带有特定的组件.

There may be times where you need to target one or more messages to a specific message component, for example suppose you have growl and messages on same page and you need to display some messages on growl and some on messages. Use for attribute to associate messages with specific components.

<p:messages for="somekey" />
<p:growl for="anotherkey" />

豆子

FacesContext context = FacesContext.getCurrentInstance();
context.addMessage("somekey", facesMessage1);
context.addMessage("somekey", facesMessage2);
context.addMessage("anotherkey", facesMessage3);

在上面的示例中,消息将显示第一条和第二条消息,咆哮声将仅显示 第三条消息.

In sample above, messages will display first and second message and growl will only display the 3rd message.

这篇关于如何指定消息应显示在p:growl还是p:messages中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆