Showing posts with label APEX. Show all posts
Showing posts with label APEX. Show all posts

Wednesday, October 23, 2013

Using Fancybox in Oracle APEX

In Oracle APEX, showing master-details, or drilldown data can be achieved by using two pages: one for the master data, and using a link to pass the key value to the opening page.  Depends on the volume of presenting data , the opening page can be:
A lot of data: a complete page
Moderate amount of data: a popup page
Just a couple of data: a Fancybox page
In here I show these three page types and you can compare which one is best-fit for your situation.

Tables: EBA_DEMO_MD_DEPT and EBA_DEMO_MD_EMP (the data is the same as in tables DEPT and EMP in schema SCOTT)

Master Page
Department Name with employee count for each department.  The opening page is the list of employee for each department, which is invoked from the link in the employee count column.

SQL Query:
select A.DEPTNO
     , initcap(A.DNAME) DNAME
     , initcap(A.LOC) LOC
     , B.EMP_COUNT
  from EBA_DEMO_MD_DEPT A
     , (SELECT COUNT(*) EMP_COUNT
             , DEPTNO 
          FROM EBA_DEMO_MD_EMP
         GROUP BY DEPTNO) B
 where A.DEPTNO=B.DEPTNO
ORDER BY DNAME



Opening Page
Employees list for a given department. This page contains a hidden item P11_DEPTNO
SQL Query:
SELECT A.EMPNO 
     , initcap(A.ENAME) ENAME
     , initcap(A.JOB) JOB
     , initcap(B.ENAME) MANAGER
     , A.HIREDATE 
     , A.SAL 
     , A.COMM
FROM EBA_DEMO_MD_EMP A
   , EBA_DEMO_MD_EMP B
where A.DEPTNO=:P11_DEPTNO
  AND A.MGR=B.EMPNO(+)
order by ENAME


Two-Page Setup
Using Column Link is the most standard way of linking two pages.  In our case, the column EMP_COUNT in the master page is linked to the opening page by passing the DEPTNO value.

The opening page is a standard, stand-alone page.


Popup Page Setup
To make this opening page as a popup (a new browser window), first you have to change the page template of the opening page to "Popup".

Next, the column link is changed to URL, and using the built-in Javascript function popUp2([link], [width],[height]) to construct the URL of the opening page:  
javascript:popUp2('f?p=&APP_ID.:11:&SESSION.::&DEBUG.::P11_DEPTNO:#DEPTNO#', 600, 300)


As as result, when you click the Emp. Count for a department, a popup window of the opening page will be created. 

FancyBox Page Setup

To setup Fancybox 2, you need to add the javascript file and css to the master page:
JavaScript File URLs: jquery.fancybox.js or jquery.fancybox.pack.js
CSS File URLS: jquery.fancybox.css
You can easily add these files in your environment if you host your own APEX site and it is setup with APEX connector and Servlet container.



Alternatively, you can add links for these files from external CDN under HTML Header by:
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/jquery.fancybox.css" media="screen" />
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/fancybox/2.1.5/jquery.fancybox.pack.js"></script>

Write a piece of Javascript code to setup Fancybox for any object using the class called "fancybox". The most important parameter is the type: 'ajax'.   You can use other parameters as specified in here.
<script type="text/javascript">
$(document).ready(function() {
  $('.fancybox').fancybox({
    maxWidth    : 600,
    maxHeight   : 300,
    fitToView   : false,
    autoSize    : false,
    closeClick  : false,
    openEffect  : 'elastic',
    closeEffect : 'fade',
    scrolling   : true,
    type        : 'ajax'
  });
});
</script>


Finally, you just need to add the Link Attribute class="fancybox" for the column link in the master page.

After the setup has done, when you click the Emp. Count link in the master page, the Fancybox popup will be shown.


Demo




Monday, October 21, 2013

Using Tomcat & Apache for APEX and Oracle XE

Using Open Source components is always my first priority for software application design.  In recent APEX Listener releases, Oracle removed the instruction of using Tomcat, and it added Weblogic and Glassfish as Servlet container instead. I think it's a really bad idea that Oracle tried too hard to push their products and suppressed the info of using free alternatives.  It just make me even more likely not to use Weblogic nor Glassfish to host APEX application.  If you want to get the best, free, and most stable combination of software stack to host the APEX installation, here are the steps.  I created these steps under Windows 7 platform. However, the same steps could be apply to any Linux/Unix environment.

