Hi All,
Today I am going to discussing about an use case around Date's. JDev version used for this example is 11.1.2.2
Use Case:
There are two fields on UI, Start Date and End Date.
1. If StartDate > EndDate - appropriate message should be displayed
2. If StartDate > Sysdate - appropriate message should be displayed
3. If EndDate > Sysdate - appropriate message should be displayed
4. If EndDate < StartDate - appropriate message should be displayed
Here, In this example, I am creating a VO, which has only two attributes StartDate and EndDate. This is a query based VO - DateCheckerVO. I am going to drag this VO to a page as a form, after creating an application module and creating the appropriate view instance.
This is the page display after dragging the view to the page(dateCompare.jspx).

Now add, a validateDateTimeRange validator onto the start date to validate the date entered compared to end date and sysdate.
<af:validateDateTimeRange maximum="#{bindings.EndDate.inputValue}" messageDetailMaximum="Start Date should not be greater than End date"/>
<af:validateDateTimeRange maximum="#{dateCompare.maxDate}" messageDetailMaximum="Start Date should not be greater than Today‘s date"/>
The above two validator's manages the validation points 1 & 2 mentioned at the starting of the post.
Now, we need to add a private variable to set the max date for a date field.Next few lines serves the purpose. So, first we need to create the accessor's for this variable.
public void setMaxDate(Date maxDate) {
this.maxDate = maxDate;
}
public Date getMaxDate() {
Calendar cl = Calendar.getInstance();
cl.setTime(new Date());
cl.add(Calendar.DATE, 0);
Date toDate = cl.getTime();
return toDate;
}
Now, apply the same steps to EndDate as followed for StartDate.
<af:validateDateTimeRange maximum="#{dateCompare.maxDate}" messageDetailMaximum="End should not be greater than Today‘s date"/>
<af:validateDateTimeRange minimum="#{bindings.StartDate.inputValue}" messageDetailMinimum="End should not be less than Start date"/>
Don't forget to set the auto-submit property for both the fields to true.
Just run the page and play with the date fields and you will be able to check the appropriate message.
You can get the sample application here. Feel free to comment on the post :)
Today I am going to discussing about an use case around Date's. JDev version used for this example is 11.1.2.2
Use Case:
There are two fields on UI, Start Date and End Date.
1. If StartDate > EndDate - appropriate message should be displayed
2. If StartDate > Sysdate - appropriate message should be displayed
3. If EndDate > Sysdate - appropriate message should be displayed
4. If EndDate < StartDate - appropriate message should be displayed
Here, In this example, I am creating a VO, which has only two attributes StartDate and EndDate. This is a query based VO - DateCheckerVO. I am going to drag this VO to a page as a form, after creating an application module and creating the appropriate view instance.
This is the page display after dragging the view to the page(dateCompare.jspx).
Now add, a validateDateTimeRange validator onto the start date to validate the date entered compared to end date and sysdate.
<af:validateDateTimeRange maximum="#{bindings.EndDate.inputValue}" messageDetailMaximum="Start Date should not be greater than End date"/>
<af:validateDateTimeRange maximum="#{dateCompare.maxDate}" messageDetailMaximum="Start Date should not be greater than Today‘s date"/>
The above two validator's manages the validation points 1 & 2 mentioned at the starting of the post.
Now, we need to add a private variable to set the max date for a date field.Next few lines serves the purpose. So, first we need to create the accessor's for this variable.
public void setMaxDate(Date maxDate) {
this.maxDate = maxDate;
}
public Date getMaxDate() {
Calendar cl = Calendar.getInstance();
cl.setTime(new Date());
cl.add(Calendar.DATE, 0);
Date toDate = cl.getTime();
return toDate;
}
Now, apply the same steps to EndDate as followed for StartDate.
<af:validateDateTimeRange maximum="#{dateCompare.maxDate}" messageDetailMaximum="End should not be greater than Today‘s date"/>
<af:validateDateTimeRange minimum="#{bindings.StartDate.inputValue}" messageDetailMinimum="End should not be less than Start date"/>
Don't forget to set the auto-submit property for both the fields to true.
Just run the page and play with the date fields and you will be able to check the appropriate message.
You can get the sample application here. Feel free to comment on the post :)
No comments:
Post a Comment