servlets struts hibernate spring maven java
 

JSF <h:messages> Tag



It is utilized to shows all messages that were stored in the faces context throughout the JSF life cycle.

Example:

// index.xhtml

  1. <h:form id="form">  
  2. <h:outputLabel for="username">User Name</h:outputLabel>  
  3. <h:inputText id="name-id" value="#{user.name}"/><br/>  
  4. <h:outputLabel for="Password">Password No.</h:outputLabel>  
  5. <h:inputText id="Password-id" value="#{user.Password}"/><br/>  
  6. <h:commandButton value="OK" action="response.xhtml"></h:commandButton>  
  7. <!-- Here, we are single tag to display all the errors. -->  
  8. <h:messages style="color: red"></h:messages>  
  9. </h:form>  

// User.java

  1. import javax.faces.bean.ManagedBean;  
  2. import javax.faces.bean.RequestScoped;  
  3. import javax.validation.constraints.NotNull;  
  4. import javax.validation.constraints.Size;  
  5. @ManagedBean  
  6. @RequestScoped  
  7. public class User{  
  8. @NotNull(message = "Name can't be empty")  
  9. String name;  
  10. @NotNull(message = "Password can't be empty")  
  11. @Size(min = 10, max = 10, message = "Password must have 10 digits")  
  12. String Password;  
  13. public String getName() {  
  14. return name;  
  15. }  
  16. public void setName(String name) {  
  17. this.name = name;  
  18. }  
  19. public String getPassword() {  
  20. return Password;  
  21. }  
  22. public void setPassword(String Password) {  
  23. this.Password = Password;  
  24. }  
  25. }  






© Javacodegeeks © 2019 - 2019
All Right Reserved and you agree to have read and accepted our term and condition.

Python 3