Browsing "Older Posts"

APEX-AT-WORK no image

Dynamic file directories through javascript on page load

Von Tobias Arnhold → 8.03.2009
I fumble around with supporting objects to make my application as portable as possible without any manual scripting. One issue I had discovered had to do with static CSS and JS files provided by frameworks like Ext/YUI or JQuery. I just addressed them hard coded inside my template header:

<html lang="&BROWSER_LANGUAGE.">
<head>
#HEAD#
<title>#TITLE#</title>

<!-- --------------------------------------------------------------------------------- -->
<!-- cascading style sheet file allocation -->
<!-- --------------------------------------------------------------------------------- -->

<!-- apex css integration -->
<link rel="stylesheet" href="#IMAGE_PREFIX#themes/theme_7/theme_3_1.css" type="text/css" />
<!-- extjs css stylesheets -->
<link rel="stylesheet" type="text/css" href="/i/themes/ext-2.0.2/resources/css/ext-all.css" /> -->
<!-- extjs theme -->
<link rel="stylesheet" type="text/css" href="/i/themes/ext-2.0.2/resources/css/xtheme-slate.css" /> -->
<!-- tobias arnhold css integration for extjs -->
<link rel="stylesheet" type="text/css" href="#WORKSPACE_IMAGES#extjs_css_template.css" />
<!-- inidviual css formatatting -->
<!-- forces form to fit screen height -->
<style type="text/css"> #wwvFlowForm {width:100%; height:100%;} </style>

<!-- --------------------------------------------------------------------------------- -->
<!-- javascript file allocation -->
<!-- --------------------------------------------------------------------------------- -->

<!-- extjs js integration -->
<script type="text/javascript" src="/i/themes/ext-2.0.2/adapter/ext/ext-base.js"></script> -->
<script type="text/javascript" src="/i/themes/ext-2.0.2/ext-all.js"></script> -->
<script type="text/javascript" src="/i/themes/ext-2.0.2/ext-all-debug.js"></script> -->
<!-- json integration -->
<script type="text/javascript" src="#APP_IMAGES#json.js"></script>
<!-- global js variables -->
<script type="text/javascript"> var htmldb_Img_Dir = "/i/"; </script>
<!-- extjs template integration by Tobias Arnhold -->
<script type="text/javascript" src="#APP_IMAGES#extjs_js_template_no_tabs.js"></script>
<!-- Own js, css, libs for applciation -->
<script type="text/javascript" src="#APP_IMAGES#aaw_js.js"></script>

</head>
<body #ONLOAD#>
<!-- id="wwvFlowForm"> --> #FORM_OPEN#
...

If you download this application and use other file directories you would need to change all page headers by hand. So I thought how could I make all directories portable (saved inside the database) and automatically be loaded with an application process. I made two examples both worked perfectly with Firefox but IE 8 failed completely.

<!-- --------------------------------------------------------------------------------- -->
<!-- APEX Page Template for ExtJS - No Tabs -->
<!-- by Tobias Arnhold -->
<!-- --------------------------------------------------------------------------------- -->

<html lang="&BROWSER_LANGUAGE.">
<head>
#HEAD#
<title>#TITLE#</title>

<!-- --------------------------------------------------------------------------------- -->
<!-- set ExtJS source directory -->
<!-- --------------------------------------------------------------------------------- -->
<script type="text/javascript">
// set gloabl variables
var v_dir = "http://www.gwt-ext.com/ext/2.0.2";
var v_wi = "#WORKSPACE_IMAGES#";
var v_ai = "#APP_IMAGES#";
var CSS_ext_all;
var CSS_template;
var JS_ext_base;
var JS_ext_all;
var JS_ext_all_debug;
var JS_template;
var JS_aaw;

// add CSS
// add ext-all.css
var v_file= "/resources/css/ext-all.css";
var v_css = v_dir + v_file;
// set variable head
head=document.getElementsByTagName('HEAD')[0];
// next line removes the previously added StyleSheet
if (CSS_ext_all){ head.removeChild(CSS_ext_all); }
CSS_ext_all=document.createElement('LINK');
CSS_ext_all.rel='stylesheet';
CSS_ext_all.type='text/css';
CSS_ext_all.href=v_css;
head.appendChild(CSS_ext_all);