Once the setup has done and the site runs smoothly, you can then add any framework, Servlet, JSP, web services or other open-source components to enrich your application easily.

Bottom line: no need to use Weblogic for APEX unless you are designing the Obamacare website.

(1) Install Oracle XE 11g as usual

(2) Open SQL*Plus as sysdba, run the script to drop original APEX installation:
C:\oraclexe\app\oracle\product\11.2.0\server\apex\apxremov.sql

(3) Download APEX Release 4.2.3 from http://download.oracle.com/otn/java/appexpress/apex_4.2.3.zip.  Unzip this file to c:\temp\apex423.

(4) Open SQL*Plus as sysdba, run the script to install APEX 4.2.3
c:\temp\apex423\apex\apexins.sql SYSAUX SYSAUX TEMP /i/

(5) Unlock the account APEX_PUBLIC_USER and reset its password
alter user APEX_PUBLIC_USER account unlock;
alter user APEX_PUBLIC_USER identified by APEX_PUBLIC_USER;

(6) Run the script c:\temp\apex423\apex\apxconf.sql to set admin initial password and the XDB port to zero (to avoid port conflict with Tomcat)
SQL> @apxconf.sql
      PORT
----------
      8080
Enter values below for the XDB HTTP listener port and the password for the Application Express ADMIN user.
Default values are in brackets [ ].
Press Enter to accept the default value.
Enter a value below for the password for the Application Express ADMIN user.
Enter a password for the ADMIN user              []
Session altered.
...changing password for ADMIN
PL/SQL procedure successfully completed.
Enter a port for the XDB HTTP listener [      8080] 0
...changing HTTP Port
PL/SQL procedure successfully completed.

(7) Download APEX Listener 2.0.5 from  http://download.oracle.com/otn/java/appexpress/apex_listener.2.0.5.287.04.27.zip.  Unzip this file to C:\temp\apex_listener

(8) Create a directory (C:\APEX) to hold the APEX configuration data.  Then run the config.
java -jar c:\temp\apex_listener\apex.war
Enter the location to store configuration data:C:\apex
Oct 21, 2013 12:26:07 PM oracle.dbtools.common.config.cmds.ConfigDir execute
INFO: Set config.dir to C:\apex in: C:\temp\apex_listener\apex.war
Oct 21, 2013 12:26:10 PM oracle.dbtools.common.config.file.ConfigurationFolder logConfigFolder
INFO: Using configuration folder: C:\apex\apex
Enter the name of the database server [localhost]:
Enter the database listen port [1521]:
Enter 1 to specify the database service name, or 2 to specify the database SID [1]:2
Enter the database SID [xe]:XE
Enter the database user name [APEX_PUBLIC_USER]:
Enter the database password for APEX_PUBLIC_USER:
Confirm password:
Enter 1 to enter passwords for the RESTful Services database users (APEX_LISTENER,APEX_REST_PUBLIC_USER),
2 to use the same password as used for APEX_PUBLIC_USER or, 3 to skip this step [1]:3
Oct 21, 2013 12:26:36 PM oracle.dbtools.common.config.file.ConfigurationFiles update
INFO: Updated configurations: defaults, apex
Enter 1 if you wish to start in standalone mode or 2 to exit [1]:2

(9) Download Tomcat 7, unzip/install it to a directory (e.g. C:\TOMCAT7)

(10) copy the war file C:\temp\apex_listener\apex.war to C:\TOMCAT7\webapps.  Move the directory C:\temp\apex423\images to C:\apex\images

(11) Edit the tomcat config file C:\TOMCAT7\conf\server.xml to create the URI path of /i/ to c:\apex\images
....
<Host name="localhost" appBase="webapps"
....
<Context docBase="C:\apex\images" path="/i" />
...
</Host>

(12) Make sure system variable JAVA_HOME has set.  Start Tomcat and open URL http://localhost:8080/apex
Browse around and check whether it run properly.  If it looks good, shutdown Tomcat.

