Sunday, October 28, 2007

Central Norway - Lillehammer City

Today I was doing sightseeing trip to Lillehammer city in Norway. This city is located on the north part of largest lake in Norway - Mjøsa. In the city center, through stones and mountains flows Lågen river. It's not so much water now in the river, but it is typical to Norway. Rivers here are full with water on Spring, when snow goes down from mountains. And yes, it's golden autumn here - yellow leafs are on the ground :-).

Thursday, October 25, 2007

Security in Oracle ADF and Automatic Page Loading

In enterprise applications, automatic page loading based on user role is used quite often. Automatic page load is done during user login phase. This means that when user with role A enters into system, page X will be opened for him. And in the same way, when user with role B enters into system, page Y will be opened. Information about which page to open is acquired from security container, but how to open dynamically one or another page - here is the question.

Solution I have used is to put some empty intermediate page between login module and application pages. After user is authenticated in login module, he is transfered to intermediate page. However, this intermediate page does not require any input from the user, implemented logic allows to check connected user role and based on it automatically open suitable page in application.

You can download developed sample application - Sample is based on Employees entity from standard HR schema. Two JSPX pages are implemented, first is opened when connected user have read-only access rights and second is designed for editable case. This means that two roles (clerks and managers) are defined in web.xml - one allows only read-only access and second editable. Clerks role is mapped to access clerks.jspx and managers role to access managers.jspx page. On both pages the same data from Employees entity is available.

It's time to describe how actually automatic redirection is done based on role. All logic is centered in index.jspx, so I will describe it. This page is used for automatic redirect, it is achieved with onPageLoad() function in backing bean. onPageLoad() function is defined as empty function in a class that implements oracle.adf.controller.v2.lifecycle.PagePhaseListener. In this class standard beforePhase(PagePhaseEvent event) function is implemented, provided functionality allows to call onPageLoad() during page loading process. Class code:

So, backing bean of index.jspx page extends this class and provides code for onPageLoad() function by overriding it:

In this function actual logic is implemented - depending on role, redirection is done. One important thing, do not forget to include ControllerClass definition into index.jspx page page-definition file. You should bind it to a name of backing bean for the same page:

How it works? Let's provide in login form a user with read-only access - alex (welcome):

Read-only table with Employees data is opened:

And if we are providing a user - john (welcome) who can edit data, another page is opened:

When running sample application, don't forget to add adf-faces-impl.jar and jsf-impl.jar to application's WEB-INF\lib directory.

Wednesday, October 24, 2007

Oracle OpenWorld Unconference - Session Proposal

I'm planning to do a session at Oracle OpenWorld Unconference. Session is called - Oracle JDeveloper/ADF Real Life Story, more info and it's description you can find on Oracle Wiki page. Everyone is welcome - see you at Oracle OpenWorld in San Francisco!

Chris Muir also will have a presentation related to JDeveloper topic at Oracle OpenWorld Unconference. His session will be focused on testing and related stuff. This session is very important, because from my practice I can see, that JDeveloper features are not used so frequently during testing phase. So, just come and see how testing should be done! ;-).

Monday, October 15, 2007

Oracle Fusion Middleware Workshop in Vilnius

Today I was on Oracle FMW (Fusion Middleware) Workshop in Vilnius, actually it was a workshop based on my material available in Oracle Fusion User Group (OFUG). There were 22 people auditory, at the beginning I have presented information about Oracle ACE Directors, Oracle Fusion Middleware, Oracle JDeveloper with ADF, and Technical Resources needed to start to work with Oracle JDeveloper and ADF. Presentation took for me about 1 hour, after it people started to solve labs. There were six labs, all of them are available in OFUG for free to download. During labs solving, there were quite many questions about ADF, I was glad to provide answers. At the end I realized, that while answering questions, I got even new knowledge for me. Thanks for great auditory!

Tuesday, October 9, 2007

Using Hidden Column in af:table Component

Quite often you may face requirement, when you will need to use hidden column in af:table component. Such requirement could be to insert into database, along with values provided by the user, some another value automatically. This value is not visible for the user and is inserted through a hidden column. Hidden column here should be understood as a column that doesn't exist in af:table component, but exists it's definition in page definition file for associated table.

Developed sample application - provides JSPX page with a table component, that allows to create new data for Employees entity. Five columns are available in the table - First name, Last name, Email, Hire date and Job Id. But along with data for those five columns, data for Salary column is stored into database as well. Value that is inserted into Salary column is retrieved from file. Now I will describe how actually data is inserted into a column, that is not available in af:table component.

First step is to use the same technique, which I have successfully used in my previous samples - to include managed bean method call into let's say ReadOnly property of any column available in the table. In developed sample application, I have included #{valueHolder.readOnly} into ReadOnly property of First name column. This technique allows to invoke managed bean method, when each row of af:table component is rendered. Managed bean method code:

Developed method always return false value, it is because we always want to have editable column and are using this method for other purpose. Method is used to set Salary value #{row.Salary} for newly created row. Row is determined as a newly created using #{row.EmployeeId}. If DBSequence value is negative this means that row is newly created and we set value for #{row.Salary}.

Let's say we create new row and provide values for all columns:

When Save button is pressed, new row is inserted into database. Value for Salary column is inserted as well:

When running sample application, don't forget to add adf-faces-impl.jar and jsf-impl.jar to application's WEB-INF\lib directory.

Wednesday, October 3, 2007

Conditional rendering of JSF fields based on dynamic af:selectOneChoice

My friend in her recent project was implementing conditional rendering of JSF fields based on dynamic af:selectOneChoice component, and she was in trouble with this. There exists excellent Grant Ronald blog post - Conditional rendering of JSF fields depending on a drop down list (af:selectOneChoice). However, Grant in his post describes conditional rendering of JSF fields depending on fixed drop down list, not dynamic. Together with my friend we have developed needed solution and I have decided to post it.

Sample application - is based on standard HR schema and provides one JSPX page called main.jspx. This page contains form component with navigation controls and functionality that allows to create new data and save changes in existing one. Application is focused on two form elements - DepartmentId and PhoneNumber. Functional requirement is not to show PhoneNumber element if IT is selected in DepartmentId drop down list.

Probably you will ask, what is the difference between fixed and dynamic drop down lists in conditional rendering. In fact it is similar, however you will need to add some Java code. Steps are the same like described in Grant Ronald blog I have mentioned, however implementation of some steps differs. Here I will describe differences.

At first you need to create dynamic drop down list for DepartmentId, this step is simple. In developed sample application for List Iterator is used DepartmentsView1Iterator, this iterator binds to DepartmentsView1 data control. We will need to access created drop down list to get selected value, to make it possible we have created table definition and binded it to the same DepartmentsView1Iterator iterator. Don't forget to enable AutoSubmit and set PartialTriggers on parent UI item.

PhoneNumber element property Rendered we have binded to a method available in page backing bean, this method is called - isPhoneNumberRendered(). Method code:

Code is straightforward but it allows to use dynamic drop down list in conditional rendering. In this code, DepartmentName is retrieved for selected element in drop down list, and it is compared with IT department. Depending on comparison result, true or false is returned and based on returned value component is rendered or no.

Here PhoneNumber is shown:

And when IT is selected for department, PhoneNumber is not shown. It will not be shown even if you will just open a page with IT department selected.

When running sample application, don't forget to add adf-faces-impl.jar and jsf-impl.jar to application's WEB-INF\lib directory.