From Date and To Date Validation in ADF.

Scenario: Many times we may have requirements that we need to perform from date and to date validation in ADF. Means From Date should not be greater than To Date or To Date should not be smaller than From Date as shown below.





Solution:

This can be achieved in following manner.

Suppose you have a view object with two attribute namely "DateFrom" and "DateTO" on which you need to perform validation.




Now drag and drop this view object on you page fragment as form and put autoSubmit="true" for both the attribute. Also you can specify the date format if you want as shown below:





Now go to you taskflow and drag and drop createInsert of the corresponding view object as default activity and then drag and drop your fragment and then put a control flow.




Then create one jspx page and drag and drop your taskflow as "region" on your jspx page as shown below.


Then go to the binding of you jsff page and put "changeEventPolicy" to "ppr" as shown below:




Then go to your view object and add two temporary attribute as shown below.




Then go to java section and generate VORowImpl class with accessor as shown below:




Then open you RowImpl Class and add the following code in setter method of the "DateFrom" and "DateTO" attribute.

    public void setDateFrom(Date value) {
        String errorMessage="From Date should be less than To Date.";
        oracle.jbo.domain.Date other = null;
                java.util.Date otherUtil = null;
               
                setAttributeInternal(DATEFROMTEMP, value);
                if (null != getAttributeInternal(DATETOTEMP)) {
                    other = (Date)getAttributeInternal(DATETOTEMP);
                    otherUtil = other.getValue();
                } else if (null != getAttributeInternal(DATETO)) {
                    other = (Date)getAttributeInternal(DATETO);
                    otherUtil = other.getValue();
                }
                java.util.Date valueUtil = value.getValue();
                if (null != otherUtil && otherUtil.before(valueUtil)) {
                    throw new JboException(errorMessage);
                }
                setAttributeInternal(DATEFROM, value);
                setAttributeInternal(DATETO, other);
           
    }

    public void setDateTO(Date value) {
        String errorMessage ="To Date should be greater than From Date.";
        Date other = null;
                java.util.Date otherUtil = null;
                setAttributeInternal(DATETOTEMP, value);
                if (null != getAttributeInternal(DATEFROMTEMP)) {
                    other = (Date)getAttributeInternal(DATEFROMTEMP);
                    otherUtil = other.getValue();
                } else if (null != getAttributeInternal(DATEFROM)) {
                    other = (Date)getAttributeInternal(DATEFROM);
                    otherUtil = other.getValue();
                }
                java.util.Date valueUtil = value.getValue();
                if (null != otherUtil && otherUtil.after(valueUtil)) {
                    throw new JboException(errorMessage);
                }
                setAttributeInternal(DATETO, value);
                setAttributeInternal(DATEFROM, other);
    }



Now run you page and test the result.

You can specify the different scenario and see that date validation are working perfectly.







Happy Coding :)



Comments

Popular posts from this blog

Setting up the environment for Angular2 and Hello World Example in Angular2

Showing number of rows or row count on top and bottom of table in ADF.

Build a Simple ReactJS application using react-cli