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 - :
- Lets start with creating the managed bean, create a new generic application in Jdev.
- Name the application, the prefix should be oracle.iam.ui custom.
- Name the project, don't select any technologies and click finish.
- Right click on the application and say new.
- Select ADF View Controller project.
- Name the project.
- Make sure the default package is oracle.iam.ui custom.
- 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
- Create a new a new class in the project. The class should extends oracle.iam.ui.platform.view.backing.BaseStateMBand implements Serializable.
- Create a private property of type Date. Generate its getter and setter.
- 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;
}
}
} - Make sure there are no compilation errors, your bean is created now go to webcontent>PageFlows>adfc-config.xml.
- Declare your managed bean and specify its scope.
- 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.
- 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.
- 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.
- ZIP the war again and upload/place it to OIM_HOME>apps. To avoid extra work, take a backup of war.
- 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.
- This may take time and you might get a timeout error, don’t worry your deployments are updated, restart the oim servers.
- 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.
- 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.
- 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}"> - 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