Saturday, January 6, 2007

JavaScript in ADF Faces - Oracle Maps

Inspired by Jeroen van Schaijk article, I have developed simple application with Oracle Maps functionality, that shows how it is easy to use JavaScript in ADF Faces JSPX page. OraMapsSimple.zip, is developed using steps described in tutorial supplied with Oracle Maps. To develop this application, I have used spatial MVDEMO datasource and Oracle MapViewer 10.1.3.1 Quickstart kit, both available on OTN.

Spatial datasource comes with detailed instructions and there was no problem to install it on my Oracle XE (XE supports spatial functionality). When you start Quickstart kit for the first time, Oracle MapViewer deployment process is completed automatically. You can find instructions in Quickstart readme file about how to open Oracle MapViewer homepage and then according to the tutorial - Learning Oracle Maps by Example (it comes with Oracle MapViewer), configure Oracle Maps settings.

So, what about JavaScript? Oracle Maps functionality is reached from JavaScript code, so we need to place a portion of JavaScript somewhere between ADF Faces components. It is quite easy, just include div element for map image and surround it using f:verbatim tag. Script for displaying a map is straightforward (do not forget to include oraclemaps.js, this script comes with Oracle MapViewer).


And, finally we have a map, that displays population density by counties:


With sample application comes deployment profile, which you can use if deploying to Oracle Application Server.

20 comments:

B. Fischer-Wasels said...

Hi Andrej,
as an oracle-maps enthusiast (oracle-maps.blogspot.com) and I tried ur simple example with ADF just incorporating the map and got this error in JDeveloper 10.1.3.1:
java.lang.NullPointerException at javax.faces.webapp.FacesServlet.init(FacesServlet.java:165)
- admittedly I am not a Java guy (rather pl/sql) - what went wrong ?
Any hint wud help.
TIA
Bernhard

B. Fischer-Wasels said...

Andrej,
I solved the error by installing the JSP Tag Lib as indicated as a remark in four of the first lines.
Bernhard

Andrejus Baranovskis said...

Hi Bernhard,
Most probably you have faced this problem, because standard adf-faces-impl.jar and jsf-impl.jar were not available in JDeveloper project lib directory by default. I'm simply removing those libraries when posting samples on the blog, in order to reduce zip archive size. How to add those libraries:

adf-faces-impl.jar should be copied from C:\JDeveloper\jlib to ApplicationName\UserInterface\public_html\
WEB-INF\lib

jsf-impl.jar should be copied from C:\JDeveloper\jsf-ri to C:\JDeveloper\jlib to ApplicationName\UserInterface\public_html\
WEB-INF\lib

If you will have more questions, please post a comment or drop an email. I will be glad to answer.

Thanks,
Andrejus

Anonymous said...

Hello,
when I run the page I get no output at all , neither any error messages.

Andrejus Baranovskis 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

Francisco said...

Hi Andrej,
Is it possible to run this application with a standalone Mapviewer, I mean, like the Faces example that comes with Oracle Mapviewer? I am able to run the sample application on JDeveloper embedded OC4J, but of course, no map is rendered as Mapviewer is not in the same server...

Andrejus Baranovskis said...

Hi Francisco,

Yes, it is possible. You just should use Quickstart kit for MapViewer. It comes with standalone OC4J, this means you can deploy on it your application.

Regards,
Andrejus

Sergey said...

Andrejus,
thank you very much for you useful blog.
I am tried run Oracle MapViewer on one server and application with Oracle Maps functionality on JDeveloper embedded OC4J. I could not achieve success. What did you mean "This is related to JavaScript security issues." Maybe I should special configure OC4J with MapViewer?
Thank you very much.
Sergey Malinin.

Andrejus Baranovskis said...

Hi Sergey,

You can run Oracle Maps application only on the same server where Oracle MapViewer is deployed. Oracle Maps functionality is implemented with JavaScript, its not possible to access server side Oracle MapViewer, deployed on separate server.

Regards,
Andrejus

suman said...

I am trying to run the mvdemo.dmp for exporting data and i am getting the folowing warning

The statement i used to run this dmp is
imp ora04110/ora04110@qa4a file=demo/mvdemo.dmp full=y ignore=y
Is there any other way i can run the mapViewer on any other database which has by default all the data?

Warning: the objects were exported by MVDEMO, not by you

