Thursday 16 May 2013

ADF | Button Action or ActionListener queuing through bean programatically.

During development sometimes we have to call several button events at a time. In ADF Button event listeners or we can say Action or ActionListeners can be called programmatically. There is a concept of action queuing in ADF. But i found a much easier and better way of doing it. As we call methods in java, we can call the Action or ActionListener too by passing the suitable parameters. In the given example I am simply using print statements to demonstrate. Follow the simple steps :


  1. Create an ADF application in JDeveloper and define a task flow and then create a view and add 3 buttons on the view. Nae them differently so that you can identify them. Here I have used names "Button 1" , "Button 2" , "Button 3". I have defined ActionListeners for all three buttons.
     
  2. Now go to bean and just write print statements in the actionListeners just to make sure that the control came to it.
  3. Now run the application and click on the "Button 3". Now look on the console, the print statements off the other two actionListeners are also printed. Thus our task is complete.
  4. Am attaching the sample application for this, You can download by clicking here.QueueingDemo.rar
  5. Note: This procedure will not work if you are using the ActionEvent's object i.e. passed in the method. If you are using the ActionEvent then you have to call the method by initializing the ActionEvent with the appropriate button.
    • First, create a binding of the component in the bean whose actionLister is to be called.
    • And then use :
      ActionEvent event = new ActionEvent(this.componentBinding);

      ** Here "componentBinding" is the binding of the button component in the bean.
      To initialize the ActionEvent and then use the object " event " to call the ActionListener

Tuesday 7 May 2013

ADF : To implement duplicate record validation form Entity Object (EO)

Most of the time we need to make sure that no duplicate value should exist in database. For example you are making an entry in the employees table in HR schema you dont want that no two employees have same First name. So, in ADF you can eaisly implement this validation. You just have to put an integrity constraint in the EO and simply give the message that you want to show when the user enters duplicate employee name.

  1. Create a Fusion Web Application(ADF) in JDeveloper. And create connection to the database. And then create a taskflow and then drag an view from component pallate and then give it a name and create a jsff page.
  2. Then right click on the model and then create business components from tables. And then select the employee table and create VO and EO and add the same in AM.
  3. Now select EmployeeEO and in "General" tab add an alternate key with "First Name" column, then go to "Business Components". And then select "Entity Validators" and click on Add button. And choose Unique key in "Rule Definetion". Then go to the another tab in the popup "Failure handeling" and write the message that you want to show when duplicate record is found.


  4. Then just go to the jsff page and then then create a form from the table that comes shows in Datacontrol. Then just add "createInsert" and "commit" button from the operations in datacontrol.
  5. Then create a jspx page in viewController and drag the taskflow in it and right click and run the page. Click on createInsert button and enter a name in First Name that already exists and then click Commit. Then the error will come up at First name field.


    You can download sample app here. DuplicateRecordCheck.rar
    Simply download and unrar it and the run it in JDeveloper.