You are here

Using the username in a JSR 286 portlet with ADF business components in WebCenter

In my previous post i have explained how we can get the current username in JSR 286 portlet. In this post we will take it to the next level and use the username to power a view criteria in our model project.

So this post is more an example portlet that shows you how to use business components, taskflows and the username in a JSR 286 portlet.

You can of course download the sample project to see how everything works.

We are not converting an existing taskflow to a portlet. Instead, we create a new application and use the Portlet Producer Application as the template

In the application I have created a single Standard Based JSR 286 portlet. The only special step is the 3th one. We need to specify that we want to use ADF-Faces for our portlet:

Because we want to pass the username to our portlet we need to add an additional parameter to the Container Runtime options in the portlet.xml:

The next thing we need to do is create the model project. The Portlet Producer Application does not have a model project so we need to create one. Just press File and New and select the ADF Model project:

So let's create a simple model with just a single EO and VO. We will use the HR schema for this. We will use the employees table to create a view criteria that will show all the employees with the same first name as the current username.

Right click on the model project and select New. Select Business Components from Tables

First you need to create a connection or select from an existing connection from your application. Just create a connection to the HR schema on your local XE for example . In my project I have a local XE on the default port with default username and password for the HR schema (hr/hr).

Just add the employees table in the Entity Objects and as View Object. This is how the model looks like:

Open the EmployeesView because we will create a view criteria that uses a bind variable for the username:

Now that's done we need to add the view criteria to our application module:

In order to execute the query with the parameter, we create a simple taskflow that has the ExecuteWithParameters method as the default activity that redirect to a jsff that contains the emp view:

In the bindings of the ExecuteWithParams we pass the username by using expression language #{securityContext.userName}

By doing this, the username will be passed to the bind variable of our view criteria.

The jsff fragment just displays the EmbByuserName view from our data control. Nothing special to that.

Just deploy the portlet and consume it in a webcenter application. In order to test this example, you need to add a user to the jazn-data so the username matches with a firstname of the emp table.

In my case i have added a user called Steven. When i login with this user, i will get followingrecords:

So as you can see, it's not really that complicated. The most important step is to add the additional parameter to the runtime container. If you don't do that, the securityContext.userName will always return null.

WebCenter Tags: 


this is really an inspiring blog. I am a newbie in webcenter. I have a HomePage where in i accept a Person ID and then pass it to another page which contains a wsrp v2 portlet. The Person ID is getting passed and I have even set the default value of portlet using EL. But the portlet displays only form Layout and data is not getting displayed.
whenever i navigate in the portlet, i get the error:


i am using the same version you are.
Please help me asap.
THank you.

Theme by Danetsoft and Danang Probo Sayekti inspired by Maksimer