JSF h:messages标记

它用于显示在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:messages标记

文章图片

    推荐阅读