Oracle ADF Faces Cookbook
上QQ阅读APP看书,第一时间看更新

Running your first ADF Faces application

In this recipe, we will run our application in multiple scenarios by trying the worst scenario first and enhancing it till we reach the best scenario.

How to do it…

To run your first ADF Faces application, perform the following steps:

  1. Locate your task flow retrieve-employees-information and right-click on it.
  2. Click on Run or select it and click on Run (the green arrow icon) on the toolbar, and the page will start appearing.

    Tip

    If this is the first time you run an application in JDeveloper, a pop-up window will ask you to instantiate your first Weblogic instance and will ask you about the password for your weblogic user and port numbers.

If you did everything correctly, you should see a form that you can navigate through with Next, Previous, First, and Last.

How to do it…

However, if you check the URL, it's quite ugly. It's not quite what you have in mind, so how can it be enhanced?

Tip

This method is not recommended and is only used for debugging and testing Page-based task flows, but it's worth mentioning.

The second scenario is where you run the page directly. So let's try that and see if there are any changes.

  1. Right-click on the employees.jsf page and run it. You will probably get a warning message from JDeveloper telling you that running the page itself is not recommended, which is true, but ignore it for the moment and click on Yes; let's examine the end result.

    The URL is much better now; it doesn't show all the adf.task-flow parameters in the URL that expose a bit of sensitive information about our task flow.

    But still, the warning from JDeveloper means that this way is also not recommended, so what is the best way to run your application?

    Well, if you remember, we said that the adfc-config task flow and usually any unbounded task flows are generally responsible for the application's navigation model, so why don't we use it? In order to do so, all we have to do is expose the employees.jsf page as a View activity in that task flow.

  2. Open the adfc-config task flow.
  3. Drag-and-drop the employees.jsf page from the Application Pane into the body of the task flow to have it look like the following screenshot:
    How to do it…
  4. As you can see, the activity's name is employees without the .jsf part, and this is what is going to be shown in the URL.

    By doing this, we added the employees.jsf page as a View activity inside the adfc-config task flow, which as you know can act as an entry point since unbounded task flow has unlimited entry points.

  5. Right-click on adfc-config and run it; you will now see an even more enhanced version of the URL. You will see something like the following:

    http://127.0.0.1:7101/ViewController/faces/employees

    This is good, but ViewController isn't really the name of our application. So, in order to make the name reflect your application, let's rename it to what JDeveloper thinks is the name of our application.

  6. Right-click on the ViewController project and click on Project Properties… at the end of the list; select Java EE Application.
  7. Change Java EE Web Application Name and Java EE Web Context Root to something like helloadf and then run again; now, you can see your application with a nicely formatted URL like the following: http://127.0.0.1:7101/helloadf/faces/employees

    Tip

    You can also run the page directly from the ViewController project. It'll ask you for a target to run; choose the adfc-config. It'll also ask you for the target inside adfc-config; choose employees.

How it works…

In this recipe, we tried three different methods to run our ADF application; however, it is preferable to always use the third method; adfc-config is the heart of your ADF application and contains all of the project's navigation information. From the task flow, you can notice that there are no green circles behind the page, which means that if you have any other activity, then the new activity can also be called directly and it doesn't have to follow any order.

If you run your application using any one of the scenarios and this is the first time you run an application in JDeveloper's lifetime, it'll create the weblogic domain first with no managed servers and only one admin server. It'll be created under the JDEV_USER_HOME environment variable that we created. After the domain is created successfully, the Admin Server starts, and after it does, JDeveloper starts packaging the application into a WAR (Web Archive) file. You can see this deployment profile by right-clicking and navigating to ViewController | Properties | Deployment; you will find an entry that represents the WAR packaging of this project. This project is also dependent on the Model project, which means that packaging will include all the stuff created in the Model Project. After the WAR file is created successfully, JDeveloper starts deploying the WAR file into the Admin Server. If the operation is successful, it will start to access the URL of the application inside the embedded Weblogic Server to show the target.

When you view the page, you can see that each input that has bindings represents a data field from the Employees table. When you start clicking on the buttons, you can see that the row of focus is changing to the next, previous, first, or last row, and you can validate this data against the database.