// add extjs_css_template.css
var v_file= "extjs_css_template.css";
var v_css = v_wi + v_file;
// set variable head
head=document.getElementsByTagName('HEAD')[0];
// next line removes the previously added StyleSheet
if (CSS_template){ head.removeChild(CSS_template); }
CSS_template=document.createElement('LINK');
CSS_template.rel='stylesheet';
CSS_template.type='text/css';
CSS_template.href=v_css;
head.appendChild(CSS_template);

// add JS
var v_file= "/adapter/ext/ext-base.js";
var v_js = v_dir + v_file;

// add ext-base.js
head=document.getElementsByTagName('HEAD')[0];

// next line removes the previously added External JavaScript
if (JS_ext_base){ head.removeChild(JS_ext_base); }
JS_ext_base=document.createElement('SCRIPT');
JS_ext_base.type='text/javascript';
JS_ext_base.src=v_js;
head.appendChild(JS_ext_base);

// add JS
// add ext-base.js
var v_file= "/adapter/ext/ext-base.js";
var v_js = v_dir + v_file;
head=document.getElementsByTagName('HEAD')[0];
// next line removes the previously added External JavaScript
if (JS_ext_base){ head.removeChild(JS_ext_base); }
JS_ext_base=document.createElement('SCRIPT');
JS_ext_base.type='text/javascript';
JS_ext_base.src=v_js;
head.appendChild(JS_ext_base);

// add ext-all.js
var v_file= "/ext-all.js";
var v_js = v_dir + v_file;
head=document.getElementsByTagName('HEAD')[0];
// next line removes the previously added External JavaScript
if (JS_ext_all){ head.removeChild(JS_ext_all); }
JS_ext_all=document.createElement('SCRIPT');
JS_ext_all.type='text/javascript';
JS_ext_all.src=v_js;
head.appendChild(JS_ext_all);

// add ext-all-debug.js
v_dir = "/i/themes/ext-2.0.2";
var v_file= "/ext-all-debug.js";
var v_js = v_dir + v_file;
head=document.getElementsByTagName('HEAD')[0];
// next line removes the previously added External JavaScript
if (JS_ext_all_debug){ head.removeChild(JS_ext_all_debug); }
JS_ext_all_debug=document.createElement('SCRIPT');
JS_ext_all_debug.type='text/javascript';
JS_ext_all_debug.src=v_js;
head.appendChild(JS_ext_all_debug);

// add extjs_js_template_no_tabs.js
var v_file= "extjs_js_template_no_tabs.js";
var v_js = v_ai + v_file;
head=document.getElementsByTagName('HEAD')[0];
// next line removes the previously added External JavaScript
if (JS_template){ head.removeChild(JS_template); }
JS_template=document.createElement('SCRIPT');
JS_template.type='text/javascript';
JS_template.src=v_js;
head.appendChild(JS_template);

// add aaw_js.js
var v_file= "aaw_js.js";
var v_js = v_ai + v_file;
head=document.getElementsByTagName('HEAD')[0];
// next line removes the previously added External JavaScript
if (JS_aaw){ head.removeChild(JS_aaw); }
JS_aaw=document.createElement('SCRIPT');
JS_aaw.type='text/javascript';
JS_aaw.src=v_js;
head.appendChild(JS_aaw);
</script>

<!-- --------------------------------------------------------------------------------- -->
<!-- cascading style sheet file allocation -->
<!-- --------------------------------------------------------------------------------- -->

<!-- apex css integration -->
<link rel="stylesheet" href="#IMAGE_PREFIX#themes/theme_7/theme_3_1.css" type="text/css" />

<!-- individual css formatting -->
<!-- forces form to fit screen height -->
<style type="text/css"> #wwvFlowForm {width:100%; height:100%;} </style>

