It's been a while since I wrote my last part of this tutorial so it's about time I continued with it. Meanwhile I got some great ideas for additional content of this tutorial so keep supporting it and I will keep posting it!
In this part I will show you how we can build a taskflow in a separate application and then import that taskflow into our WebCenter portal application. The taskflow will display a simple form so people can register themselves to our portal. The form will contain a username and password field. We will do simple checks like password and password confirmation check and display a message when the user already exist.
Before we begin, a small disclaimer: the code provided to create a user will only work to create a user in the default security realm of a WebLogic server. If you are using OID or any other external provider, the code provided in this tutorial will no longer work. The aim of this tutorial is to show how to separate the taskflows from your portal and how to include them into your portal application.
That said, let's get to work.
The first part of this tutorial will be about the creation of the Register taskflow. Let's start by creating a new Fusion Web application. Yes, that's right. A regular Fusion Web Application, no WebCenter Portal Application:
Specify the name and package
We won't be needing the Model project so just leave these as the default value.
It is a good practice to change the ViewController to something more meaningfull so specify RegisterView as the project name:
Press Finish to complete the creation.
Right click the WEB-INF folder and select New.
Select JSF from the list on the left and ADF Task Flow on the right:
Press OK and specify registerTF.xml as the filename. Make sure that the checkbox Create as Bounded Task Flow is checked. The difference between a Bounded and Unbounded taskflow is that a Bounded Taskflow has a single point of entry and can have multiple exit points. An Unbounded taskflow can have multiple entry points. By default, JDeveloper will create an Unbounded taskflow when you create a Fusion Web Application. The definition can be found in the adfc-config.xml. This is not really important for WebCenter but I just wanted to give you some background information about this...
Press the OK button to create the taskflow.
Our Register taskflow will be a very simple taskflow. It will only have a single view in its definition. So drop the View component from the Component Palette on the Diagram of the taskflow and change the name to register:
The green background circle means that the register view is the default activity. This activity will be executed when the taskflows renders. The warning is displayed because we didn't bind the view component to an actual fragment so double click on the register view. This will open the Create New JSFF page fragment wizard.
The filename will be set to the name of the view which is fine. Change the folder so it ends on \register as shown in the image:
Personally I find it good practice to create a folder for each taskflow to group the fragments of the same taskflow together.
Before we add some components to the register fragment we need to create a managed bean to store our code in.
right click on the RegisterView project and select New. Select General in the left menu and Java Class in the right list.
Name the class RegisterBean and specify a class:
Press OK to create the Java Class.
Add a username, password, passwordConfirm string to the class and create the accessors.
Create the createUser method in the class with following code:
This method will create the user in the security realm of your WebLogic server. As you can see from one of the last lines of code, we also grant the user a role. This is required to allow the user to authenticate. Before this code can compile, we need to setup security to our application. This is done. This is done by selecting Application => Secure => Configure ADF Security:
Because we only need the libraries and the actual security is not really important, we can just press Finish and keep the defaults. The WebCenter Portal will contain the actual security settings. This is setup by default so you don't have to worry about that.
A next step is to create the role that we assign to the user. This is done in the WebLogic console so make sure your Integrated WLS is running and browse to http://localhost:7101/console
Login to the console and select security realm in the domain structure in the left hand side. Select myrealm.
Select the Users and Groups tab and select the Groups tab:
Click on the New button to create a new group. Specify member as the name and press OK:
This will create the group in the security realm so we can assign this by using our method from above. Notice that the group name is the same as the role name specified in the code!
The taskflow will display a link to register which will open a popup that displays the form. The popup uses a dialog so we need to have a dialogListener to handle the dialog events:
This method will check if the OK button is clicked. If so, it will create the user by calling the createUser method and display the message to the user so he knows he can login. If there was an issue, the user will see a message that the registration has failed.
That's it for java code for now. Let's register the bean to our taskflow. Open the registerTF.xml and open the Overview. In the Managed Beans section press the Add button and specify following values for the managed bean:
Save the taskflow.
Now we can finally create the code for the register.jsff fragment.
We add a commandLink to open a popup and the popup will contain the form for username, password and passwordConfirm:
That's it. Now we can deploy this taskflow as a library so we can use it in WebCenter.
If you want to consume taskflows from other applications, you need to deploy those applications/taskflows as an ADF Library JAR so we need to create a special deployment profile for this.
This can be done by right clicking on the RegisterView project and select Project Properties
Select Deployments and click the New button on the right hand side.
Select ADF Library JAR File as the archive type and specify a name for the profile:
Press OK to create the profile. Press OK in the next window to keep the defaults.
You now have two profiles:
Let's deploy the taskflow. This will actually not deploy the taskflow to any server. It will create a JAR file instead that we can use as a reference in WebCenter Portal.
Right click on the RegisterView project, select Deploy and select the adfLibRegisterTF profile.
In the next screen you can only select Deploy to ADF Library JAR file. Press Finish to deploy to the JAR file.
Now that we have created the Register taskflow and deployed it to a JAR file, we can consume it in WebCenter Portal.
If you got stuck in the previous section of this tutorial, you can download the RegisterTaskflow workplace from here.
First of all we need to create a File System connection to the location of the JAR file. In JDeveloper in the resource Palette right click on File System in the IDE Connections and select New File System Connection:
Specify a name for the connection and point the directory to the deployment path of the Register Taskflow project:
Make sure to point to the directory, not to the JAR file!
Press OK to create the connection.
When you open the connection you will see the jar and the taskflow:
Now we are ready to consume the taskflow.
Now it's time to open the ViePortal application. Open the VieTemplate.jspx and add a li before the logout li. Inside the new li drag and drop the registeTF from the adfLibRegisterTF we have registered in the resource palette to the VieTemplate.jspx. This will add the taskflow as a region and your code will look like this:
Because the WebCenter Portal application has security enabled, we need to configure which roles have access to the taskflow. When we drop the taskflow to our page, the registerTF library will be added to our project and we will be able to configure its security.
Open the jazn-data.xml from the descriptors/META-INF folder in the Application Resources. Select Resource Grants. Select Task Flows as the Resource Type and make sure you selected Show task flows imported from ADF libraries:
In the list look for registerTF. It is showing a lock icon which means that nobody can access the taskflow. Let's change this by adding the anonymous Application Role:
That's it! We are finished. Let's register a new user. Right click on the Portal project and select Run.
When the portal has started you will see the Register link on the right hand side:
Click it and it will open the Register popup:
And now I can login with my user.
That's it. As a summary of this section I will outline the steps to create and consume taskflows in WebCenter
You can download the finished ViePortal for this part from here.
Hope you enjoyed this section of the tutorial. As always, the comments are open for questions and opinions.