title: JSF : How create custom validator to birthdate?
body: <p>I would like to create the selected birthdate with a custom validator.
  This is my view:</p>
  
  <pre><code>        &lt;h:selectOneMenu id="birthdate_day" value="#{userc.userb.b_day}"&gt;
              &lt;f:validator validatorId="dateExistValidator" /&gt;
              &lt;f:attribute name="day" value="#{dateExist.submittedValue}" /&gt;
              &lt;f:ajax event="blur" render="m_birthdate_day" /&gt;
  
              &lt;f:selectItem itemLabel="Dia" itemValue="" /&gt;
              &lt;f:selectItems value="#{userc.birthDateDays}" /&gt;
          &lt;/h:selectOneMenu&gt;
          &lt;h:selectOneMenu id="birthdate_month" value="#{userc.userb.b_month}" binding="#{dateExist}" &gt;
              &lt;f:selectItem itemLabel="Mês" itemValue="" /&gt;
              &lt;f:selectItems value="#{userc.birthDateMonths}" var="month" itemValue="#{month.key}" itemLabel="#{month.value}" /&gt;
              &lt;f:ajax event="blur" execute="birthdate_day birthdate_month" render="m_birthdate_month" /&gt;
          &lt;/h:selectOneMenu&gt;
          &lt;h:selectOneMenu id="birthdate_year" value="#{userc.userb.b_year}"&gt;
              &lt;f:selectItem itemLabel="Ano" itemValue="" /&gt;
              &lt;f:selectItems value="#{userc.birthDateYears}" /&gt;
              &lt;f:ajax event="blur" render="m_birthdate_year" /&gt;
          &lt;/h:selectOneMenu&gt;
  </code></pre>
  
  <p>This is my validator:</p>
  
  <pre><code>@FacesValidator("dateExistValidator")
  public class DateValidator implements Validator {
  
      @Override
      public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
          Integer day =   (Integer) value;
          Integer month = (Integer) component.getAttributes().get("month");
          Integer year =  (Integer) component.getAttributes().get("year");
  
          if (day == null || month == null || year == null) {
              return; // Just ignore and let required="true" do its job.
          }
  
          // do the verifications if the selected date exist
      }
  }
  </code></pre>
  
  <p>But for some reason, my <code>month</code> and <code>year</code> object in my validator is always null.
  To be honest I don't know how to link the selected value in the <code>selectItems</code> to my <code>validator.</code></p>
  
  <p>How can I do that ? Or should I do this validation only when the user submit the form ?</p>