Sunday, April 29, 2007

Invoking Create method programmatically

Wizards are cool, but I'm sure that one day you will need to remember the roots and add some code by hand. Just don't afraid this, it could be even simpler than using wizards. In this sample I will explain how you could develop Create form without (or may be almost without ;) using JDeveloper wizards. Described principles can be applied in the same way for other CRUD type operations.

Provided sample application - CreateMethod.zip is based on standard HR schema, two tables are used - COUNTRIES and REGIONS. First table is used for Create operation, second is a source for a LOV component. So, developed application can be used to insert countries data into a table from HR schema.

While developing Create form, at first I have used simple drag and drop method to create two af:inputText and one af:selectOneChoice components. Those components were created without binding to Data Control. After that I have declared in page definition file three variables and generated attributeValue elements for them. When described steps were done, values of components available in JSPX page were binded to elements defined in page definition file. For example, for Country ID value binding is equal to: #{bindings.countryIdAttr.inputValue}, where countryIdAttr is generated attributeValue element. Page definition file structure:


When components and page definition were created, I have developed create method code in Application Module class. Method code is rather simple, it acquires definition for Countries entity and opens transaction. After that, new instance of Countries entity is initialized by values submited from ADF Faces components available in JSPX page. If there is no exceptions, data for new row is commited to the database. Create method code:


When method code is created, don't forget to add method signature into Application Module client interface. This will allow to call created method from JSPX page.

And, my last step was to drag and drop createCountry(String, String, Number) from Data Controls palette to af:panelForm footer facet. Method parameters should be binded to variables defined in page definition file. Data Controls palette for this sample:


af:panelForm component contains two af:inputText, one af:selectOneChoice and one af:commandButton:


Finally, Create form in action:


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

Leaving TietoEnator, joining IBM

There are some news from me - I'm leaving TietoEnator and joining IBM. I will work for IBM Global Business Services in J2EE Technical Leader position. My home office will be located in Vilnius, but I'll be traveling a lot - that's cool!

This move will not affect my blogging activity in any way. I'm happy that you like to read my blog, thanks! ;-)

Sunday, April 22, 2007

Oracle Spatial and TopLink Essentials JPA

It seems Oracle Spatial functionality can be used successfully with TopLink Essentials JPA also. I have reviewed in detail Doug Clarke (Principal Product Manager for Oracle TopLink) post about how it looks in theory - Oracle Spatial using TopLink Essentials JPA. And, have implemented described steps in practice. I have faced some issues, but final result is successful, I will describe below how I have created sample application for today post - SpatialTopLinkJPA.zip.

Sample application is based on standard schema - MVDEMO, schema contains tables with spatial columns. I'm using CITIES table, this table contains spatial column - LOCATION, column have MDSYS.SDO_GEOMETRY type assigned.

I have passed all three steps described in Doug blog without any problems. I have modified class for mapping customization - name for mapping attribute was changed. Also, I have changed named query definition a little bit - just to adjust it to Cities entity. Of course, you should not forget to change in Cities entity, type for location attribute from String to oracle.spatial.geometry.JGeometry. After that, I have generated Session bean and added a method similar to presented in Doug blog:


The differences are only such, that I'm passing arguments dynamically and returning result using List type. Cities.sampleQuery executes MDSYS.SDO_RELATE spatial operator.

Ok, now we can test implemented Model layer. Everything should be ok, but Oracle JDeveloper 10.1.3.2 gives error when trying to run created sample application:


Upss..., this is quite strange - class defined in persistence.xml configuration file can't be loaded. But, it is possible to solve everything - I have found Issue #: 2432 on glassfish project page, it seems this issue is directly related to my problem and it is solved in Build 37. I have downloaded glassfish JAR file from project download page. I have overwrited TopLink Essentials JPA JAR files available in jdevstudio10132\toplink\jlib directory with Build 37 JAR files. After that I have restarted Oracle JDeveloper 10.1.3.2 - and I got it, there are no errors anymore.

Additionally, I have developed View layer using Oracle ADF Faces components. In View layer it is possible to provide Xmin, Ymin, Xmax and Ymax values, according to provided values Cities data will spatially filtered and returned into table.

Now I will show how it works. At first, we need to know MBR (Minimal-Bounding-Rectangle) of data stored in CITIES table. It is possible to calculate MBR using MDSYS.SDO_AGGR_MBR function. I have executed this function in SQLPlus, also COUNT(*) on CITIES is executed - there are 195 rows in CITIES table:


It is time to start-up OC4J and test application from browser. Here I'm testing with rectangle, whose dimensions are bigger than MBR dimensions - all 195 rows are returned:


Now I have defined smaller window to show how spatial filter works - only 31 rows are returned:


So, there should not be any problems to use spatial functionality in TopLink Essentials JPA. And, this or similar support will be available in the next release of Oracle TopLink, as it is mentioned in Doug Clarke blog post.

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

