Build Responsive Web Applications with Oracle ADF


Options



Before You Begin

Purpose

In this tutorial you’ll build a web application that displays information about employees. The focus of this tutorial is on the development of a rich user interface that leverages some of the key concepts of the Oracle Alta UI design system. For more information on Oracle Alta UI – http://bit.ly/oraclealta

To develop the application you’ll be leveraging Oracle JDeveloper and Oracle ADF. Oracle ADF is Oracle’s application development framework for simplifying the development of Java applications, focusing on providing a visual and declarative approach to application development.

As you’ll see during the tutorial the amount of manual code you’ll need to write is minimal. However at any point of time you can click the source tab, and see and modify the actual code of your application.

At the end of the tutorial, your application should look like this:

This screenshot shows the employee names to the left and 4 regions to the right displaying employee information.

What Do You Need

To complete this tutorial you must:

1: Have access to or have installed Oracle JDeveloper 12.2.1. You can download it from Oracle Technology Network. Install it into a directory of your choice, which, in this tutorial is referred to as JDEVELOPER_HOME.

2: Download the AltaLab.zip and save it to you local drive.

Required Files
Download Files

The application that you create displays information about departments and employees. Click the Download link and save the altalab.zip file to your local hard drive. Then, unzip it and take note of the location.

Download solution application

Step 1: Open the application and create a page

We are going to skip the part of developing access to our data source for now, and rely on a set of data that is already developed. If you are interested in learning to develop the layer that exposes data we recommend running through this tutorial: Introduction to Oracle ADF Development.

For now we’ll just open an existing project.

  1. Start JDeveloper by selecting Start > Programs > JDEVELOPER_HOME > OracleHome > Oracle JDeveloper Studio > Oracle JDeveloper Studio.

    If a dialog box opens asking if you would like to import preferences from a previous JDeveloper installation, click No.

  2. In the Select Role dialog, select Studio Developer (All Features) and click OK.

    This screenshot shows the various Roles in J Developer with the Studio Developer (All Features) option selected.

    Shaping, which is based on the role of the user, allows the JDeveloper environment to tailor itself. It does this by removing unneeded items from the menus, preferences, new gallery, and even individual fields on dialogs.

    Shaping can even control the default values for fields on dialogs within the tool. When you first start JDeveloper, you are prompted to choose a role that describes how you are going to use JDeveloper. If you choose a role of "Java Developer" versus "Database Developer " versus "Customization Developer " you will get a totally different experience!

  3. If a dialog box opens asking if you would like to import preferences from a previous JDeveloper installation, click No.

    This screenshot shows the dialog with details about the J Developer installation to import from.
  4. In the Track Usage popup, click OK.

    This screenshot shows the dialog with a checkbox enabled that automates usage reporting to Oracle.
  5. Once loaded, the JDeveloper IDE appears. The very first time you open JDeveloper, the Start Page displays. You can re-invoke the Start Page later by choosing Help > Start Page.

    Notice the various options available to help you learn about JDeveloper. After exploring some of these options, close the Start Page by clicking the X on its tab (the X appears when you mouse over the tab).

    This screenshot shows the J Developer Start Page. The Learn and Explore tab is selected which displays links to various       tutorials and documentation.
  6. From inside JDeveloper, select Open Application…

    This screenshot shows the Open Application button available in J Developer.
  7. Navigate to where you unzipped the AltaLab.zip file and select the AltaLab.jws file.

    This screenshot shows the Open Applications window with the location as C : \ Alta Lab. The Alta Lab.j w s file is selected.
  8. The application consists of two projects – the Model project has our data sources. The ViewController project is where we’ll develop our user interface.

    Right click the ViewController project and select New - Page.

    This screenshot shows the Model and View Controller projects of Alta Lab application. In the context menu of View Controller,  New - Page is selected.

    Set the File Name to dashboard.jsf.

    Select Reference ADF Page Template and then select the Tablet First Template.

    Click OK.

    This screenshot shows the Create JSF page wizard with the filename. In the Page Layout tab, Reference ADF Page Template -     Tablet First Template is selected.
  9. You’ll be taken into the visual page designer in JDeveloper. You see the page template and will be able to design your page dragging and positioning items on the page.

    This is a good time to get yourself familiar with the key areas in the JDeveloper IDE.

    This screenshot shows the different panels that are displayed for the JSF page created in J Developer.
  10. Make sure the af:pageTemplate is selected on the Structure pane on the left and look at the template’s properties.

    This screenshot shows the a f : page template option selected in the Structure pane.

    Change the endWidth property to be 0px. Change the value of the showAppNavbar property to false.

    This screenshot shows the Properties pane for a f : page Template. end Width is set to 0 px and show App Nav bar is set to    False.

Step 2: Add data to the page

