消息通常用于通知,告知和让用户知道他们所采取的行动。 通常,消息用于显示信息,错误,警告等。 像所有 jsf 实现一样,Primefaces提供了不同类型的组件,用于此。
首页 信息 基本信息
Message 是标准 JSF 消息组件的预皮扩展版本。
Tag | message |
---|---|
Component Class | org.primefaces.component.message.Message |
Component Type | org.primefaces.component.Message |
Component Family | org.primefaces.component |
Renderer Type | org.primefaces.component.MessageRenderer |
Renderer Class | org.primefaces.component.message.MessageRenderer |
首页 信息 属性
+| 名称 +| 默认 +| 类型 +| 描述 +| -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- QQ 使 & @ @ @ @ @ @ boolean @ @ boolean 值指定组件的渲染, 当设定为假组件时将不会被渲染 。 QQ 绑定 QQ 无效 Object QQ 一个 el 表达式, 将图像映射到服务器侧 UIComponent 实例中的后置豆. QQ #################################################################################################################################################################################################################################################### QQ 显示 Detail QQ real QQ Boolean 指定是否显示 FacesMessage 的细节 。 QQ 对于要显示其信件的组件的QQ 无效字符串 。 QQ QQ 重新播放 QQ 真实的 QQ 布尔 QQ 定义, 如果已经发送的信件应该显示 QQ QQ 显示 QQ 字符串 定义显示模式 。 QQ QQ 出逃 真正的QQ Boolean QQ 定义html是否会出逃 . QQ 严重性 QQ 无效 QQ 字符串 QQ 逗号分离的断块列表仅显示 。 QQ QQ 风格 QQ 无效 QQ 字符串 QQ 内置样式 组件 。 QQ _QQ 样式 Class 无效 QQ 字符串 QQ 样式类 组件 。 |
用 Primefaces 消息开始
一般来说,要将消息添加到你的应用程序中,你需要将 FacesMessage实例添加到自己的 FacesContext实例中,以便在之后的 RenderResponse阶段进行渲染。 这些消息中的许多是手动添加的,而其他则是通过 jsf 实现添加的。 当你处理验证和转换时,会显示很多实际上不是你的代码的一部分的消息。
1<html xmlns="https://www.w3.org/1999/xhtml"
2 xmlns:ui="https://java.sun.com/jsf/facelets"
3 xmlns:h="https://java.sun.com/jsf/html"
4 xmlns:f="https://java.sun.com/jsf/core"
5 xmlns:p="https://primefaces.org/ui">
6<h:head>
7 <script name="jquery/jquery.js" library="primefaces"></script>
8</h:head>
9<h:form id="form">
10 <p:outputPanel>
11 <p:outputLabel value="Typing of your message is mandatory:"></p:outputLabel>
12 </p:outputPanel>
13 <h:inputText id="input" value="#{messageManagedBean.message}" required="true"/>
14 <p:message id="message" for="input"></p:message>
15 <p:commandButton value="Execute JSF Lifecycle - Invoke Action" action="#{messageManagedBean.doSomeAction}" update="input message"></p:commandButton>
16</h:form>
17</html>
主持人:Java
1package com.journaldev;
2
3import javax.faces.bean.ManagedBean;
4import javax.faces.bean.SessionScoped;
5
6@ManagedBean
7@SessionScoped
8public class MessageManagedBean {
9 private String message;
10
11 public String getMessage() {
12 return message;
13 }
14
15 public void setMessage(String message) {
16 this.message = message;
17 }
18
19 public String doSomeAction(){
20 return "";
21 }
22}
Here's detailed explanation for the above code:
通过执行 ProcessValidation 阶段
- RenderResponse 阶段负责显示消息
- Queuing 消息需要通过 jsf 生命周期来传递。 jsf 生命周期的正常开始是通过激活操作 *以确保某个输入是必要的, required属性必须被设置为 true。 ProcessValidation 将查看您所需的组件和排列消息,如果其中一些被错过
- 消息组件主要用于将特定组件与消息相关联。
第一面消息显示模式
消息组件有三个不同的显示模式:
- ** 文本:** 只显示消息文本.
- ** 图标:** 仅显示消息的严重性,消息文本可作为工具提示显示
- ** (默认):** 显示图标和文本。
让我们更改之前引入的相同示例来控制将使用的显示模式。
1<html xmlns="https://www.w3.org/1999/xhtml"
2 xmlns:ui="https://java.sun.com/jsf/facelets"
3 xmlns:h="https://java.sun.com/jsf/html"
4 xmlns:f="https://java.sun.com/jsf/core"
5 xmlns:p="https://primefaces.org/ui">
6<h:head>
7 <script name="jquery/jquery.js" library="primefaces"></script>
8</h:head>
9<h:form id="form">
10 <p:outputPanel>
11 <p:outputLabel value="Typing of your message is mandatory:"></p:outputLabel>
12 </p:outputPanel>
13 <h:inputText id="input" value="#{messageManagedBean.message}" required="true"/>
14 <p:message id="message" for="input" display="icon"></p:message>
15 <p:commandButton value="Execute JSF Lifecycle - Invoke Action" action="#{messageManagedBean.doSomeAction}" update="input message"></p:commandButton>
16</h:form>
17</html>
首页 信息 基本信息
Messages 是标准 JSF 消息组件的预皮扩展版本。
Tag | messages |
---|---|
Component Class | org.primefaces.component.messages.Messages |
Component Type | org.primefaces.component.Messages |
Component Family | org.primefaces.component |
Renderer Type | org.primefaces.component.MessagesRenderer |
Renderer Class | org.primefaces.component.messages.MessagesRenderer |
首页 信息 属性
+| 名称 +| 默认 +| 类型 +| 描述 +| -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- QQ 使 & @ @ @ @ @ @ boolean @ @ boolean 值指定组件的渲染, 当设定为假组件时将不会被渲染 。 QQ 绑定 QQ 无效 Object QQ 一个 el 表达式, 将图像映射到服务器侧 UIComponent 实例中的后置豆. QQ 显示概要 QQ 真实 QQ 布尔 QQ 指定是否要显示 FacesMessages 的摘要 。 QQ 显示 Detail QQ 假的 QQ Boolean 指定是否显示 FacesMessages 的细节 。 QQ %% 全球 只有虚构的 QQ 字符串 当真实时, 只有没有客户端的面相信息 日记显示. * ________________________________________________________________________________________________ QQ 对于 QQ 无效 QQ 字符串 QQ 关联密钥名称, 当使用 Global Only 时优先使用 。 QQ QQ 出逃 真正的QQ Boolean QQ 定义html是否会出逃 . QQ 严重性 QQ 无效 QQ 字符串 QQ 逗号分离的断块列表仅显示 。 QQ #################################################################################################################################################################################################################################################### QQ QQ 风格 QQ 无效 QQ 字符串 QQ 内置样式 组件 。 QQ _QQ 样式 Class 无效 QQ 字符串 QQ 样式类 组件 。 QQ #################################################################################################################################################################################################################################################### |
开始使用 Primeface 消息
在使用 p:messages 时,重要的是要知道,此组件用于显示页面中不属于特定控件的通用消息。
1<html xmlns="https://www.w3.org/1999/xhtml"
2 xmlns:ui="https://java.sun.com/jsf/facelets"
3 xmlns:h="https://java.sun.com/jsf/html"
4 xmlns:f="https://java.sun.com/jsf/core"
5 xmlns:p="https://primefaces.org/ui">
6<h:head>
7 <script name="jquery/jquery.js" library="primefaces"></script>
8</h:head>
9<h:form id="form">
10 <p:messages id="messages"/>
11 <p:outputPanel>
12 <p:outputLabel value="Typing of your preferred technical site"></p:outputLabel>
13 </p:outputPanel>
14 <h:inputText id="input" value="#{messageManagedBean.message}"/>
15 <p:commandButton value="Execute JSF Lifecycle - Invoke Action"
16 action="#{messageManagedBean.doSomeAction}" update="messages"></p:commandButton>
17</h:form>
18</html>
主持人:Java
1package com.journaldev;
2
3import javax.faces.application.FacesMessage;
4import javax.faces.bean.ManagedBean;
5import javax.faces.bean.SessionScoped;
6import javax.faces.context.FacesContext;
7
8@ManagedBean
9@SessionScoped
10public class MessageManagedBean {
11 private String message ="";
12
13 public String getMessage() {
14 return message;
15 }
16
17 public void setMessage(String message) {
18 this.message = message;
19 }
20
21 public String doSomeAction(){
22 if(this.message.equals("")){
23 FacesContext.getCurrentInstance().addMessage(null,
24 new FacesMessage(FacesMessage.SEVERITY_ERROR, "Empty value isn't accepted","Empty value isn't accepted"));
25 }
26 else if(this.message.equals("") == false){
27 FacesContext.getCurrentInstance().addMessage(null,
28 new FacesMessage(FacesMessage.SEVERITY_ERROR, "You entered value","You entered value"));
29 }
30 return "";
31 }
32}
Here's detailed clarifications for what's happened previously:
- 主要用于通讯覆盖的消息组件
- 您可以通过创建 FacesMessage 实例来添加消息,该实例包括消息的严重性、消息细节部分和消息总结部分。
严重程度
在前面探索的示例中,您提供了两个错误严重程度的消息,这些消息在您的页面后进行渲染,重要的是要知道您可以控制您的 p:messages 组件会显示的这些消息的类型。
1<html xmlns="https://www.w3.org/1999/xhtml"
2 xmlns:ui="https://java.sun.com/jsf/facelets"
3 xmlns:h="https://java.sun.com/jsf/html"
4 xmlns:f="https://java.sun.com/jsf/core"
5 xmlns:p="https://primefaces.org/ui">
6<h:head>
7 <script name="jquery/jquery.js" library="primefaces"></script>
8</h:head>
9<h:form id="form">
10 <p:messages id="messages" severity="fatal,info,warn"/>
11 <p:outputPanel>
12 <p:outputLabel value="Typing of your preferred technical site"></p:outputLabel>
13 </p:outputPanel>
14 <h:inputText id="input" value="#{messageManagedBean.message}"/>
15 <p:commandButton value="Execute JSF Lifecycle - Invoke Action"
16 action="#{messageManagedBean.doSomeAction}" update="messages"></p:commandButton>
17</h:form>
18</html>
主持人:Java
1package com.journaldev;
2
3import javax.faces.application.FacesMessage;
4import javax.faces.bean.ManagedBean;
5import javax.faces.bean.SessionScoped;
6import javax.faces.context.FacesContext;
7
8@ManagedBean
9@SessionScoped
10public class MessageManagedBean {
11 private String message ="";
12
13 public String getMessage() {
14 return message;
15 }
16
17 public void setMessage(String message) {
18 this.message = message;
19 }
20
21 public String doSomeAction(){
22 if(this.message.equals("")){
23 FacesContext.getCurrentInstance().addMessage(null,
24 new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error Message","Error Message"));
25 FacesContext.getCurrentInstance().addMessage(null,
26 new FacesMessage(FacesMessage.SEVERITY_FATAL, "Fatal Message","Fatal Message"));
27 FacesContext.getCurrentInstance().addMessage(null,
28 new FacesMessage(FacesMessage.SEVERITY_WARN, "WARN Message","WARN Message"));
29 FacesContext.getCurrentInstance().addMessage(null,
30 new FacesMessage(FacesMessage.SEVERITY_INFO, "INFO Message","INFO Message"));
31 }
32 return "";
33 }
34}
自动更新
如果你已经探索了之前提供的所有示例,你必须注意到p:commandButton已非同步地更新了消息/消息组件,你可以避免这种安排,特别是那些具有层次结构的页面。
1<html xmlns="https://www.w3.org/1999/xhtml"
2 xmlns:ui="https://java.sun.com/jsf/facelets"
3 xmlns:h="https://java.sun.com/jsf/html"
4 xmlns:f="https://java.sun.com/jsf/core"
5 xmlns:p="https://primefaces.org/ui">
6<h:head>
7 <script name="jquery/jquery.js" library="primefaces"></script>
8</h:head>
9<h:form id="form">
10 <p:messages id="messages" autoUpdate="true"/>
11 <p:outputPanel>
12 <p:outputLabel value="Typing of your preferred technical site"></p:outputLabel>
13 </p:outputPanel>
14 <h:inputText id="input" value="#{messageManagedBean.message}"/>
15 <p:commandButton value="Execute JSF Lifecycle - Invoke Action"
16 action="#{messageManagedBean.doSomeAction}"></p:commandButton>
17</h:form>
18</html>
主持人:Java
1package com.journaldev;
2
3import javax.faces.application.FacesMessage;
4import javax.faces.bean.ManagedBean;
5import javax.faces.bean.SessionScoped;
6import javax.faces.context.FacesContext;
7
8@ManagedBean
9@SessionScoped
10public class MessageManagedBean {
11 private String message ="";
12
13 public String getMessage() {
14 return message;
15 }
16
17 public void setMessage(String message) {
18 this.message = message;
19 }
20
21 public String doSomeAction(){
22 if(this.message.equals("")){
23 FacesContext.getCurrentInstance().addMessage(null,
24 new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error Message","Error Message"));
25 }
26 return "";
27 }
28}
- 已开发的命令操作未提供 update属性. 尽管更新属性不存在,但消息仍然显示,因为 autoUpdate是由消息组件本身使用的
目标信息
顯示訊息可以控制使用特定訊息組件來顯示。 讓我們使用兩個不同的訊息組件 {A 和 B} 和兩個不同的輸入組件 {1 和 2}. 對於輸入數字 1 的訊息會顯示對訊息 A 和對訊息 2 的訊息 B 會使用。
1<html xmlns="https://www.w3.org/1999/xhtml"
2 xmlns:ui="https://java.sun.com/jsf/facelets"
3 xmlns:h="https://java.sun.com/jsf/html"
4 xmlns:f="https://java.sun.com/jsf/core"
5 xmlns:p="https://primefaces.org/ui">
6<h:head>
7 <script name="jquery/jquery.js" library="primefaces"></script>
8</h:head>
9<h:form id="form">
10 <p:messages for="input1" id="messagesA"/>
11 <p:messages for="input2" id="messagesB"/>
12 <p:outputPanel>
13 <p:outputLabel value="Typing of your preferred technical site"></p:outputLabel>
14 </p:outputPanel>
15 <h:inputText id="input1" value="#{messageManagedBean.message}"/>
16 <h:inputText id="input2" value="#{messageManagedBean.message}"/>
17 <p:commandButton value="Execute JSF Lifecycle - Invoke Action One"
18 action="#{messageManagedBean.doSomeActionOne}" update="messagesA messagesB"></p:commandButton>
19 <p:commandButton value="Execute JSF Lifecycle - Invoke Action Two"
20 action="#{messageManagedBean.doSomeActionTwo}" update="messagesA messagesB"></p:commandButton>
21</h:form>
22</html>
主持人:Java
1package com.journaldev;
2
3import javax.faces.application.FacesMessage;
4import javax.faces.bean.ManagedBean;
5import javax.faces.bean.SessionScoped;
6import javax.faces.context.FacesContext;
7
8@ManagedBean
9@SessionScoped
10public class MessageManagedBean {
11 private String message ="";
12
13 public String getMessage() {
14 return message;
15 }
16
17 public void setMessage(String message) {
18 this.message = message;
19 }
20
21 public String doSomeActionOne(){
22 if(this.message.equals("")){
23 FacesContext.getCurrentInstance().addMessage("form:input1",
24 new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error Message For Input1","Error Message For Input1"));
25 }
26 return "";
27 }
28 public String doSomeActionTwo(){
29 if(this.message.equals("")){
30 FacesContext.getCurrentInstance().addMessage("form:input2",
31 new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error Message For Input2","Error Message For Input2"));
32 }
33 return "";
34 }
35}
- 提供 Target Messages 需要将您的消息组件与使用 for 属性的组件关联,并为所有添加到 FacesContext 的消息提供 **clientId。
请注意, jsf 实现已将其组件分配给一个独特的标识符,这些标识符以 FormId:componentId的形式进行。您可以通过提供 prependId为 false 对 form 组件来禁用此标识符,因此每个组件将通过仅使用其 componentId进行实际识别,对于未识别的组件,它们将通过随机识别(如 j_id4)进行识别。
首页 > 基本信息
Growl 基于 Mac 的 Growl 通知小工具,用于显示 FacesMessages 在重叠中,就像消息和消息组件一样。
Tag | Growl |
---|---|
Component Class | org.primefaces.component.growl.Growl |
Component Type | org.primefaces.component.Growl |
Component Family | org.primefaces.component |
Renderer Type | org.primefaces.component.GrowlRenderer |
Renderer Class | org.primefaces.component.growl.GrowlRenderer |
首页 Growl 属性
\ 名称 \ 默认 \ 类型 \ 描述 \ \ -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- QQ 绑定 QQ 无效 QX对象 QQ 一个 el 表达式,将图像映射到服务器侧 UIContent 实例中的后置豆QQ QQ 粘性 假QQQ Boolean QQQ 指定如果信件应该自动停留而非隐藏 。 QQ 显示摘要 QQ 真实的 QQ Boolean 指定是否显示信件摘要 。 QQ 显示详细 QQ 假 QQ 布尔 QQ 指定是否要显示信件的细节 。 QQ %% 全球 只有QQ假的QQ Boolean QQ在真实时,只显示没有客户端的面相信息. QQ QQ生命 QQ 6000Q 整数以毫秒为单位显示非粘性信件. QQ( _) QQ 自动更新 QQ 假的 QQ布尔 指定自动更新模式 。 QQ( _) QQ 重新播放 QQ 真实的 QQ布尔 定义, 如果已发送信件 。 QQ 对于 QQ 无效 QQ 字符串 QQ 关联密钥名称, 当使用 Global Only 时优先使用 。 QQ QQ 出逃 真正的QQ Boolean QQ 定义html是否会出逃 . QQ 严重性 QQ 无效 QQ 字符串 QQ 逗号分离的断块列表仅显示 。 |
用 Primefaces Growl 开始
Growl 与之前讨论的这些消息组件没有差异,所以您可以依靠它们来提供 ** Targetable Messages & Severity Levels** 选项。
1<html xmlns="https://www.w3.org/1999/xhtml"
2 xmlns:ui="https://java.sun.com/jsf/facelets"
3 xmlns:h="https://java.sun.com/jsf/html"
4 xmlns:f="https://java.sun.com/jsf/core"
5 xmlns:p="https://primefaces.org/ui">
6<h:head>
7 <script name="jquery/jquery.js" library="primefaces"></script>
8</h:head>
9<h:form id="form">
10 <p:growl id="message"/>
11 <p:outputPanel>
12 <p:outputLabel value="Typing of your preferred technical site"></p:outputLabel>
13 </p:outputPanel>
14 <h:inputText id="input" value="#{messageManagedBean.message}"/>
15 <p:commandButton value="Execute JSF Lifecycle - Invoke Action One"
16 action="#{messageManagedBean.doSomeAction}" update="message"></p:commandButton>
17</h:form>
18</html>
主持人:Java
1package com.journaldev;
2
3import javax.faces.application.FacesMessage;
4import javax.faces.bean.ManagedBean;
5import javax.faces.bean.SessionScoped;
6import javax.faces.context.FacesContext;
7
8@ManagedBean
9@SessionScoped
10public class MessageManagedBean {
11 private String message ="";
12
13 public String getMessage() {
14 return message;
15 }
16
17 public void setMessage(String message) {
18 this.message = message;
19 }
20
21 public String doSomeAction(){
22 if(this.message.equals("")){
23 FacesContext.getCurrentInstance().addMessage(null,
24 new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error Message Displayed Growl","Error Message Displayed Growl"));
25 }
26 return "";
27 }
28}
首页 > 信息 > 生命
由于每个消息将显示6000ms,然后隐藏,您可以控制Growl消息粘贴,这意味着它永远不会自动隐藏。
1<html xmlns="https://www.w3.org/1999/xhtml"
2 xmlns:ui="https://java.sun.com/jsf/facelets"
3 xmlns:h="https://java.sun.com/jsf/html"
4 xmlns:f="https://java.sun.com/jsf/core"
5 xmlns:p="https://primefaces.org/ui">
6<h:head>
7 <script name="jquery/jquery.js" library="primefaces"></script>
8</h:head>
9<h:form id="form">
10 <p:growl id="message" sticky="true"/>
11 <p:outputPanel>
12 <p:outputLabel value="Typing of your preferred technical site"></p:outputLabel>
13 </p:outputPanel>
14 <h:inputText id="input" value="#{messageManagedBean.message}"/>
15 <p:commandButton value="Execute JSF Lifecycle - Invoke Action One"
16 action="#{messageManagedBean.doSomeAction}" update="message"></p:commandButton>
17</h:form>
18</html>
If you wouldn't your Growl message to be work in a sticky manner, you can also control the duration of displaying messages by tuning of life attribute.
index8.xhtml
1<html xmlns="https://www.w3.org/1999/xhtml"
2 xmlns:ui="https://java.sun.com/jsf/facelets"
3 xmlns:h="https://java.sun.com/jsf/html"
4 xmlns:f="https://java.sun.com/jsf/core"
5 xmlns:p="https://primefaces.org/ui">
6<h:head>
7 <script name="jquery/jquery.js" library="primefaces"></script>
8</h:head>
9<h:form id="form">
10 <p:growl id="message" life="2000"/>
11 <p:outputPanel>
12 <p:outputLabel value="Typing of your preferred technical site"></p:outputLabel>
13 </p:outputPanel>
14 <h:inputText id="input" value="#{messageManagedBean.message}"/>
15 <p:commandButton value="Execute JSF Lifecycle - Invoke Action One"
16 action="#{messageManagedBean.doSomeAction}" update="message"></p:commandButton>
17</h:form>
18</html>
Primefaces Growl 消息定位
默认情况下,Growl位于右上角,位置可以用名为 ui-growl的CSS选择器来控制。
1<html xmlns="https://www.w3.org/1999/xhtml"
2 xmlns:ui="https://java.sun.com/jsf/facelets"
3 xmlns:h="https://java.sun.com/jsf/html"
4 xmlns:f="https://java.sun.com/jsf/core"
5 xmlns:p="https://primefaces.org/ui">
6<h:head>
7 <script name="jquery/jquery.js" library="primefaces"></script>
8 <style>
9 .ui-growl {
10 left:700px;
11 }
12 </style>
13</h:head>
14<h:form id="form">
15 <p:growl id="message"/>
16 <p:outputPanel>
17 <p:outputLabel value="Typing of your preferred technical site"></p:outputLabel>
18 </p:outputPanel>
19 <h:inputText id="input" value="#{messageManagedBean.message}"/>
20 <p:commandButton value="Execute JSF Lifecycle - Invoke Action One"
21 action="#{messageManagedBean.doSomeAction}" update="message"></p:commandButton>
22</h:form>
23</html>
逃跑
对于所有 Primefaces 消息组件(消息、消息和 growl),它们是默认的,以逃避所有 HTML 内容. 如果您需要通过 Primefaces 消息显示 HTML,则组件将逃避设置为 false. index10.xhtml
1<html xmlns="https://www.w3.org/1999/xhtml"
2 xmlns:ui="https://java.sun.com/jsf/facelets"
3 xmlns:h="https://java.sun.com/jsf/html"
4 xmlns:f="https://java.sun.com/jsf/core"
5 xmlns:p="https://primefaces.org/ui">
6<h:head>
7 <script name="jquery/jquery.js" library="primefaces"></script>
8</h:head>
9<h:form id="form">
10 <p:messages id="message" escape="false"/>
11 <p:outputPanel>
12 <p:outputLabel value="Typing of your preferred technical site"></p:outputLabel>
13 </p:outputPanel>
14 <h:inputText id="input" value="#{messageManagedBean.message}"/>
15 <p:commandButton value="Execute JSF Lifecycle - Invoke Action One"
16 action="#{messageManagedBean.doSomeAction}" update="message"></p:commandButton>
17</h:form>
18</html>
主持人:Java
1package com.journaldev;
2
3import javax.faces.application.FacesMessage;
4import javax.faces.bean.ManagedBean;
5import javax.faces.bean.SessionScoped;
6import javax.faces.context.FacesContext;
7
8@ManagedBean
9@SessionScoped
10public class MessageManagedBean {
11 private String message ="";
12
13 public String getMessage() {
14 return message;
15 }
16
17 public void setMessage(String message) {
18 this.message = message;
19 }
20
21 public String doSomeAction(){
22 if(this.message.equals("")){
23 FacesContext.getCurrentInstance().addMessage(null,
24 new FacesMessage(FacesMessage.SEVERITY_ERROR, "<i>Error Message Displayed</i>","<i>Error Message Displayed</i>"));
25 }
26 return "";
27 }
28}
细节和摘要消息部分
Displaying of messages' parts can be controlled, so you can choose which part of message you need to display. All of FacesMessage contains for Summary and Detail parts that are provided once the message has been added into your FacesContext. All of Primefaces' messages components are defaulted to render the summary part. As you can provide showSummary and showDetail for displaying both parts of FacesMessage.
index11.xhtml
1<html xmlns="https://www.w3.org/1999/xhtml"
2 xmlns:ui="https://java.sun.com/jsf/facelets"
3 xmlns:h="https://java.sun.com/jsf/html"
4 xmlns:f="https://java.sun.com/jsf/core"
5 xmlns:p="https://primefaces.org/ui">
6<h:head>
7 <script name="jquery/jquery.js" library="primefaces"></script>
8</h:head>
9<h:form id="form">
10 <p:messages id="message" showDetail="true" showSummary="true" escape="false"/>
11 <p:outputPanel>
12 <p:outputLabel value="Typing of your preferred technical site"></p:outputLabel>
13 </p:outputPanel>
14 <h:inputText id="input" value="#{messageManagedBean.message}"/>
15 <p:commandButton value="Execute JSF Lifecycle - Invoke Action One"
16 action="#{messageManagedBean.doSomeAction}" update="message"></p:commandButton>
17</h:form>
18</html>
首页 > 短信 > Growl Summary
Primefaces为您提供了大量的这些组件,可以用于在您的应用程序中提供信息,通知和显示信息性文本。
[下载首席信息工程(LINK0)]