primefaces
Messages are normally used for notifying, informing and keep the users aware of the actions that they are achieved. Typically, messages used for displaying information, errors, warnings and so on. Primefaces like all of jsf implementations, provides a different types of components that are used for doing so. Messages, message and growl are the only components get used for this purpose. This tutorial will help you getting featured these components into your application.
消息通常用于通知,通知用户并使他们知道所实现的操作。 通常,用于显示信息,错误,警告等的消息。 像所有jsf实现一样,Primefaces提供了用于执行此操作的不同类型的组件。 消息,消息和咆哮是用于此目的的唯一组件。 本教程将帮助您在应用程序中使用这些组件。
Primefaces消息基本信息 (Primefaces Message Basic Info)
Message is a pre-skinned extended verison of the standard JSF message component.
消息是标准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 |
标签 | 信息 |
---|---|
组件类别 | org.primefaces.component.message.Message |
组件类型 | org.primefaces.component.Message |
组件族 | org.primefaces.component |
渲染器类型 | org.primefaces.component.MessageRenderer |
渲染器类 | org.primefaces.component.message.MessageRenderer |
Primefaces消息属性 (Primefaces Message Attributes)
Name | Default | Type | Description |
---|---|---|---|
id | null | String | Unique identifier of the component. |
rendered | true | Boolean | Boolean value to specify the rendering of the component, when set to false component will not be rendered. |
binding | null | Object | An el expression that maps to a server side UIComponent instance in a backing bean. |
showSummary | false | Boolean | Specifies if the summary of the FacesMessage should be displayed. |
showDetail | true | Boolean | Specifies if the detail of the FacesMessage should be displayed. |
for | null | String | Id of the component whose messages to display. |
redisplay | true | Boolean | Defines if already rendered messages should be displayed |
display | both | String | Defines the display mode. |
escape | true | Boolean | Defines whether html would be escaped or not. |
severity | null | String | Comma separated list of severities to display only. |
style | null | String | Inline style of the component. |
styleClass | null | String | Style class of the component. |
名称 | 默认 | 类型 | 描述 |
---|---|---|---|
ID | 空值 | 串 | 组件的唯一标识符。 |
呈现 | 真正 | 布尔型 | 布尔值,用于指定组件的呈现,当设置为false时将不呈现组件。 |
捆绑 | 空值 | 目的 | 一个el表达式,它映射到后备bean中的服务器端UIComponent实例。 |
显示摘要 | 假 | 布尔型 | 指定是否显示FacesMessage的摘要。 |
查看详细 | 真正 | 布尔型 | 指定是否显示FacesMessage的详细信息。 |
对于 | 空值 | 串 | 要显示其消息的组件的ID。 |
重新显示 | 真正 | 布尔型 | 定义是否应显示已渲染的消息 |
显示 | 都 | 串 | 定义显示模式。 |
逃逸 | 真正 | 布尔型 | 定义是否对html进行转义。 |
严重程度 | 空值 | 串 | 以逗号分隔的严重性列表仅显示。 |
样式 | 空值 | 串 | 组件的内联样式。 |
styleClass | 空值 | 串 | 组件的样式类。 |
Primefaces消息入门 (Getting Started With Primefaces Message)
In general, for adding messages into your application you need to add FacesMessage instances into your own FacesContext instance to be rendered at the RenderResponse phase after then. Many of these messages are added manually and at the same time others are added by jsf implementation. When you deal with validation and conversion, a lot of messages are displayed that actually aren’t part of your code. Following example shows you a simple example of validation process that generates an error message that get displayed when submitting a form without filling required input.
通常,要将消息添加到应用程序中,您需要将FacesMessage实例添加到您自己的FacesContext实例中,然后在之后的RenderResponse阶段进行渲染。 其中许多消息是手动添加的,而其他消息是通过jsf实现添加的。 当您进行验证和转换时,会显示很多实际上不属于您的代码的消息。 以下示例向您展示了一个简单的验证过程示例,该示例将生成一条错误消息,该错误消息在提交表单时不填写所需的输入而显示。
index.xhtml
index.xhtml
<html xmlns="https://www.w3.org/1999/xhtml"
xmlns:ui="https://java.sun.com/jsf/facelets"
xmlns:h="https://java.sun.com/jsf/html"
xmlns:f="https://java.sun.com/jsf/core"
xmlns:p="https://primefaces.org/ui">
<h:head>
<script name="jquery/jquery.js" library="primefaces"></script>
</h:head>
<h:form id="form">
<p:outputPanel>
<p:outputLabel value="Typing of your message is mandatory:"></p:outputLabel>
</p:outputPanel>
<h:inputText id="input" value="#{messageManagedBean.message}" required="true"/>
<p:message id="message" for="input"></p:message>
<p:commandButton value="Execute JSF Lifecycle - Invoke Action" action="#{messageManagedBean.doSomeAction}" update="input message"></p:commandButton>
</h:form>
</html>
MessageManagedBean.java
MessageManagedBean.java
package com.journaldev;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean
@SessionScoped
public class MessageManagedBean {
private String message;
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String doSomeAction(){
return "";
}
}
Here’s detailed explanation for the above code:
以下是上述代码的详细说明:
- The rendered message isn’t part of your code, it’s queued by the jsf implementation through executing of ProcessValidation phase. 呈现的消息不是代码的一部分,它由jsf实现通过执行ProcessValidation阶段进行排队。
- RenderResponse phase is responsible of getting messages displayed. RenderResponse阶段负责获取显示的消息。
- Queuing messages require to pass through jsf lifecycle. Normal starting of jsf lifecycle get done by activating an action. 排队消息需要通过jsf生命周期。 正常启动jsf生命周期可通过激活操作来完成。
- To ensure that certain input is required, required attribute m