In this section, add a list of employees to the page.

  1. Expand the Data Controls palette accordion in the Application Navigator area, expand the HRService control locate and select the allEmployees data control. This is a collection of the employees working in the company.

    This screenshot shows the Alta Lab Application Navigator pane in which all Employees is selected in the Data Controls         accordion.
  2. Drag it into the start area on the page in the visual editor area (or the f:facet-start entry in the structure pane)

    In the popup menu, select the Table/List View - ADF List View… option.

    This screenshot shows where to drag and drop all Employees in the page editor. In the pop menu, Table/List View - ADF List    View option is selected.
  3. Select the Panel Grid Layout in step 1 of the wizard and click Next.

    This screenshot shows the Default Layout page of the wizard. The Panel Grid layout is selected in the right pane.
  4. In step 2 change Rows to 1 and click Next.

    This screenshot shows the List Item Grid page of the wizard. Rows text box shows 1 in the right pane.
  5. Click Next again in step 3.

    In step 4, in the Value Binding column, select the firstName and lastName for the value binding of the two columns. Then click Finish.

    This screenshot shows the List Item Data page of the wizard. The row with cell g c 1 , 2 is highlighted in the right pane.
  6. This created a list of employees on the page. Let’s enable users to select an employee from the list. To do this, verify that af:listView is selected in the structure pane, and in the property inspector set the Selection property to be single.

    This screenshot shows the list View of f : facet - start selected in the Structure pane. In the Properties pane, Selection    property is set to single.
  7. Scroll to the end of the properties and locate the SelectionListener property click the little blue wheel that appears to the right of the value field.

    This screenshot shows the Properties pane for list View. The Selection Listener value field with the blue wheel is            highlighted.
  8. From the popup menu, select Method Expression Builder….

    Expand the tree to select ADF Bindings - bindings - allEmployees - treeModel - makeCurrent and then click OK.

    This screenshot shows the Method Expression Builder window. make Current is selected in the ADF Bindings tree.

    (Alternatively you can just type the value #{bindings.allEmployees.treeModel.makeCurrent} into the value of the selectionListener property.).

    This screenshot shows the Selection Listener value in the Properties pane as selected from the Method Expression Builder.
  9. Click the Save All button in the toolbar, and right click inside the page designer to bring up the context menu and select the Run option (green arrow). .

    This screenshot shows the page editor context menu displayed on right click. The Run option is highlighted.
  10. This will package your project so far, start WebLogic and deploy your application to it. After a couple of minutes a browser will open showing your page.

    The list of employees will show up and you can select any of them, at the end of the list you’ll also see a “Load More Items” option allowing you to bring the details of more employees into your list. This is ADF optimizing the amount of traffic between the browser and the server.

    This screenshot shows the browser page with the employee first and last names listed to the left.

Step 3: Add responsive layout to the page

Next we are going to create a responsive area on our page that can respond to changes in browser width. This allows us to create a single page that will display in a clear way on tablets in both landscape and portrait mode for example.

Keep the browser open, and switch back into JDeveloper.

We are going to use a Masonry layout component that automates responsive behavior when the browser size is changed.

  1. In the structure pane select the f:facet-center area of the template, then from the component palette on the right side expand the “ADF Faces” accordion and click the Masonry Layout component.

    This will add the af:masonryLayout component into the center facet.

    This screenshot shows where to drag and drop the Masonry Layout from ADF Faces accordion of the Components pane to the page editor.

    You could also drag and drop it from the component palette to the visual designer or to the structure pane.

    This screenshot shows the Masonry Layout component added to the center facet in the Structure pane.
  2. Next, we are now going to define 4 sections that will populate the masonryLayout..

    Expand the Layout section of the components palette and locate the Panel Group Layout component. Then, drag and drop it into the af:masonryLayout in the structure pane.

    This screenshot shows the Panel Group Layout component added to the Masonry Layout in the Structure pane.

    Repeat this three more times, so at the end your af:masonryLayout contains 4 - af:panelGroupLayout components.

  3. Use Shift+Select to select all 4 and look at the their properties.

    Then, set the Layout property to be vertical

    This screenshot shows 4 Panel Group Layout components added to Masonry Layout in the Structure pane. The Layout value in the  Properties pane is set to vertical for the 4 components.
  4. Next locate the StyleClass property and set it to AFMasonryTileSize2x1 tileStyle.

    This screenshot shows the StyleClass value set to A F Masonry Tile Size 2 x 1 in the Properties pane for the 4 Panel Group    Layouts.
  5. Click Save All then switch to your web browser and reload the page.

    Play with the width of the page to see how the area’s re-arrange when the browser window width is smaller.

    This screenshot shows a browser page with the employee names to the left and 4 empty regions of area 2 x 1 to the right.
  6. Back in JDeveloper, select the two lower af:panelGroupLayout components and change their styleClass from 2x1 to 2x2 – this will make them bigger.

    This screenshot shows the StyleClass value set to A F Masonry Tile Size 2 x 2 in the Properties pane for the last 2 Panel     Group Layouts.
  7. Save All and reload the page in the browser to see the change.

    If you closed the browser window, scroll up in the log window in JDeveloper to find the URL of the application, you can click on it to open the app in the browser.

    This screenshot shows a browser page with the employee names to the left and 4 empty regions to the right, of which the last  2 regions are of area 2 x 2.

Step 4: Display employee information

In this section, you set data in the first box on our page is going to show the image name and role of the employee we choose from the list. We are going to split the box into two sections using a panelGridLayout.

  1. Select the first af:panelGroupLayout in the structure pane (or in the visual editor), then from the component palette - layout select a Panel Grid Layout.

    This screenshot shows the first Panel Group Layout selected in the Structure pane. In the Layout accordion of the Components pane, Panel Grid Layout is highlighted.
  2. Keep the 2 columns and 2 rows setting and click Next.

    This screenshot shows step 1 of the Create Panel Grid Layout wizard. Rows and Columns are set to 2.
  3. In the second step of the wizard switch the Spans tab and define a span from gc1,1 to gc2,1.

    Then click Finish.

    This screenshot shows step 2 of the wizard. In the Spans tab, the From and To options are selected accordingly.
  4. Select the top right gridCell and from the Data Controls palette drag the allEmployees collection into that gridCell and select Create - ADF Form…

    This screenshot shows step 3 of the wizard. It shows where to drag and drop all Employees from the Data Controls palette to   the Visual Editor. A Create context menu appears in which ADF Form is highlighted.
  5. In the Create Form dialog check the Read-Only Form check box and remove all the fields using the red X except for firstName, lastName, title and email. (You can use shift select to select all the fields).

    Then click OK.

    This screenshot shows the Create Form wizard with the Read-Only Form checkbox enabled. 4 components are displayed under       Fields.
  6. In the data control palette expand the allEmployees node and locate the image attribute. Drag it into the first gridCell and select Text - ADF Output Text.

    This screenshot shows where to drag and drop an image attribute from Data Controls palette to the Visual Editor. A Create     context menu appears in which Text - ADF Output Text option is highlighted.
  7. While the new field is selected in the structure pane, copy the value that is inside the Value property of the field. #{bindings.image.inputValue}.

    This screenshot shows the Properties pane for Output Text. The Value property reflects # { bindings . image . inputValue } .
  8. Next, we’ll now convert this text field to an image component.

    Simply right click the af:outputText and select Convert To… from the popup menu.

    Select Image, and then click OK and then click OK to accept the removal of the Value.

    This screenshot shows the context menu for Output Text. The Convert To option is selected and in the Convert Output Text      dialog, Image option is selected.
  9. Now we’ll set the source of the image to be the value we copied from the field with the path to our images directory.

    Set the Source property of the image component to be resources/images/people/#{bindings.image.inputValue}.

    This screenshot shows the Properties pane for Image. The Source property value reflects the path to images directory.
  10. Click the Save All and then click the Rebuild button , then reload the page in your browser.

    Select different employees in your list and see the details change in the box.

    This screenshot shows a browser page with the name of the employees to the left. The first region to the right displays the   Image, First, Last, Title, and Email address of the selected employee.

Step 5: Add a chart to the page

In this section, you add some data visualization to our page. A picture is worth a thousands words – and charts are one of the preferred way of showing data in Oracle Alta UIs.

  1. We are going to work with the second af:panelGroupLayout (second box on our page) so select it in the structure pane or the visual page editor.

    This screenshot shows the second Panel Group Layout component selected under Masonry Layout in the Structure pane.
  2. In the data control palette expand the allEmployees data control and scroll down to locate the perfHistory collection – select it and drag it into the second af:panelGroupLayout and select Chart…

    This screenshot shows where to drag and drop perf History from the Data Controls Palette to the Structure pane. In the        Create context menu, Chart option is highlighted.

    In the popup, select the Line type of chart and the second Quick Start Layout.

    Then click OK.

    This screenshot shows the Component Gallery wizard. Line is selected as the category and chart types. The second Quick Start  Layout is selected.
  3. This will take you into the line chart creation dialog, here we are going to define which data is going to be shown in the chart.

    For the Lines we wan to use the rating field, and for the X Axis we’ll use the effective field. Drag or select them in the right location.

    Then, click OK.

    This screenshot shows the Create Line Chart dialog where Lines field has rating and X Axis field has effective as the values.
  4. Make sure that the dvt:lineChart is selected in the Structure pane and in the Properties window set the Appearance - TimeAxisType property to enabled.

    This screenshot shows the Appearance accordion in the Properties pane. The Time Axis Type property value is set to enabled.
  5. Scroll down to the Title property and set it to Ratings, then locate the InlineStyle field and type width:300px; height:150px; This will size the chart to fit into the box).

    This screenshot shows the Appearance accordion in the Properties pane. The Title value is set to Ratings and the Inline       Style property shows the values set for width and height.
  6. Save All and Rebuild your project and the reload the browser window.

    This screenshot shows a browser page with the name of the employees to the left. Region 1 shows the employee details and      region 2 shows a line chart.
  7. Next we’ll add a chart showing the breakdown of the compensation of an employee.

    This will go into the third af:panelGroupLayout on the page.

    Locate the pieComp data control and drag it into the third panelGroupLayout drop it as a Chart…

    This screenshot shows where to drag and drop pie Comps from the Data Controls Palette to the Structure pane. In the Create    context menu, Chart option is highlighted.

    Select the Pie, and click OK.

    This screenshot shows the Component Gallery wizard. Pie is selected as the category and Chart Types. The Quick Start Layout   is selected.
  8. For the pie drop down list select itemValue, drag the itemLevel to the Slices field.

    This screenshot shows the Create Pie Chart dialog. The Pie dropdown is selected as item Value.
  9. To turn the pie into a doughnut chart, in the properties for the dvt:pieChart set InnerRadius to 0.5, set the styleClass to chartStyle, and the Title to Compensation.

    This screenshot shows the Properties pane for the pie chart. The property values for Style Class and Title are set to chart   Style and Compensation.
  10. Save All and Rebuild your project then reload your browser window.

    This screenshot shows a browser page with the name of the employees listed to the left. To the right, region 1 shows the      employee details, region 2 shows a line chart, and region 3 shows a doughnut chart.
  11. Next we are going to add a special data visualization called NBox – this is a way to represent data points across multiple axis. We are going to see how the peers of the Employee rate in terms of their potential and their ratings. We are going to place this component, so we are going to make the third box smaller and the fourth one bigger.

    Select the third af:panelGroupLayout and change the style class to AFMasonryTileSize1x2 tileStyle.

    This screenshot shows the Properties pane for the third Panel Group Layout. The Style Class property value is set to A F      Masonry Tile Size 1 x 2 tile Style.

    Select the pieChart and in the InlineStyle property change the value to width:150px; height:300px;.

    This screenshot shows the Properties pane for the pie chart. The Inline Style property shows the values set for width and     height.

     

  12. In the fourth af:panelGroupLayout, but we need more space for it, so click the af:panelGroupLayout and update the styleClass to be AFMasonryTileSize3x2 tileStyle.

    This screenshot shows the Properties pane for the fourth Panel Group Layout. The Style Class property value is set to A F     Masonry Tile Size 3 x 2 tile Style.
  13. Locate the colleagues collection and drag it into the fourth af:panelGroupLayout choose NBox….

    In the first section of defining the NBox we need to define the axis and values of the boxes. Fill out 3 for both Rows and Columns, type Potential and Rating for the rows and columns titles. Then click the lower left corner and in the Row1 and Column1 fields type low.

    This screenshot shows the Create N Box dialog. The first column is highlighted and the value of Row 1 and Column 1 is set to  low.
  14. Next click the column to the right and for the empty column value type med.

    Then, click on the right most column and type high for the column value.

    This screenshot shows the Create N Box dialog. The Column 2 value is set to med and Column 3 is highlighted and the value is  set to high.
  15. Now let’s fill out the rows. Click the middle row and in the Row value field type med, then click the top row and type high in the row value field.

    Your dialog should look like the image below. Then click Next to move the the next step of the wizard.

    This screenshot shows the Create N Box dialog with Row 1 value set to high, Row 2 set to med, and Row 3 set to low.
  16. In the next step of the dialog select nboxPotential for Row, and for Column select nboxRating. For Label choose empName.

    Click the icon tab, and set the radio button to Shape.

    Click the green + sign to add grouping rule:

    Select potential for both the Group by Value and Legend columns. The Icon should default to color and that is fine.

    Click the green + sign to add another grouping rule:

    Select rating for both the Group by Value and Legend columns, and set the Icon to be Shape.

    Then click Finish.

    This screenshot shows page 2 of Create N Box wizard. In the icon tab, Shape is selected and two Grouping Rules are displayed.
  17. Set the InlineStyle property of the af:nBox to width:500px;height:300px;.

    This screenshot shows the Properties pane for the N Box. The Inline Style property shows the values set for width and height.
  18. Save all and Rebuild your project and reload your page in the browser window.

    This screenshot shows a browser page with the employee names listed to the left. To the right, region 1 shows the employee    details, region 2 shows a line chart, region 3 shows a doughnut chart, and region 4 shows an nBox with details.