Wednesday, 5 November 2014

Date picker will allow Today and Tomorrow Dates only in ADF

I have validation, the date field should allow today and tomorrow dates only.
For the see the following code:

in java bean code:

    public Date getMinDate() {
        try {
            Calendar now = Calendar.getInstance();
            java.util.Date date = now.getTime();
            DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
            String currentDate = formatter.format(date);
            return formatter.parse(currentDate);
        } catch (Exception e) {
            return null;
        }
    }
    public Date getMaxDate(){
        Calendar c = Calendar.getInstance();
        c.setTime(new Date()); // Now use today date.
        c.add(Calendar.DATE, 1); // Adding 1 days
        return c.getTime();
       
    }

jspx code:

 <af:inputDate value="#{bindings.StartDate.inputValue}"  label="#{bindings.StartDate.hints.label}"
                        minValue="#{viewScope.MyBean.minDate}" maxValue="#{viewScope.MyBean.maxDate}"
                          required="#{bindings.StartDate.hints.mandatory}" shortDesc="#{bindings.StartDate.hints.tooltip}"
                          id="id3">
              <f:validator binding="#{bindings.StartDate.validator}"/>
              <af:convertDateTime pattern="#{bindings.StartDate.format}"/>
            </af:inputDate>