Sunday, April 15, 2007

Oracle Maps portlet in Oracle WebCenter

Oracle WebCenter is a framework, that allows using standard portlets in your Oracle ADF application. Oracle Maps product is a part of Oracle MapViewer, Oracle Maps functionality can be used by provided JavaScript API. It was interesting for me - how it is possible to integrate both? I mean - develop portlet with Oracle Maps functionality and integrate it into Oracle ADF application JSPX page. It seems, this is possible and it works perfectly. So, with Oracle WebCenter you can use spatially enabled portlets directly in Oracle ADF. Download developed sample - MapViewerPortlet.zip.

If you are new to Oracle Maps, it would be helpful to review my previous post - JavaScript in ADF Faces - Oracle Maps. For this sample is used the same spatial datasource - MVDEMO. However, instead of Oracle MapViewer Quickstart Kit, I'm using mapviewer.ear application deployed to WebCenter Preconfigured OC4J. Everything you may need for developing spatially enabled applications can be downloaded from OTN. Detailed information about how to use Oracle WebCenter framework you can find in Oracle WebCenter Framework Tutorial.

Oracle Maps functionality is implemented in portlet view.jsp file using JavaScript code. In view.jsp Oracle Maps JavaScript API file is included, style for map window and it's ID is defined, and lastly map creation code is provided. When those steps are done, developed portlet is integrated and created on map.jspx in standard way, like any other portlet used in Oracle WebCenter framework. Oracle Maps API used in this sample is really simple:


When deploying and running developed application, you should carefully follow steps described in Oracle WebCenter Framework Tutorial - 9 Deploying Your WebCenter Application.

Developed spatial portlet used in Oracle ADF should look similar:


It is possible to refresh or hide it. This functionality is provided by Oracle WebCenter framework.

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

Monday, April 9, 2007

Create, Edit and Delete operations in ADF Faces af:table component

I have received questions for my previous post - Creating new row using CreateInsert operation, about how to extend described sample with Edit functionality and how to make table read-only. I have extended published sample and want to describe updated functionality in this post.

Datasource and business logic are used the same as before. New features of extended sample - EditableTable.zip:
  1. Table is read-only, however newly created row is shown in edit mode
  2. Editing for selected row is enabled
  3. Delete operation is added
To make existing rows read-only and newly created row editable until save, you must change ReadOnly property value for each af:inputText component contained in af:column. Set ReadOnly property value to - #{row.JobId != null}. This means, if row isn't empty it will be displayed as read-only. In other case, if row is empty it will be displayed as editable:


After 'Save' button is pressed, newly entered row is stored in the database:


Second feature - selected row editing. To enable row editing I have used technique described in Frank Nimphius's blog - ADF Faces: Conditionally disabling an af:tableSelectOne row for selection. You should create ActionListener for Edit button, created ActionListener will store selected row ID into managed bean atttribute - enableEditing. Managed bean method code for enableEditing attribute, this code compares current row with selected row:


For each af:inputText component contained in af:column, change ReadOnly property value to #{row.JobId != null && !valueHolder.enableEditing}. Edit functionality:


Delete operation is developed by making simple drag-and-drop from Data Controls pallete to ADF Faces af:table component.


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

Sunday, April 1, 2007

Oracle Day'07 in Vilnius

This week I was participating in local Oracle Day event. This event was organized by local Oracle Corporation office on March 27. Event statistics - 43 sessions and 700 participants. Parallel sessions were divided into three categories - Oracle applications, Oracle technologies and Oracle partners.


My presentation title was - "Oracle JDeveloper and Oracle ADF: deeper sight". During the presentation I have talked about Oracle JDeveloper functionality and about Oracle ADF features. The main focus was to show for the auditory how it is simple to use Oracle ADF, I have described steps needed to create standard CRUD type WEB application. I should say, presentation has received quite big attention - there was something about 100 people auditory. Presentation title slide - "Oracle JDeveloper and Oracle ADF: deeper sight":


As it was mentioned, I have described steps needed when using Oracle ADF. Described steps were:
  1. Entity objects development
  2. Use Case implementation - View objects and Application Module
  3. Developed Application Module testing
  4. Business logic implementation - adding data validation functionality to Entity object
  5. View layer development using Oracle ADF Faces
  6. Application running using Oracle JDeveloper embedded OC4J
Those steps were described based on developed sample application - OracleDayDemo.zip. Sample is based on standard HR schema and use two tables - JOBS and EMPLOYEES. It implements two Entity objects, two View objects and one ApplicationModule. All Business Components are developed using Oracle JDeveloper Business Components diagram. In View layer three pages are created - viewJobs.jspx, editJob.jspx and viewEmployees.jspx. Business Components structure for developed sample:


Page flow diagram - available pages and navigation cases between them:


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