f:validateRequired

The f:validateRequired Facelet tag can be used to require a value from a UIInput Component. f:validateRequired activates the same validation logic as required="true" and UIInput.setRequired(true).

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['required']}</label>
  6. <h:inputText id="required" value="#{inputTextModelBean.text}"
  7. label="#{i18n['f-validaterequired-label']}">
  8. <f:validateRequired />
  9. </h:inputText>
  10. <br />
  11. <h:message for="required" />
  12. <hr />
  13. <h:commandButton value="#{i18n['submit']}">
  14. <f:ajax execute="@form" render="@form" />
  15. </h:commandButton>
  16. <h:outputText value="#{inputTextModelBean.text}" />
  17. </h:form>
  18.  
  19. </ui:composition>
  1. @ManagedBean
  2. @RequestScoped
  3. public class InputTextModelBean {
  4.  
  5. private Date date = new GregorianCalendar().getTime();
  6. private String text;
  7.  
  8. public Date getDate() {
  9. return date;
  10. }
  11.  
  12. public String getText() {
  13. return text;
  14. }
  15.  
  16. public void setDate(Date date) {
  17. this.date = date;
  18. }
  19.  
  20. public void setText(String text) {
  21. this.text = text;
  22. }
  23. }
Liferay Faces Bridge Implementation 5.0.0 + Showcase Common 3.1.1 + Liferay Faces Util 3.4.1 + Mojarra 2.2.20