f:validateBean

The f:validateBean Facelet tag takes advantage of Bean Validation annotations on Java Bean properties.

General Usage




                   

Source Code

  1. <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://xmlns.jcp.org/jsf/core"
  2. xmlns:ui="http://xmlns.jcp.org/jsf/facelets" xmlns:h="http://xmlns.jcp.org/jsf/html">
  3.  
  4. <h:form>
  5. <label class="control-label">#{i18n['please-enter-your-email']}</label>
  6. <h:inputText id="email" value="#{validationModelBean.email}"
  7. label="#{i18n['validate-email-label']}">
  8. <f:validateBean />
  9. </h:inputText>
  10. <br />
  11. <h:message for="email" />
  12. <hr />
  13. <h:commandButton value="#{i18n['submit']}">
  14. <f:ajax execute="@form" render="@form" />
  15. </h:commandButton>
  16. <h:outputText value="#{validationModelBean.email}" />
  17. </h:form>
  18.  
  19. </ui:composition>
  1. @ManagedBean
  2. @RequestScoped
  3. public class ValidationModelBean {
  4.  
  5. @Pattern(regexp = ".+[@].+[.].+")
  6. private String email;
  7. private Double doubleNumber;
  8. private Long longNumber;
  9. private String otherText;
  10.  
  11. public Double getDoubleNumber() {
  12. return doubleNumber;
  13. }
  14.  
  15. public String getEmail() {
  16. return email;
  17. }
  18.  
  19. public Long getLongNumber() {
  20. return longNumber;
  21. }
  22.  
  23. public String getOtherText() {
  24. return otherText;
  25. }
  26.  
  27. public void setDoubleNumber(Double doubleNumber) {
  28. this.doubleNumber = doubleNumber;
  29. }
  30.  
  31. public void setEmail(String email) {
  32. this.email = email;
  33. }
  34.  
  35. public void setLongNumber(Long longNumber) {
  36. this.longNumber = longNumber;
  37. }
  38.  
  39. public void setOtherText(String otherText) {
  40. this.otherText = otherText;
  41. }
  42. }
Liferay Faces Bridge Implementation 5.0.0 + Showcase Common 3.1.1 + Liferay Faces Util 3.4.1 + Mojarra 2.2.20