Blog Ronald

Welcome to my Blog

AJAX – Getting Started ExtJs with Perl CGI

Posted by T. Ronald S. on December 22, 2009

I usually use ExtJs with Struts, PHP, or Google Web Toolkit (GWT). Here i will create a simple tree panel sample using ExtJS and Perl CGI.

Here is our directory structure:
extjstest
-extjs (directory)
-JSON (directory)
-data.cgi (file)
-index.html (file)
-JSON.pm (file)

requirements:
1. Download the latest Ext Js from here and extract the archive files to extjs folder
2. You have mod Perl cgi enabled with your apache server, you can see my post at Perl for how to set up mod mod Perl CGI in apache
3. JSON module for Perl, you can download it from here

Enough talk, let’s start coding!

Filename: index.html

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css"
	href="extjs/resources/css/ext-all.css" />
<script type="text/javascript" src="extjs/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="extjs/ext-all-debug.js"></script>
<script type="text/javascript">
	Ext.onReady(function() {
		var Tree = Ext.tree;
		var tree = new Tree.TreePanel( {
			el : 'tree-div',
			autoScroll : true,
			border: false,
			title: 'My First Panel',
			animate : true,
			enableDD : true,
			containerScroll : true,
			loader : new Tree.TreeLoader( {
				<strong>dataUrl : 'data.cgi'</strong>
			})
		});
		// set the root node
			var root = new Tree.AsyncTreeNode( {
				text : 'Ext JS',
				draggable : false,
				id : 'source'
			});
			tree.setRootNode(root);

			 // render the tree
		    tree.render();
		    root.expand();
		});
</script>

</head>
<body>
<div id="tree-div" style="overflow:auto; height:300px;width:250px;border:1px solid #c3daf9;"></div>
</body>
</html></a>

As you see above code, the treepanel gets the data url from data.cgi. What is this data.cgi produce? the data.cgi will response JSON type to the html, JSON is optimized version of XML.

2. data.cgi

#!/usr/bin/perl -w
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use Storable;
use JSON;
$page = new CGI;

print "Content-type: application/json\n\n";
@mydata0={'text'=>'merci','id'=>'3','leaf'=>true,'cls'=>'file'};
@mydata1={'text'=>'audi','id'=>'2','children'=>\@mydata0};
@mydata2={'text'=>'benz','id'=>'1','children'=>\@mydata1};

@mydata=(@mydata2,@mydata3);

$text = objToJson(\@mydata);

print $text;
exit (0);

Open your browser and point to http://localhost/extjstest/index.html. If everything fine, you should see a treepanel displayed.

Posted in AJAX | Leave a Comment »

JBoss – Create JNDI Datasource with Oracle

Posted by T. Ronald S. on December 5, 2009

Goal: able to create and use jndi datasource with jboss as backend
First, make sure you have JBoss and Oracle installed on your system, then we can start creating our datasource configuration file.
filename: oracle-ds.xml

<?xml version="1.0" encoding="UTF-8"?>
<datasources>
    <local-tx-datasource>
        <jndi-name>oraclexeDS</jndi-name>
        <connection-url>jdbc:oracle:thin:@localhost:1521:your-db-sid</connection-url>
        <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
        <user-name>your-db-user</user-name>
        <password>your-db-pass</password>
        <valid-connection-checker-classname>org.jboss.resource.adapter.jdbc.vendor.OracleValidConnectionChecker</valid-connection-checker-classname>
        <metadata>
            <type-mapping>Oracle10g</type-mapping>
        </metadata>
    </local-tx-datasource>
</datasources>

copy the file to your deployment directory: ../pathto/Jboss-x.x.x/server/default/deploy
congratulation, you already set up datasource with jndi named: oraclexeDS. Next, create a simple jsp project and named it Datasource, modify index.jsp so it becomes like below.
Filename: index.jsp

<%@page contentType="text/html"
        import="java.util.*,javax.naming.*,javax.sql.DataSource,java.sql.*"
        %>
<%
        DataSource ds = null;
        Connection con = null;
        PreparedStatement pr = null;
        InitialContext ic;
        try {
            ic = new InitialContext();
            ds = (DataSource) ic.lookup("java:/oraclexeDS");
            con = ds.getConnection();
            pr = con.prepareStatement("select sysdate as coldate from dual");
            ResultSet rs = pr.executeQuery();
            while (rs.next()) {
                out.println("<br> today is " + rs.getString("coldate"));
            }
            rs.close();
            pr.close();
        } catch (Exception e) {
            out.println("Exception thrown " + e);
        } finally {
            if (con != null) {
                try {
                    con.close();
                } catch (Exception ex) {
                    out.println(ex.getMessage());
                }
            }
        }%>

