它用于显示在JSF生命周期过程中存储在face上下文中的所有消息。
【JSF h:messages标记】例:
// index.xhtml
<
h:form id="form">
<
h:outputLabel for="username">
User Name<
/h:outputLabel>
<
h:inputText id="name-id" value="http://www.srcmini.com/#{user.name}"/>
<
br/>
<
h:outputLabel for="mobile">
Mobile No.<
/h:outputLabel>
<
h:inputText id="mobile-id" value="http://www.srcmini.com/#{user.mobile}"/>
<
br/>
<
h:commandButton value="http://www.srcmini.com/OK" action="response.xhtml">
<
/h:commandButton>
<
!-- Here, we are single tag to display all the errors. -->
<
h:messages style="color: red">
<
/h:messages>
<
/h:form>
// User.java
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
@ManagedBean
@RequestScoped
public class User{
@NotNull(message = "Name can't be empty")
String name;
@NotNull(message = "Mobile can't be empty")
@Size(min = 10, max = 10, message = "Mobile must have 10 digits")
String mobile;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
}
输出量
文章图片
推荐阅读
- JSF h:outputText标记
- JSF h:message标签
- JSF托管Bean
- JavaServer Faces生命周期
- JSF JDBC连接
- JSF h:inputTextarea标记
- JSF h:inputText标签
- JSF h:inputSecret标记
- JSF h:inputHidden标记