<!-- --------------------------------------------------------------------------------- -->
<!-- javascript file allocation -->
<!-- --------------------------------------------------------------------------------- -->

<!-- json integration -->
<script type="text/javascript" src="#APP_IMAGES#json.js"></script>

<!-- global js variables -->
<script type="text/javascript"> var htmldb_Img_Dir = "/i/"; </script>

</head>
<body #ONLOAD#>
<!-- id="wwvFlowForm"> --> #FORM_OPEN#

And this example which should work with IE. It loads every scripts one by one with 5 seconds in between. If you are more interested take a look into the sources.

<!-- --------------------------------------------------------------------------------- -->
<!-- APEX Page Template for ExtJS - No Tabs -->
<!-- by Tobias Arnhold -->
<!-- Sources: -->
<!-- http://www.phpied.com/dynamic-script-and-style-elements-in-ie/ -->
<!-- http://forum.jswelt.de/javascript/46294-innerhtml-probleme-internet-explorer.html -->
<!-- http://www.phpied.com/javascript-include-ready-onload/ -->
<!-- http://www.phpied.com/javascript-include-ready/ -->
<!-- http://www.phpied.com/javascript-include-ready/#comment-22580 -->
<!-- http://www.javascriptkit.com/javatutors/navigator.shtml -->
<!-- --------------------------------------------------------------------------------- -->

<html lang="&BROWSER_LANGUAGE.">
<head>
#HEAD#
<title>#TITLE#</title>

<!-- --------------------------------------------------------------------------------- -->
<!-- set ExtJS source directory -->
<!-- --------------------------------------------------------------------------------- -->
<script type="text/javascript">
// set gloabl variables
var v_dir = "http://www.gwt-ext.com/ext/2.0.2";
var v_wi = "#WORKSPACE_IMAGES#";
var v_ai = "#APP_IMAGES#";
var CSS_ext_all;
var CSS_template;
var JS_ext_base;
var JS_ext_all;
var JS_ext_all_debug;
var JS_template;
var JS_aaw;

// check browser and start loading files
if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
var t1 = setTimeout("CSS_ext_all()",5000);
// var t2 = setTimeout("CSS_template()",5000);
// var t3 = setTimeout("JS_ext_base()",5000);
// var t4 = setTimeout("JS_ext_all()",5000);
// var t5 = setTimeout("JS_ext_all_debug()",5000);
// var t6 = setTimeout("JS_template()",5000);
// var t7 = setTimeout("JS_aaw()",5000);
}
else
{
var t1 = CSS_ext_all();
var t2 = CSS_template();
var t3 = JS_ext_base();
var t4 = JS_ext_all();
var t5 = JS_ext_all_debug();
var t6 = JS_template();
var t7 = JS_aaw();
}


// add CSS
function CSS_ext_all() {
// add ext-all.css
var v_file= "/resources/css/ext-all.css";
var v_css = v_dir + v_file;
var html_doc = document.getElementsByTagName('head')[0];
CSS_ext_all = document.createElement('link');
CSS_ext_all.setAttribute('rel', 'stylesheet');
CSS_ext_all.setAttribute('type', 'text/css');
CSS_ext_all.setAttribute('href', v_css);
html_doc.appendChild(CSS_ext_all);
CSS_ext_all.onreadystatechange = function () {
if (CSS_ext_all.readyState == 'complete'|| CSS_ext_all.readyState == 'loaded') {var t2 = setTimeout("CSS_template()",5000);}}
CSS_ext_all.onload = function () {null;}
return true;
}

function CSS_template() {
// add extjs_css_template.css
var v_file= "extjs_css_template.css";
var v_css = v_wi + v_file;
var html_doc = document.getElementsByTagName('head')[0];
CSS_template = document.createElement('link');
CSS_template.setAttribute('rel', 'stylesheet');
CSS_template.setAttribute('type', 'text/css');
CSS_template.setAttribute('href', v_css);
html_doc.appendChild(CSS_template);
CSS_template.onreadystatechange = function () {
if (CSS_template.readyState == 'complete'|| CSS_template.readyState == 'loaded') {var t3 = setTimeout("JS_ext_base()",5000);}}
CSS_template.onload = function () {null;}
return true;
}