import done in WE8MSWIN1252 character set and AL16UTF16 NCHAR character set
import server uses AL32UTF8 character set (possible charset conversion)
export client uses US7ASCII character set (possible charset conversion)
. importing MVDEMO's objects into ORA04110
. importing MVDEMO's objects into ORA04110
IMP-00060: Warning: Skipping table "ORA04110"."STYLES" because object type "MDSYS"."SDO_GEOMETRY" does not exist or has
different identifier
IMP-00017: following statement failed with ORACLE error 1950:
"CREATE TABLE "THEMES" ("NAME" VARCHAR2(32) NOT NULL ENABLE, "DESCRIPTION" V"
"ARCHAR2(4000), "BASE_TABLE" VARCHAR2(32) NOT NULL ENABLE, "GEOMETRY_COLUMN""
" VARCHAR2(2048) NOT NULL ENABLE, "STYLING_RULES" CLOB) PCTFREE 10 PCTUSED "
"40 INITRANS 1 MAXTRANS 255 STORAGE(INITIAL 16384 FREELISTS 1 FREELIST GROUP"
"S 1) TABLESPACE "SYSTEM" LOGGING LOB ("STYLING_RULES") STORE AS (TABLESPAC"
"E "SYSTEM" ENABLE STORAGE IN ROW CHUNK 8192 PCTVERSION 10 NOCACHE STORAGE("
"INITIAL 24576 FREELISTS 1 FREELIST GROUPS 1))"
IMP-00003: ORACLE error 1950 encountered
ORA-01950: no privileges on tablespace 'SYSTEM'
IMP-00017: following statement failed with ORACLE error 1950:
"CREATE TABLE "MAPS" ("NAME" VARCHAR2(32) NOT NULL ENABLE, "DESCRIPTION" VAR"
"CHAR2(4000), "DEFINITION" CLOB) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS "
"255 STORAGE(INITIAL 16384 FREELISTS 1 FREELIST GROUPS 1) TABLESPACE "SYSTEM"
"" LOGGING LOB ("DEFINITION") STORE AS (TABLESPACE "SYSTEM" ENABLE STORAGE "
"IN ROW CHUNK 8192 PCTVERSION 10 NOCACHE STORAGE(INITIAL 24576 FREELISTS 1 "
"FREELIST GROUPS 1))"
IMP-00003: ORACLE error 1950 encountered
ORA-01950: no privileges on tablespace 'SYSTEM'
IMP-00060: Warning: Skipping table "ORA04110"."CITIES" because object type "MDSYS"."SDO_GEOMETRY" does not exist or has
different identifier
IMP-00060: Warning: Skipping table "ORA04110"."COUNTIES" because object type "MDSYS"."SDO_GEOMETRY" does not exist or h
as different identifier
. . importing table "EMPLOYEES" 14 rows imported
IMP-00060: Warning: Skipping table "ORA04110"."INTERSTATES" because object type "MDSYS"."SDO_GEOMETRY" does not exist o
r has different identifier
IMP-00060: Warning: Skipping table "ORA04110"."STATES" because object type "MDSYS"."SDO_GEOMETRY" does not exist or has
different identifier
IMP-00060: Warning: Skipping table "ORA04110"."TERRITORIES" because object type "MDSYS"."SDO_GEOMETRY" does not exist o
r has different identifier
. . importing table "TERR_COUNTIES" 3230 rows imported
IMP-00017: following statement failed with ORACLE error 942:
"ANALYZE TABLE "CITIES" ESTIMATE STATISTICS "
IMP-00003: ORACLE error 942 encountered
ORA-00942: table or view does not exist
IMP-00017: following statement failed with ORACLE error 942:
"ANALYZE TABLE "COUNTIES" ESTIMATE STATISTICS "
IMP-00003: ORACLE error 942 encountered
ORA-00942: table or view does not exist
IMP-00017: following statement failed with ORACLE error 942:
"ANALYZE TABLE "INTERSTATES" ESTIMATE STATISTICS "
IMP-00003: ORACLE error 942 encountered
ORA-00942: table or view does not exist
IMP-00017: following statement failed with ORACLE error 942:
"ANALYZE TABLE "STATES" ESTIMATE STATISTICS "
IMP-00003: ORACLE error 942 encountered
ORA-00942: table or view does not exist
IMP-00017: following statement failed with ORACLE error 942:

Andrejus Baranovskis said...

Hi,

Your database should have MDSYS schema installed. This schema comes with Oracle XE database. Basically, you need to have Oracle Locator package in your database.

Regards,
Andrejus

Anonymous said...

Hi,
I did everythig you said and deployed in standalone OC4J that contains mapviewer but now i can't figure out which URL to use to run application

Thnx in advance,
Alexandra

Andrejus Baranovskis said...

Hi Alexandra,

You can open OraMapsSimple.deploy file in JDeveloper, in General section under J2EE Web Context Root there is specified - oramapsimple.

Complete URL will be: http://host:port/oramapsimple/faces/map.jspx

Regards,
Andrejus

NJ said...

Hello Andrejus,

I am getting the same error while importing MVDEMO.dmp as Suman has reported in his comments.

IMP-00060: Warning: Skipping table "ORA04110"."CITIES" because object type "MDSYS"."SDO_GEOMETRY" does not exist or has different identifier.

I have verified that the MDSYS schema exists in the database and i can describe SDO_GEOMETRY type.

Also, i am able to create a table which has a spatial column (using SDO_GEOMETRY). Not sure why the import does not work and throws the error on SDO_GEOMETRY.

I am on database 11g.

Any help in this regard is much appreciated.

Thanks,
Nitin

Andrejus Baranovskis said...

Hi,

It can be something specific to 11g, I suggest to check on OTN forum for Spatial group.

Regards,
Andrejus

Richard said...

Hi
I'm having the same issue as Nitin (two comments above). I'm also on 11g. I couldn't find anything related to this on the Spatial forum so have posted there as well.

If anyone has successfully imported the mvdemo.dmp file into an 11g database then please let us know!

Cheers
Richard

Richard said...

I got a reply from the OTM Forum regarding the 11g installation problem. The answer is to disable validation on the SDO types by setting parameters on the 'imp' command line:

imp .... file=mvdemo.dmp TOID_NOVALIDATE=MDSYS.SDO_GEOMETRY,MDSYS.SDO_ELEM_INFO_ARRAY,MDSYS.SDO_ORDINATE_ARRAY

It worked for me.
(Thanks to Siva)
http://forums.oracle.com/forums/thread.jspa?messageID=3346532#3346532

Entertainer said...

Hi Andrejus,

Good see your posts. I wanted to get world map. How one can create spatial data for world map.

Also explain me with querying non spatial data when I click a particular place.

Awaiting for your response.

muload26@gmail.com

thanks in advance.

Daisy said...

Hi Andrejus,

For oracle ADF geographic maps how can I use javascript to draw a line between two points ... or

Andrejus Baranovskis said...

I would need to test this Daisy, no immediate answer.

Andrejus