Saturday, January 13, 2007

Oracle Maps and ADF Faces af:table component

In this post I will describe how to develop spatially enabled data table using Oracle ADF. If you are new to Oracle Maps and want to know more about this product, you could check my previous post - JavaScript in ADF Faces - Oracle Maps, where I'm describing how to configure Oracle Maps and develop simple spatial application using Oracle ADF, also you will find links to external resources.

Business logic of developed sample - OraMapsWithTable.zip, is to provide a possibility of browsing through a table with cities data and to show selected city on the map. For the data source is used CITIES table from MVDEMO schema. Geometry theme for the CITIES table is declared using Oracle MapBuilder product. Oracle MapViewer, Oracle MapBuilder, MVDEMO schema and other spatial products you can download from - OTN. In the application Model layer EJB and TopLink are used, and ADF Faces components in the View layer.

Ok, if you have successfully deployed and configured MVDEMO schema, Oracle MapViewer and Oracle MapBuidler, it is time to describe how I have developed this sample application.

As you may notice, I'm using cities data, however cities geometry theme declaration doesn't come with MVDEMO. So, we need to declare it. You can declare it in the less than a minute, just use Oracle MapBuilder tool. There are two main things you should define, when declaring geometry theme for cities - hidden info field and query condition. In the hidden info field you should define all fields you want to show in pop-up window when city's point on the map will be clicked. In the query condition, data selection criteria is defined. More information on this topic is available in MapViewer User's Guide section - 8.3.1 Theme-Based FOI Layers. Shortly, cities geometry theme declaration for this application should look like this:


Application Model layer is generated using JDeveloper wizards, and there is no any custom code added. However, I have deleted default session definition and created - oramaps session definition with data source location pointed to jdbc/OraMapsDS data source.

Application View layer contains cities table and map image. Cities table row selection is implemented using af:commandLink component for #{row.city} field. Partial submit is enabled on af:commandLink and partial trigger points to af:panelHorizontal that contains map image. There is no any action or action listener defined on #{row.city} field, for map image update is used JavaScript onclick functionality onclick="showCity(#{row.rank90})". You should notice, that in ADF Faces it is possible to pass value from binding expression, as JavaScript function parameter. showCity(param) function is used to display selected city, function logic is implemented using JavaScript Oracle Maps API. Function source:


I have tested this sample on standalone Oracle Application Server (deployment profile is included into application workspace). Finally, we have a table and a map:


Let's say, we select Milwaukee city in the cities table, then similar map will be displayed:


So, what is better - to have a table or to have spatially enabled table? ;-)

7 comments:

Anonymous said...

Hi Andrejus,

Great example.
I did something similar but not with parameterized query. Instead I wrote custom method into Application Module service with Spatial functions.
Your example is more elegant and simpler to intergrate.

Branislav

Andrej Baranovskij said...

Hi Branislav,

Thanks for feedback!

Andrejus

kteckfun said...

hi.

I follow the example from above
however i had problem running it. I manage to configure the mvdemo database, but when i run the page, it is able to show the tables populated with cities, but there is nothing shown on the map on the right hand side. I check the log file, there is no error, only got

TopLink Info]: 2007.05.02 09:25:06.250--ServerSession(25033969)--TopLink, version: Oracle TopLink - 10g Release 3 (10.1.3.1.0) (Build 061004)
[TopLink Info]: 2007.05.02 09:25:07.109--ServerSession(25033969)--oramaps login successful

What could be wrong?

Thanks for any help

Andrej Baranovskij said...

Hi,

You should run application from the same server where Oracle MapViewer is deployed. It is not possible (ok, it's possible with some hacking :), just browse Spatial forum on OTN) to have Oracle MapViewer on one server and application with Oracle Maps functionality on another. This is related to JavaScript security issues.

I guess, in your case, you have deployed Oracle MapViewer on Application Server and you are running sample application on JDeveloper embedded OC4J.

Regards,
Andrejus

Anonymous said...

These comments have been invaluable to me as is this whole site. I thank you for your comment.

BB said...

Hi,

I am new to Oracle MapViewer, JDeveloper, and even Java. I need put up a spatially enabled table similar what you did.

I've installed JDeveloper 10.1.3.2 and Oracle JDeveloper 10g Extensions for MapViewer as instructed in the readme.txt file from the download zip file. When I open JDeveloper, I've got the following error. Do you have any insight?

C:\jdevstudio10132\jdev\lib\ext\mvconnection.jar
Severe(2,402): No class def found for addin jdevextensions.spatial.connections.AddConnection
Severe(2,468): No class def found for addin jdevextensions.spatial.connections.UpdateConnection
Severe(2,535): No class def found for addin jdevextensions.spatial.connections.RefreshConnection
Severe(2,606): No class def found for addin jdevextensions.spatial.connections.AddConnectionInFolder
Warning(0,0): This extension was written for a previous version of {0} and may not run properly.
Warning(0,0): To switch off these warnings, set the system property ide.extension.legacy.nowarn=true.
Warning(0,0): To disable all incompatible extensions, set the system property ide.extension.legacy.disabled=true.
C:\jdevstudio10132\jdev\lib\ext\mvpalette.jar
Severe(2,368): No class def found for addin oracle.lbs.jdevaddin.MapViewerPaletteAddin
Warning(0,0): This extension was written for a previous version of {0} and may not run properly.
Warning(0,0): To switch off these warnings, set the system property ide.extension.legacy.nowarn=true.
Warning(0,0): To disable all incompatible extensions, set the system property ide.extension.legacy.disabled=true.

Thanks,
BB

Andrej Baranovskij said...

Hi,

Those extensions are supported only for older Oracle JDeveloper release. I have developed this sample, without those extensions, just with standard Oracle JDeveloper.

Regards,
Andrejus