Scenario:
How to calculate the datefield by considering another datefield that’s entered in by the user.
If you have entered a datefield “Today” as 12/04/2012
Now the requirement is to calculate another datefield’s date as 12/04/2012 + 30 days?
Solution:
- Have two fields in the page. inputDate1 and inputDate2 bounded to the value in the bean as date1 and date2.
- set inputDate1 autosubmit=true, and inputDate2 partialTrigger is set to the id of the inputDate1
<af:inputDate label="Date 1" id="id1" value="#{bean.date1}" autoSubmit="true"/> <af:inputDate label="Date 2" id="id2" value="#{bean.date2}" partialTriggers="id1"/>
in the bean for the date fields. have getter and setter
in the getter of the date2 field have the following code
private Date date1; private Date date2; public void setDate1(Date date1) { this.date1 = date1; } public Date getDate1() { return date1; } public void setDate2(Date date2) { this.date2 = date2; } public Date getDate2() { if(date1 != null){ Calendar cal =Calendar.getInstance(); cal.setTime(date1); cal.add(Calendar.DATE, 30); date2 = cal.getTime(); } return date2; }
The source code is downloaded from here, for Jdeveloper 11.1.2.2.0