// add JS
function JS_ext_base() {
// add ext-base.js
var v_file= "/adapter/ext/ext-base.js";
var v_js = v_dir + v_file;
var html_doc = document.getElementsByTagName('head')[0];
JS_ext_base = document.createElement('script');
JS_ext_base.setAttribute('type', 'text/javascript');
JS_ext_base.setAttribute('src', v_js);
html_doc.appendChild(JS_ext_base);
JS_ext_base.onreadystatechange = function () {
if (JS_ext_base.readyState == 'complete'|| JS_ext_base.readyState == 'loaded') {var t4 = setTimeout("JS_ext_all()",5000);}}
JS_ext_base.onload = function () {null;}
return true;
}
function JS_ext_all() {
// add ext-all.js
var v_file= "/ext-all.js";
var v_js = v_dir + v_file;
var html_doc = document.getElementsByTagName('head')[0];
JS_ext_all = document.createElement('script');
JS_ext_all.setAttribute('type', 'text/javascript');
JS_ext_all.setAttribute('src', v_js);
html_doc.appendChild(JS_ext_all);
JS_ext_all.onreadystatechange = function () {
if (JS_ext_all.readyState == 'complete'|| JS_ext_all.readyState == 'loaded') {var t5 = setTimeout("JS_ext_all_debug()",5000);}}
JS_ext_all.onload = function () {null;}
return true;
}
function JS_ext_all_debug() {
// add ext-all-debug.js
v_dir = "/i/themes/ext-2.0.2";
var v_file= "/ext-all-debug.js";
var v_js = v_dir + v_file;
var html_doc = document.getElementsByTagName('head')[0];
JS_ext_all_debug = document.createElement('script');
JS_ext_all_debug.setAttribute('type', 'text/javascript');
JS_ext_all_debug.setAttribute('src', v_js);
html_doc.appendChild(JS_ext_all_debug);
JS_ext_all_debug.onreadystatechange = function () {
if (JS_ext_all_debug.readyState == 'complete'|| JS_ext_all_debug.readyState == 'loaded') {var t6 = setTimeout("JS_template()",5000);}}
JS_ext_all_debug.onload = function () {null;}
return true;
}
function JS_template() {
// add extjs_js_template_no_tabs.js
var v_file= "extjs_js_template_no_tabs.js";
var v_js = v_ai + v_file;
var html_doc = document.getElementsByTagName('head')[0];
JS_template = document.createElement('script');
JS_template.setAttribute('type', 'text/javascript');
JS_template.setAttribute('src', v_js);
html_doc.appendChild(JS_template);
JS_template.onreadystatechange = function () {
if (JS_template.readyState == 'complete'|| JS_template.readyState == 'loaded') {var t7 = setTimeout("JS_aaw()",5000);}}
JS_template.onload = function () {null;}
return true;
}
function JS_aaw() {
// add aaw_js.js
var v_file= "aaw_js.js";
var v_js = v_ai + v_file;
var html_doc = document.getElementsByTagName('head')[0];
JS_aaw = document.createElement('script');
JS_aaw.setAttribute('type', 'text/javascript');
JS_aaw.setAttribute('src', v_js);
html_doc.appendChild(JS_aaw);
JS_aaw.onreadystatechange = function () {
if (JS_aaw.readyState == 'complete'|| JS_aaw.readyState == 'loaded') {null;}}
JS_aaw.onload = function () {null;}
return true;
}
</script>
<!-- --------------------------------------------------------------------------------- -->
<!-- cascading style sheet file allocation -->
<!-- --------------------------------------------------------------------------------- -->

<!-- apex css integration -->
<link rel="stylesheet" href="#IMAGE_PREFIX#themes/theme_7/theme_3_1.css" type="text/css" />