The idea of jsp code is to get today’s date from oracle. Build your web and copy the war file to jboss deployment directory.

run it in a browser: http://localhost:8080/Datasource

if everything works fine, it should display today is 2009-12-05 16:42:20.0

Posted in JBoss | Leave a Comment »

JBoss – changing JMX-Console admin password

Posted by T. Ronald S. on December 5, 2009

# cd ../pathto/jboss-x.x.x/server/default/conf/props
# vi jmx-console-users.properties
admin=admin

it is user=password format, change them accordingly. Now you can login with your new username and password

Posted in JBoss | Leave a Comment »

Connect Zend Framework with Oracle XE

Posted by T. Ronald S. on November 27, 2009

Howdy,
As a new player in zend framework, i tried to connect my php with oracle using Zend_Db and tried to get sysdate from oracle. Here how it goes.
First i created a DB.php file and put it in models directory

<?php
require_once 'Zend/Db.php';
class DB{

    protected $db = null;

    function __construct(){
        $params = array('username'=>'user','password'=>'pass','dbname'=>'//localhost/XE');
        $this->db = Zend_Db::factory('oracle',$params);
    }

    function getSysDate(){
        $res = $this->db->fetchRow("select sysdate as coldate from dual");
        return $res['COLDATE'];
    }
    function helloWorld(){
        return 'Hello World';
    }
}
?>

and then i modified the indexController.php as below

<?php
require_once 'models/DBphp';
class IndexController extends Zend_Controller_Action
{
    protected $db;
    public function init()
    {
        $this->_helper->viewRenderer->setNoRender();
        $this->db = new DB();
    }

    public function indexAction()
    {
        echo $this->db->helloWorld();
        echo $this->db->getSysDate();
    }
}

Run and it displayed
Hello World 28-NOV-09

Nice, next i will try to connect php with my java webservice modules. See yaa!

Posted in PHP | Leave a Comment »

Fix error when creating action in Zend Framework

Posted by T. Ronald S. on November 27, 2009

Fatal error: Call to undefined function token_get_all() in
…/ZendFRamework/library/Zend/ReflectioN/File.php on line 300

The error message happened because we haven’t enabled the tokenizer extention in PHP. To enable that extension simply do this:

- open your php.ini, uncomment this line
before:
#extension=tokenizer.so
after:
extension=tokenizer.so

- save your php.ini and restart apache
- try to create a project and an action
$ zf.sh create project testing
$ cd testing
$ zf.sh create action testaction index

you will have your testaction created. Hope this is helpful

Posted in PHP | Leave a Comment »

Insert and fetch Binary Data with Oracle and JDBC

Posted by T. Ronald S. on November 26, 2009

First create a dummy table
create table tblBlob(c1 number primary key not null, c2 blob);

please note that blob data type in oracle can handle up to 4Gb size

here is the code for insertion

Connection conn = ... // define your connection here
PreparedStatement pstmt = conn.prepareStatement("INSERT INTO tblBlob VALUES (?,?)");
pstmt.setInt(1, 100);
File fBlob = new File("cable.jpg");  // i'm using an image as the data
is = new FileInputStream(fBlob);
pstmt.setBinaryStream(2, is, (int) fBlob.length());
pstmt.execute();

and here is the code for fetching and convert it back to image

Connection conn = OracleConnection.getConnection();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM tblBlob");
while (rs.next()) {
      int val1 = rs.getInt(1);
      InputStream val2 = rs.getBinaryStream(2);
      BufferedImage image = ImageIO.read(val2);
      img = image.getScaledInstance(300, 300, 300);
     . . .
}

Posted in Oracle PL/SQL, JDBC | Leave a Comment »

5 Reasons we chose BIRT instead of Jasper or JFreeReport

Posted by T. Ronald S. on November 5, 2009