(13) Download Apache HTTP Server 2.4 binaries VC11 from Apache Lounge (and corresponding Visual Studio Redistributable).
Then download Tomcat connector from Apache (tomcat-connectors-1.2.37-windows-i386-httpd-2.4.x.zip)

(14) Unzip/Install Apache HTTP Server to C:\Apache24.  Extract the Tomcat connector file mod_jk.so and put it to C:\Apache24\modules

(15) Create the Tomcat Worker file (worker.conf) and put it under C:\Apache24\conf.  The content is similar as follows:
workers.tomcat_home=C:/tomcat7
workers.java_home=C:/JRE7
worker.list=worker1

worker.worker1.type=ajp13 
worker.worker1.host=localhost 
worker.worker1.port=8009 

(16) Edit the Apache config file (httpd.conf) and add these lines:
LoadModule jk_module modules/mod_jk.so

JkWorkersFile C:/Apache24/conf/worker.conf
JkLogFile     C:/Apache24/logs/mod_jk.log
JkLogLevel    info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkMount  /apex/*  worker1

Alias /i/ C:/APEX/images/
<Directory C:/APEX/images>
    Require all granted
</Directory>

(17) Remove the change in Step (11) since the static files are served by Apache now.

(18) Start Tomcat, and then start Apache.  Open URL http://localhost/apex
Browse around and check whether it run properly.




Tuesday, June 22, 2010

Customize APEX Admin Login Page

How often you log on to the wrong APEX workspace and do something you're not supposed to do for that workspace? I make this careless mistake a couple of time and the result is catastrophic. The root cause (obviously) is that I did not pay enough attention to the URL, but I also blamed (sort of an excuse) that the Admin Login Page looks exactly the same for all APEX instances.

In order to prevent it from happening again, I modified the Admin Login Page so that it shows some instance information in eye-catching way. In addition the workspace becomes a dropdown list so that I don't have to type in the name anymore.

The changes are very simple, and it's very easy to rollback, in case you screw it up.

Here is an result of the changes:


SQL for the changes

-- Add a name in the login box

-- login as system and change schema to APEX owner
connect / as sysdba
alter session set current_schema = APEX_030200;

-- Change the plug header with your choice in HTML code

UPDATE WWV_FLOW_PAGE_PLUGS 
   SET PLUG_COMMENT = PLUG_HEADER   
     , PLUG_HEADER  = '

PRODUCTION

' WHERE FLOW_ID = 4550 AND PAGE_ID = 1 AND PLUG_DISPLAY_SEQUENCE = 20; -- If you have applied translation UPDATE WWV_FLOW_PAGE_PLUGS SET PLUG_COMMENT = PLUG_HEADER , PLUG_HEADER = '

PRODUCTION

' WHERE FLOW_ID LIKE '455%' AND PAGE_ID LIKE '1.%' AND PLUG_DISPLAY_SEQUENCE = 20; -- To rollback to the original value UPDATE WWV_FLOW_PAGE_PLUGS SET PLUG_HEADER = PLUG_COMMENT , PLUG_COMMENT = NULL WHERE FLOW_ID = 4550 AND PAGE_ID = 1 AND PLUG_DISPLAY_SEQUENCE = 20; UPDATE WWV_FLOW_PAGE_PLUGS SET PLUG_HEADER = PLUG_COMMENT , PLUG_COMMENT = NULL WHERE FLOW_ID = LIKE '455%' AND PAGE_ID = LIKE '1.%' AND PLUG_DISPLAY_SEQUENCE = 20; -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- Change Workspace as dropdown list UPDATE WWV_FLOW_STEP_ITEMS set DISPLAY_AS = 'COMBOBOX' , LOV = 'select short_name NAME, short_name from ' || 'wwv_flow_companies where ID NOT IN (0,3)' , LOV_DISPLAY_NULL = 'YES' , LOV_NULL_TEXT = '-- Select One --' WHERE FLOW_ID = 4550 AND NAME = 'F4550_P1_COMPANY'; -- To rollback to original value UPDATE WWV_FLOW_STEP_ITEMS set DISPLAY_AS = 'TEXT' , LOV = NULL , LOV_DISPLAY_NULL = 'NO' , LOV_NULL_TEXT = NULL WHERE FLOW_ID = 4550 AND NAME = 'F4550_P1_COMPANY';