<!-- individual css formatting -->
<!-- forces form to fit screen height -->
<style type="text/css"> #wwvFlowForm {width:100%; height:100%;} </style>

<!-- --------------------------------------------------------------------------------- -->
<!-- javascript file allocation -->
<!-- --------------------------------------------------------------------------------- -->

<!-- json integration -->
<script type="text/javascript" src="#APP_IMAGES#json.js"></script>

<!-- global js variables -->
<script type="text/javascript"> var htmldb_Img_Dir = "/i/"; </script>

</head>
<body #ONLOAD#>
<!-- id="wwvFlowForm"> --> #FORM_OPEN#

IE errors:
Details zum Fehler auf der Webseite
Benutzer-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; InfoPath.2; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)
Zeitstempel: Mon, 3 Aug 2009 11:20:49 UTC
Meldung: 'null' ist Null oder kein Objekt
Zeile: 13
Zeichen: 707
Code: 0
URI: http://:8080/i/themes/ext-2.0.2/ext-all.js

Meldung: 'null' ist Null oder kein Objekt
Zeile: 1555
Zeichen: 13
Code: 0
URI: http://:8080/i/themes/ext-2.0.2/ext-all-debug.js

Interesting behavior in example two: When I reload the page after I got these errors it works but when I then click onto another leaf IE crashes completely. For now I have enough...

Issue with packed app and javascript files (text/x-c)

Von Tobias Arnhold → 7.10.2009
I had the pleasure to find either an APEX bug or to find out that I'm unable to create packed applications! :O

After I installed my example application from http://apex.oracle.com/ on my local machine. I got a strange error after I edited an automatic installed javascript file:
The resource from this URL is not text: http://#SERVER_NAME#:8080/apex/wwv_flow_file_mgr.get_file?p_security_group_id=4257722764435732&p_flow_id=12000&p_fname=json.js



I checked the file again and found out that the "mime type" changed to: text/x-c
Normally it is: text/x-js

I uploaded/replaced a couple of installed javascript files to show you the difference:

All installed javascript files got this new mime type and they all worked properly until I changed something inside these files (in APEX).
As you see html and sql files got the right mime type even after the import.

Is this a known issue? Did I export and import something wrong?

I use the newest version of APEX 3.2 inside a XE database.
APEX-AT-WORK no image

DBMS_SCHEDULER examples

Von Tobias Arnhold → 6.25.2009
May be interesting to some of you which haven't had the time testing and working with the DBMS_SCHEDULER. I collected some examples to show what is possible with that amazing tool.

DBMS_SCHEDULER is an internal Oracle package (since Version 10g) which provides database driven jobs.
It's divided into 3 parts:
  • Time schedule part - dbms_scheduler.create_schedule
  • Program declaration part - dbms_scheduler.create_program
  • Job (conflation) part -dbms_scheduler.create_job
Examples of the dbms_scheduler.create_schedule part:

begin
-- daily from Monday to Sunday at 22:00 (10:00 p.m.)
dbms_scheduler.create_schedule
(schedule_name => 'INTERVAL_DAILY_2200',
start_date=> trunc(sysdate)+18/24, -- start today 18:00 (06:00 p.m.)
repeat_interval=> 'FREQ=DAILY; BYDAY=MON,TUE,WED,THU,FRI,SAT,SUN; BYHOUR=22;',
comments=>'Runtime: Every day (Mon-Sun) at 22:00 o'clock');

-- run every hour, every day
dbms_scheduler.create_schedule(
schedule_name => 'INTERVAL_EVERY_HOUR',
start_date => trunc(sysdate)+18/24,
repeat_interval => 'freq=HOURLY;interval=1',
comments => 'Runtime: Every day every hour');

-- run every 5 minute, every day
dbms_scheduler.create_schedule(
schedule_name => 'INTERVAL_EVERY_5_MINUTES',
start_date => trunc(sysdate)+18/24,
repeat_interval => 'freq=MINUTELY;interval=5',
comments => 'Runtime: Every day all 5 minutes');

-- run every minute, every day
dbms_scheduler.create_schedule(
schedule_name => 'INTERVAL_EVERY_MINUTE',
start_date => trunc(sysdate)+18/24,
repeat_interval => 'freq=MINUTELY;interval=1',
comments => 'Runtime: Every day every minute');

-- run every Sunday at 18:00 (06:00 p.m.)
dbms_scheduler.create_schedule
(schedule_name => 'INTERVAL_EVERY_SUN_1800',
start_date=> trunc(sysdate)+18/24,
repeat_interval=> 'FREQ=DAILY; BYDAY=SUN; BYHOUR=18;',
comments=>'Runtime: Run at 6pm every Sunday');
end;

Example of the dbms_scheduler.create_program part:

begin
-- Call a procedure of a database package
dbms_scheduler.create_program
(program_name=> 'PROG_COLLECT_SESS_DATA',
program_type=> 'STORED_PROCEDURE',
program_action=> 'pkg_collect_data.prc_session_data',
enabled=>true,
comments=>'Procedure to collect session information'
);
end;

Example of the dbms_scheduler.create_job part:

begin
-- Connect both dbms_scheduler parts by creating the final job
dbms_scheduler.create_job
(job_name => 'JOB_COLLECT_SESS_DATA',
program_name=> 'PROG_COLLECT_SESS_DATA',
schedule_name=>'INTERVAL_EVERY_5_MINUTES',
enabled=>true,
auto_drop=>false,
comments=>'Job to collect data about session values every 5 minutes');
end;

Examples to change dbms_scheduler settings:

begin
-- change start time
DBMS_SCHEDULER.SET_ATTRIBUTE(
name => 'INTERVAL_EVERY_5_MINUTES',
attribute => 'start_date',
value => to_date('22.06.2009 12:15','dd.mm.yyyy hh24:mi')
);

-- change repeat interval
DBMS_SCHEDULER.SET_ATTRIBUTE(
name => 'INTERVAL_EVERY_MINUTE',
attribute => 'repeat_interval',
value => 'freq=MINUTELY;interval=2'
);
end;

Example to run job immediate:

begin
dbms_scheduler.run_job('JOB_COLLECT_SESS_DATA',TRUE);
end;

Example to restart job:

begin
dbms_scheduler.disable('JOB_COLLECT_INST_INFO');
dbms_scheduler.enable('JOB_COLLECT_INST_INFO');
end;

Select job status:

-- All jobs
select * from user_scheduler_jobs;

-- Get information to job
select * from user_scheduler_job_log order by log_date desc;

-- Show details on job run
select * from user_scheduler_job_run_details;


Further information about the DBMS_SCHEDULER:
http://psoug.org/reference/OLD/dbms_scheduler.html
Oracle documentation about the DBMS_SCHEDULER

These scripts are tested in an Oracle XE environment (10.2.0.1).
I will extend this post whenever I need new scripts.

Update 11.09.2010:

Run a job without program and schedule plan (all in one command):

dbms_scheduler.create_job (
job_name => 'TEST_JOB',
job_type => 'PLSQL_BLOCK',
job_action => 'begin /* some process code */ commit; end;',
number_of_arguments => 0,
start_date => sysdate +1/24/59, -- sysdate + 1 minute
job_class => 'ADMIN', -- Priority Group
enabled => TRUE,
auto_drop => TRUE,
comments => 'Testrun');


@Sue
Dynamic Scheduled jobs from inside APEX are no problem. But be careful if you use "execute immediate"!
APEX-AT-WORK no image

ExtJS navigation tree

Von Tobias Arnhold → 6.19.2009
Hi folks,

I added an ExtJS navigation tree to my example application. To get the JSON data out of the database I created a small package which is dynamically creating this data string on every page load.

Take a look at the updated source code: AAW - ExtJS navigation tree

I got some request about the application installation file (application source code). So I decided to publish it to everybody how asks for it via email: tobias-arnhold@hotmail.de
I would use the same procedure as Denes does. You get an developer account and can download the current version yourself.

PS, feedback is always welcome! :D