A year ago, I was looking for a way to integrate complex/graphical reporting into our software offerings. I was sure that the way is to find an open source project that has the right kind of license and right kind of technology. Regarding licensing, I wanted to make sure that we should be able to use the reporting engine/technology in our commercial software. I evaluated JasperReport, JFree Report (now part of Pentaho) and of course, BIRT. Here is what I liked in BIRT

  1. BIRT is an Eclipse project: This made sure that the project is going to be live and evolving (as an open source project) in the times to come and will become more feature rich as the time passes. We were not afraid that someone is going to close the source directly or indirectly (by selling documentation at high prices) by creating a future version that will require commercial support to do anything but trivial.
  2. BIRT uses standard technologies to the maximum level: It uses HTML for layout related things, JavaScript for scripting and CSS for styling! It naturally means we can leverage the existing knowledge that our developers have in creating the kind of reports our customer want. Faster and at lower costs.
  3. BIRT offers very good GUI Designer: A graphical designer not just makes your life easier while developing the reports but you can also give it to your customers so that they can also do some small changes that they might need here or there in the report. Most important thing is that BIRT designer is group of plugIns for Eclipse IDE and hence quality of the report designer is excellent.
  4. BIRT has a very nice Web Viewer: Yes it comes with nice pre-integrated ajax enabled web viewer that your can run from Tomcat (our favourite) or any other Application Server in less than few minutes.
  5. BIRT has quality documentation, sample database, example reports: All this reduced the learning curve to a very affordable level.

If you are looking for a serious reporting solution (open source), I will recommend that you should consider evaluating BIRT. May be you can find the technology you are looking for.

by http://blogs.zaidsoft.com/sz_quadri

Posted in Miscellaneous | Leave a Comment »

Email Alert Management

Posted by T. Ronald S. on October 17, 2009

Project Name: Email Alert Management
Background: As there are many supporting applications tools running, the number of alert and warning from the applications is getting bigger. It is annoying when receiving hundreds of emails per day triggered by alerts from many applications. Therefore we need a mechanism to manage all the alerts.
Aim: To provide an application that will sit between supporting applications and end users so that we can set parameters to filter the alerts, and trigger the alert when the parameters are satisfied. parameters used are number of alert received, alert priority, alert status, notification list
Technology: Linux, Oracle10g, Java, GWT (Google Web Toolkit), Apache Tomcat, Dovecot, JavaMail API
Estimated time: 1 month

EmailAlertManagement

User Manual:

Alert Management is a tool that help to manage email alert from various applications

The first page you will see is a login screen that require authentication your NT Account with LDAP.

There are two privileges in this web application: Member and Administrator.

Member Privilege
When you login as a member you will be directed to below main page

Getting Started
1. Choosing subscription

At the left panel there is tree node called Available subcription, you can tick one or more available subscriptions.

2. Adding selections
Click Email Alert Setting at the tree node and then click Add Selections. This will add your selected subscription to the grid at the center panel of the page

3. Defining Alert
You can define your alert by clicking alert list at the grid. this will direct you to below alert panel

Click the arrow down button of Add New Alert panel and fill up the form to define a new alert.
Below is an example of an alert that will trigger after receiving 10 emails from QMS UTV email alert.

Note: If you have multiple notification list, please separated emails with comma (,)
Click add to continue
You will get your defined alert in your alert list grid box

Also notice that your inbox tree node also updated with the new created alert.

4. Inbox
Clicking the inbox will show your inbox with emails from the subscription

As we already defined an alert in this example to automatically sends emails alert when receiving 10 emails. You have two more options at the inbox panel: Delete and Send Now
Clicking the delete button will delete your inbox, and clicking send now will send the emails right away to the notification list defined at the alert.

 

 

Posted in EmailAlertManagement | Leave a Comment »

undefined reference to typeinfo – C++ error message

Posted by T. Ronald S. on September 13, 2009

This error message made me scratching my head for hour

g++ -o polygon shape.o circle.o square.o polygon.o
circle.o(.gnu.linkonce.r._ZTI6Circle+0x8): undefined reference to `typeinfo for Shape'
square.o(.gnu.linkonce.r._ZTI6Square+0x8): undefined reference to `typeinfo for Shape'
polygon.o(.gnu.linkonce.t._ZN5ShapeC2Ev+0x8): In function `Shape::Shape()':
: undefined reference to `vtable for Shape'
collect2: ld returned 1 exit status

To fix this?

- undefined reference to typeinfo:
got this line? virtual float getarea() ;
that should read virtual float getarea() {} ;
- undefined reference to vtable means could be there is a virtual function from your interface is not implemented yet.

Posted in C++ | Leave a Comment »

Uploader app 1.0 part 3 – Open Office Project Management

Posted by T. Ronald S. on August 29, 2009

Manage my  project is not difficult in Ubuntu, i will directly go to open office project management. tasks, resource, calendar, time line, completeness, link task, unlink task you name it, they are all provided in this software. My most favorite feature is ability to export project to a nice HTML format, i once shocked my manager with this tool and he’s wondering and asking me how did you do thatt? what tool are you using? well..you don’t need to ask now, use this tool :)

UploaderAppv1.0

Here is the html export output

export_png_sample

Posted in Uploader App v1.0 | Leave a Comment »