Saturday, 21 September 2013

ADF Search Form; Date Search

In this Post we will make a simple Search Form.

But more importantly, we will see how to handle the Date Search on a Date Column. Normally users searche by Date and not Time (e.g., on 19th Sep How many Employees were created). Oracle stores time along with the date in its Date Types. So when a user searches with Date (which by Default has no Time Element so it passes 00:00:00 in the time element) ADF does not pull any records.

Create a table XX_EMPLOYEES and insert following data. Make sure that Time part is not Truncated while inserting the date.


Create a New Web Application with Name as DateSearch and give Prefix as "com.adf.datesearch". Chose default in the Next Screens and Finish. 

Right Click on Model and Chose "Business Tier" -> "ADF Business Components" -> "Business Components from Tables" -> Query for the Table XX_EMPLOYEES -> Click Next -> In Updatatable VO Shuttle the EO to the Right Hand Side -> No Need to give anything in Read Only View -> Keep saying OK but make sure that the View XxEmployeesView is Added to a AM.

Finally the model should look like below:



Now the most Important Part, which is about the Date Search Issue.

An easy to resolve this is to include another column on VO Query and Truncate its time part using Trunc function. Goto VO -> Query -> Open the Query in Expert mode and add another Column name 
trunc(XxEmployees.CREATION_DATE) ONLY_DATE as shown below in the screenshot.


Make sure that this is showing in the Attributes as below:


Right Click on AppModule and Run. Click on XxEmployeesView1 and Click on Search Icon (Blue Binoculars) and give the date on Only Date Prompt and hit Find.



Try the same with CreationDate and you will not get any records.

Now lets build a jsf page. Right Click on the ViewController Project -> New -> Web Tier -> JSF -> JSF Page -> Ok. On the resulting "Create JSF Page" give the Page Name "DateSearchPG.jspx" -> Ok.

Goto DataControl -> XxEmployeesView1 -> NamedCriteria -> Drag "All Queriable Attributes" onto the Page as shown below: 


This will open another Dialog Box to Edit Table. Simply chose Ok. 

Now run the page and Search with OnlyDate and you should get the results you want as shown below. However if you search by CreationDate nothing will show.




Note: For every VO Created, JDeveloper Automatically Create a Default "View Criteria" using all Queriable Attributes on a VO. Since All the Attributes by default are queriable so in the Query Component you will see all. Since the search is not done on IDs and certainly not on ROWID you can goto the XxEmployeesView.xml and change the ROWID, CreationDate, EmpId to non queriable.


Edit OnlyDate Attribute and change the Label to "Date Created" in Control Hints as shown below:


Run the page and do some Search on Date as shown below:

Friday, 20 September 2013

Hello World in ADF

With Java Basics up your sleeves, you are ready for the "Hello World" of ADF. We will create a Page with an Input Text and a Button.

Activity: We will create a Page with an Input Text with label Name and a Button. On pressing the button message will appear on the top of the Page greeting the user.

The final page should look like below:



Create a "Fusion Application" with name as Hello, chose default values which will create a Model and ViewController project as below.


Now lets create a page on which we will create an InputText and a Button. Right Click on ViewController ->Web Tier-> JSF Page. Enter the name as HelloWorld and make sure that no Managed Bean is selected as shown below.


On the page drop an OutputFormatted, InputText and a Command Button. The page should look like below:



In the Source View, it should look like below:


Now, we need to handle the event on the button and modify the Output Text programmatically. To achieve that we need to create a Managed Bean which is used to gain access (and change) to the values on the Page. Select Output Text and chose the Binding property 


Chose Bean Name as MB and Class Name as "HelloManagedBean", package as "com.hello.mb"


Chose property as OutputMessage as shown below:


Similarly create a Binding for InputText. Chose MB as Managed Bean and name as "nameTextArea".
Click Ok and this will create a Class with Getter and Setter methods automatically created which will be used to get and the values programmatically on Button Click.

Now, we have to handle the Button Click event and take the values of Input Text and display the value in Output Text. Double Click the Button and chose MB as managed bean and let Method be cb1_method as shown below.


This value will be set on the Binding of the CommandButton as #{MB.cb1_action}
This will open the Managed Bean, type the following code in the method cb1_action 

    public String cb1_action() {
        // Add event code here...
        
        RichInputText helloString = getNameTextArea();
        outputMessage.setValue("¡ Hola "+ helloString.getValue().toString() +" !");
        
        return null;
    }


Here is the Screenshot for reference.


Now run the page.