Wednesday, April 30, 2014

How to disable past dates in calendar component in OIM?


When we declare any field on form as Date it renders a calendar with all the available dates. Depending on the requirements we may  need to restrict the display of dates. 

For eg: Disable all future or past dates.

This is post is to demonstrate the use of a custom managed bean to disable all past dates in the calendar. The ADF component that gets created is <af:inputdate>. This component has a property "minValue" which when set to a date, disables all prior dates. We will be setting this property to SYSDATE so that all past dates will be disabled and cannot be selected by the user. Below are the steps - :


  1. Lets start with creating the managed bean, create a new generic application in Jdev.
  2. Name the application, the prefix should be oracle.iam.ui custom.
  3. Name the project, don't select any technologies and click finish.
  4. Right click on the application and say new.
  5. Select ADF View Controller project.
  6. Name the project.
  7. Make sure the default package is oracle.iam.ui custom.
  8. Right click on the project, goto project properties> Libraries and Classpath> Add Library> Specify the
    path to OIM_HOME>Jdev>Lib and add OIM Client, OIM Model Shared and OIM View Shared library.        
    NOTE:
    These are the library files not the actual JARs, these just contain the path to the JAR files which are actually present at OIM_HOME>Jdev>modules and client folder. If you do not have local OIM Installed then download the library files to a local directory and download the modules and client folder also. The modules and client folder should be at the parent directory level of your library files. For eg if Library files are in C:/jdev/jars/libraries then your modules and client folder should be at C:/jdev/jars
  9. Create a new a new class in the project. The class should extends oracle.iam.ui.platform.view.backing.BaseStateMBand implements Serializable.
  10. Create a private property of type Date. Generate its getter and setter.
  11. The getter method should be actually returning the formatted current date. Refer the code as below:                                                                                                                                                                                import java.io.Serializable;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.Date;

    public class CurrentDate {
    publicCurrentDate() {
    super();
        }
    private Date minDate = new Date();

    public void setMinDate(Date minDate) {
    this.minDate = minDate;
        }

    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);
    minDate = formatter.parse(currentDate);
    System.out.println("$$$$$$$$$$$$$$$$$Current Date is- $$$$$$$$$$" +
    minDate);
    returnformatter.parse(currentDate);
            } catch (Exception e) {
    return null;
            }
        }
    }
  12. Make sure there are no compilation errors, your bean is created now go to webcontent>PageFlows>adfc-config.xml.
  13. Declare your managed bean and specify its scope.
  14. The code is ready now, we need to deploy it to a jar file. Right Click on the project and  Go to deployments tab. Delete the deployment profile, if any. Click on new> Select the archive type as ADF Library Jar File, Name the archive as “adflibCustomModel” and hit ok.


  15.  Right click on the project and deploy, the jar will be created in the project>deploy folder, optionally the deployment path will be there in the logs.
  16.  This jar needs to be deployed to OIM, pls download the oracle.iam.ui.custom-dev-starter-pack.war from OIM_HOME>apps directory. Extract its contents. Place the adflibCustomModel.jar inside WEB-INF/lib. Lib directory might not exists, if so create it.
  17.  ZIP the war again and upload/place it to OIM_HOME>apps. To avoid extra work, take a backup of war.
  18.  Go to weblogic console>deployments> Click lock and edit>Check oracle.iam.ui.custom(11.1.1,11.1.1) and hit update> Click on next, dependent deployments will be displayed, check both of them and finish>Click on Activate Changes.
  19.  This may take time and you might get a timeout error, don’t worry your deployments are updated, restart the oim servers.
  20.  The code deployments is complete, we need to map our bean property to component property. Login as xlesysadm>Create and activate a SandBox> Assuming the date component is in a application request form> go to catalog>search the application>add to cart>checkout.
  21.  Click on customize link>select the date component and change any of its property. The minValue property cannot be set using webcenter, we need to set the property by editing the jsff file manually after exporting the sandbox. Lets just set the show required property to true. 
  22.  Close the webcenter, export the sandbox extract it and go to “oracle\iam\ui\runtime\form\view\pages\mdssys\cust\site\site” you will find a createform.jsff xml. Edit it> go to the the date component and add the minValue property like below:
    <af:inputDatexmlns:af="http://xmlns.oracle.com/adf/faces/rich" value="#{bindings.Date__c.inputValue}" label="#{bindings.Date__c.hints.label}" required="#{bindings.Date__c.hints.mandatory}" shortDesc="#{bindings.Date__c.hints.tooltip}" id="_xg_7" autoSubmit="true" minValue="#{currentDateBean.minDate}">
  23. Save the file and create again the sanbox.zip, login to OIM and import the sandbox. Follow step 20 and set the required property to false (we had just set it so that we can get the tag in sandbox).


    If you have any questions or need more details, please update the comments. I will try my best to answer them.
    -gaurav

    No comments:

    Post a Comment