<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-15934471</id><updated>2011-09-14T06:35:14.702-07:00</updated><title type='text'>LIMinescence</title><subtitle type='html'>sharing cognitive photons to enlighten you</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://liminescence.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://liminescence.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>liminescence</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>27</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-15934471.post-7789220669988866345</id><published>2011-08-07T17:38:00.000-07:00</published><updated>2011-08-07T17:38:32.200-07:00</updated><title type='text'>Reactor Design Pattern - using java nio</title><content type='html'>While working on &lt;a href="http://wiki.nginx.org/"&gt;nginx&lt;/a&gt;, I got so interested with the architecture on how it can address the &lt;a href="http://www.kegel.com/c10k.html"&gt;C10K problem&lt;/a&gt;. Unlike traditional servers, Nginx doesn't rely on threads to handle requests. Instead it uses a much more scalable event-driven (asynchronous) architecture. &lt;br /&gt;&lt;br /&gt;But what is event-driven (asynchronous) architecture really? To simplify, let's talk about &lt;a href="http://en.wikipedia.org/wiki/Asynchronous_I/O"&gt;Asynchronous I/O&lt;/a&gt;. Asynchronous I/O is also known as Non-blocking I/O. It can be best describe by the reactor design pattern.&lt;br /&gt;&lt;br /&gt;Wikipedia explains, the reactor design pattern is a concurrent programming pattern for handling service requests delivered concurrently to a service handler by one or more inputs. The service handler then demultiplexes the incoming requests and dispatches them synchronously to the associated request handlers. (&lt;b&gt;The Reactor pattern is closely related to the Observer/Observable pattern in this aspect: all dependents are informed when a single subject changes. The Observer pattern is associated with a single source of events, however, whereas the Reactor pattern is associated with multiple sources of events.&lt;/b&gt;)&lt;br /&gt;&lt;br /&gt;Reactor design pattern is easier to understand by examples and diagrams. In this illustration, I will be using the java nio. &lt;br /&gt;&lt;br /&gt;Until JDK 1.4, the Java platform did not support nonblocking I/O calls. With an almost one-to-one ratio of threads to clients, servers written in the Java language were susceptible to enormous thread overhead, which resulted in both performance problems and lack of scalability.&lt;br /&gt;&lt;br /&gt;&lt;div id="__ss_8307601" style="width: 425px;"&gt;&lt;strong style="display: block; margin: 12px 0 4px;"&gt;&lt;a href="http://www.slideshare.net/liminescence/reactor-design-pattern" title="Reactor Design Pattern"&gt;Reactor Design Pattern&lt;/a&gt;&lt;/strong&gt;&lt;object height="355" id="__sse8307601" width="425"&gt;&lt;param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=reactordesignpattern-110614145127-phpapp02&amp;stripped_title=reactor-design-pattern&amp;userName=liminescence" /&gt;&lt;param name="allowFullScreen" value="true"/&gt;&lt;param name="allowScriptAccess" value="always"/&gt;&lt;embed name="__sse8307601" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=reactordesignpattern-110614145127-phpapp02&amp;stripped_title=reactor-design-pattern&amp;userName=liminescence" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;br /&gt;&lt;div style="padding: 5px 0 12px;"&gt;View more &lt;a href="http://www.slideshare.net/"&gt;presentations&lt;/a&gt; from &lt;a href="http://www.slideshare.net/liminescence"&gt;liminescence&lt;/a&gt;.&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;By this time, you have the basic idea of how the reactor pattern works! The key component are the Selector, Channels (and buffers) and the handler. Let's investigate them one by one.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Channels and Buffers&lt;/b&gt;&lt;br /&gt;Channels are like streams in the original I/O package. All data that goes anywhere (or comes from anywhere) must pass through a Channel object. A Buffer is a container object. All data that is sent to a channel must first be placed in a buffer; likewise, any data that is read from a channel is read into a buffer.&lt;br /&gt;&lt;br /&gt;A Buffer is an object, which holds some data, that is to be written to or that has just been read from. The addition of the Buffer object in NIO marks one of the most significant differences between the new library and original I/O. In stream-oriented I/O, you wrote data directly to, and read data directly from, Stream objects.&lt;br /&gt;&lt;br /&gt;In the NIO library, all data is handled with buffers. When data is read, it is read directly into a buffer. When data is written, it is written into a buffer. Anytime you access data in NIO, you are pulling it out of the buffer.&lt;br /&gt;&lt;br /&gt;The most commonly used kind of buffer is the ByteBuffer. A ByteBuffer allows get/set operations (that is, the getting and setting of bytes) on its underlying byte array. (There are other buffers as well. CharBuffer ShortBuffer, IntBuffer, LongBuffer, FloatBuffer, and DoubleBuffer). *NOTE: StringBuffer was added in Java 5 and it's not even part of nio package.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Basic Example on reading data from a Channel.&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;//getting the channel.&lt;br /&gt;FileInputStream fin = new FileInputStream( "readandshow.txt" );&lt;br /&gt;FileChannel fc = fin.getChannel();&lt;br /&gt;&lt;br /&gt;//creating a buffer.&lt;br /&gt;ByteBuffer buffer = ByteBuffer.allocate( 1024 );&lt;br /&gt;fc.read( buffer );&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;You'll notice that we didn't need to tell the channel how much to read into the buffer. Each buffer has a sophisticated internal accounting system that keeps track of how much data has been read and how much room there is for more data.&lt;br /&gt;&lt;br /&gt;Writing to a file.&lt;br /&gt;&lt;pre&gt;FileOutputStream fout = new FileOutputStream( "writesomebytes.txt" );&lt;br /&gt;FileChannel fc = fout.getChannel();&lt;br /&gt;&lt;br /&gt;//create a buffer, and put some data in it.&lt;br /&gt;ByteBuffer buffer = ByteBuffer.allocate( 1024 );&lt;br /&gt;for (int i=0; i&amp;lt;100; ++i) {&lt;br /&gt;    buffer.put( i );&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;//The flip() method &lt;br /&gt;//prepares the buffer to have the &lt;br /&gt;//newly-read data written to another channel&lt;br /&gt;buffer.flip();&lt;br /&gt;&lt;br /&gt;//write data of the buffer.&lt;br /&gt;fc.write( buffer );&lt;br /&gt;&lt;/pre&gt;&lt;b&gt;&lt;a href="http://download.oracle.com/javase/1.4.2/docs/api/java/nio/channels/Selector.html"&gt;Selector&lt;/a&gt;&lt;/b&gt; The central object in asynchronous I/O is called the Selector. A Selector is where you register your interest in various I/O events, and it is the object that tells you when those events occur.  Example: &lt;br /&gt;&lt;pre&gt;Selector selector = Selector.open();&lt;br /&gt;&lt;br /&gt;//another way of getting selector instance.&lt;br /&gt;Selector selector = SelectorProvider.provider().openSelector();&lt;br /&gt;&lt;/pre&gt;&lt;b&gt;Handler&lt;/b&gt; The handler are your worker threads. They are responsible for the data that you read, and also for writing your data. You can pre-define a thread pool to handle all your request. There's nothing fancy about the handler. Check  the link I provided below, for detailed example.   Now that you are familiar with Selectors, Channels, buffers and Selector, we need to tie them together. But first, to accept connection from a client, you need a &lt;a href="http://openjdk.java.net/projects/nio/javadoc/java/nio/channels/ServerSocketChannel.html"&gt;ServerSocketChannel&lt;/a&gt;. ServerSocketChannel is the nio version of ServerSocket that uses channeling and buffering methodology.  Example: &lt;br /&gt;&lt;pre&gt;// Create a new non-blocking server socket channel&lt;br /&gt;serverChannel = ServerSocketChannel.open();&lt;br /&gt;serverChannel.configureBlocking(false);&lt;br /&gt;&lt;br /&gt;// Bind the server socket to the specified address and port&lt;br /&gt;// NOTE: HOST_ADDRESS is a type InetAddress and PORT is an int.&lt;br /&gt;InetSocketAddress isa = new InetSocketAddress(HOST_ADDRESS, PORT);&lt;br /&gt;serverChannel.socket().bind(isa);&lt;br /&gt;&lt;br /&gt;//registering the ServerSocketChannel to the selector.&lt;br /&gt;SelectionKey key = ssc.register( selector, SelectionKey.OP_ACCEPT );&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The first argument to register() is always the Selector. The second argument, OP_ACCEPT, here specifies that we want to listen for accept events -- that is, the events that occur when a new connection is made. This is the only kind of event that is appropriate for a ServerSocketChannel.&lt;br /&gt;&lt;br /&gt;Note the return value of the call to register(). A SelectionKey represents this registration of this channel with this Selector. When a Selector notifies you of an incoming event, it does this by supplying the SelectionKey that corresponds to that event. The SelectionKey can also be used to de-register the channel.&lt;br /&gt;&lt;br /&gt;I'm sure by this time, you are ready to see a working sample code to implement this whole theory. I thought of writing an example, but this site did it very well.&amp;nbsp;http://rox-xmlrpc.sourceforge.net/niotut/&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15934471-7789220669988866345?l=liminescence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://liminescence.blogspot.com/feeds/7789220669988866345/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=15934471&amp;postID=7789220669988866345' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/7789220669988866345'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/7789220669988866345'/><link rel='alternate' type='text/html' href='http://liminescence.blogspot.com/2011/08/reactor-design-pattern-using-java-nio.html' title='Reactor Design Pattern - using java nio'/><author><name>liminescence</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-15934471.post-4427392498042083496</id><published>2011-06-06T16:01:00.000-07:00</published><updated>2011-06-06T16:01:23.384-07:00</updated><title type='text'>Java Concurrency Utilities: using Semaphore</title><content type='html'>If you haven't done much of multi-threaded programming with Java 5, I am sure when you are ask of how prevent concurrent problems when 2 threads is accessing your data, you would think of synchronizing code, by making the method synchronized. &lt;br /&gt;&lt;br /&gt;&lt;pre&gt;public class SyncCounter {&lt;br /&gt;    private int c = 0;&lt;br /&gt;&lt;br /&gt;    public synchronized void increment() {&lt;br /&gt;        c++;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public synchronized void decrement() {&lt;br /&gt;        c--;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public synchronized int value() {&lt;br /&gt;        return c;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Perhaps, you would probably also come up with an idea, instead of synchronizing a method, you would only synchronized a block of code.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;    public void increment() {&lt;br /&gt;        synchronized(c) {&lt;br /&gt;            c++;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;But with the concurrency API of java 5, they have added solutions for common threads requirements. In particular, the have added "Semaphore".&lt;br /&gt;&lt;br /&gt;A Semaphore controls access to shared resource using a counter. If the counter has a value greater than zero, then access is allowed. If it is zero, then access is denied. What the counter is counting are permits that allow access to the shared resource. Ergo, to access the resource, a thread must be granded a permit from the semaphore.&lt;br /&gt;&lt;br /&gt;Semaphore has two constructor:&lt;br /&gt;&lt;br /&gt;Sempahore(int num)&lt;br /&gt;Semaphore(int num, boolean how)&lt;br /&gt;&lt;br /&gt;num specifies the initial permit count. The num parameter, specifies the number of threads that can access a shared resource at any one time. If the value of num is one, then only one thread can access the resource at any one time. By setting the how to true, you can ensure that waiting threads are granted a permit in the order in which they request access.&lt;br /&gt;&lt;br /&gt;To acquire permit, call the acquire() method, which has these two forms:&lt;br /&gt;&lt;br /&gt;void acquire() throws InterruptedException&lt;br /&gt;void acquire(int num) throws InterruptedException&lt;br /&gt;&lt;br /&gt;To release a permit, call release(), which has these two forms:&lt;br /&gt;&lt;br /&gt;void release()&lt;br /&gt;void release(int num)&lt;br /&gt;&lt;br /&gt;The first form releases one permit. The second form releases the number of permits.&lt;br /&gt;&lt;br /&gt;To use a semaphore to control access to a resource, each thread that wants to use that resource must first call acquire() before accessing the resource. When the thread is done with the resource, it must call release(). &lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;import java.util.concurrent.*;&lt;br /&gt;&lt;br /&gt;class SemaphoreDemo {&lt;br /&gt;&lt;br /&gt;    public static void main(String args[]) {&lt;br /&gt;        //instantiate a Semaphore with value 1. Meaning, 1 thread can aquire permit at a time.&lt;br /&gt;        Semaphore sem = new Semaphore(1);&lt;br /&gt;      &lt;br /&gt;        //instantiate 2 threads to access a shared resource at the same time.&lt;br /&gt;        new IncThread(sem, "A");&lt;br /&gt;        new DecThread(sem, "B");&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// A shared resource.&lt;br /&gt;class Shared {&lt;br /&gt;    static int count = 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class IncThread implements Runnable {&lt;br /&gt;    String name;&lt;br /&gt;    Semaphore sem;&lt;br /&gt;&lt;br /&gt;    IncThread(Semaphore s, String n) {&lt;br /&gt;        sem = s;&lt;br /&gt;        name = n;&lt;br /&gt;        new Thread(this).start();&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public void run() {&lt;br /&gt;        try {&lt;br /&gt;        //acquiring the permit.&lt;br /&gt;            sem.acquire();&lt;br /&gt;            System.out.println(name + "gets a permit.");&lt;br /&gt;            for( int i=0; i &lt; 5; i++ ) {&lt;br /&gt;                Shared.count++;&lt;br /&gt;                System.out.println(name + ":" + Shared.count);&lt;br /&gt;                Thread.sleep(10);&lt;br /&gt;            }&lt;br /&gt;            } catch (InterruptedException exc) {&lt;br /&gt;               System.out.println(exc);&lt;br /&gt;            }&lt;br /&gt;        //releasing the permit.&lt;br /&gt;        System.out.println(name + "releases the permit.");&lt;br /&gt;        sem.release();&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;class DecThread implements Runnable {&lt;br /&gt;    String name;&lt;br /&gt;    Semaphore sem;&lt;br /&gt;&lt;br /&gt;    DecThread(Semaphore s, String n) {&lt;br /&gt;        sem = s;&lt;br /&gt;        name = n;&lt;br /&gt;        new Thread(this).start();&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public void run() {&lt;br /&gt;        try {&lt;br /&gt;            sem.acquire();&lt;br /&gt;            System.out.println(name + "gets a permit.");&lt;br /&gt;            for(int i=0; i &lt; 5; i++ ) {&lt;br /&gt;                Shared.count--;&lt;br /&gt;               System.out.println(name + ":" + Shared.count);&lt;br /&gt;            }&lt;br /&gt;        } catch (InterruptedException exc) {&lt;br /&gt;            System.out.println(exc);&lt;br /&gt;        }&lt;br /&gt;        System.out.println(name + "releases the permit.");&lt;br /&gt;        sem.release();&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Notice that in the run methods, there are no synchronized keywords define. That is because, the semaphore actually implements it internally making it synchronized as you acquire for the lock.&lt;br /&gt;&lt;br /&gt;Without the use of Semaphore, accesses to Shared.count by both threads would have occurred simultaneously, and the increments and decrements would be intermixed.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15934471-4427392498042083496?l=liminescence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://liminescence.blogspot.com/feeds/4427392498042083496/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=15934471&amp;postID=4427392498042083496' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/4427392498042083496'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/4427392498042083496'/><link rel='alternate' type='text/html' href='http://liminescence.blogspot.com/2011/06/java-concurrency-utilities-using.html' title='Java Concurrency Utilities: using Semaphore'/><author><name>liminescence</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-15934471.post-1196463250738802175</id><published>2011-05-23T13:36:00.000-07:00</published><updated>2011-05-23T13:36:15.472-07:00</updated><title type='text'>new try-catch in java</title><content type='html'>As we have experienced this, it is difficult to correctly close resources. For example, if you open a file or a socket, it is easy to forget to close it. Your code can easily ran out of file handles if not properly taken care of. &lt;br /&gt;To make things easier, Java 7 introduced the new "try with resources" syntax. It automatically closes any AutoCloseable resources referenced in the try statement. For example, instead of manually closing streams ourselves, we can simply do this: &lt;br /&gt;&lt;br /&gt;&lt;pre&gt;import java.io.*;&lt;br /&gt;&lt;br /&gt;public class AutomaticResourceClosing {&lt;br /&gt;  public static void main(String[] args) throws IOException {&lt;br /&gt;    try (&lt;br /&gt;      PrintStream out = new PrintStream (&lt;br /&gt;          new BufferedOutputStream(&lt;br /&gt;              new FileOutputStream("foo.txt")))&lt;br /&gt;    ) {&lt;br /&gt;      out.print("Unable to close resource");&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Take note that there is never a semicolon at the end of the "try ()" declaration.&lt;br /&gt;&lt;br /&gt;You can read more about other features by going to Java.net site ( http://jdk7.java.net/ ).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15934471-1196463250738802175?l=liminescence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://liminescence.blogspot.com/feeds/1196463250738802175/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=15934471&amp;postID=1196463250738802175' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/1196463250738802175'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/1196463250738802175'/><link rel='alternate' type='text/html' href='http://liminescence.blogspot.com/2011/05/new-try-catch-in-java.html' title='new try-catch in java'/><author><name>liminescence</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-15934471.post-829539867637820679</id><published>2010-11-11T21:28:00.000-08:00</published><updated>2010-11-11T21:28:11.323-08:00</updated><title type='text'>TDD with javascript, JQuery, QUnit and Maven</title><content type='html'>I recently attended a Test Driven Development (TDD) training by Brett Schuchert of ObjectMentor.com and find it really useful! With TDD your code maintenance and evolution are easier and regression testing is less likely to have bugs because it prevents bugs from happening in the first place.&lt;br /&gt;&lt;br /&gt;But what is TDD exactly? The instructor defined it as a "design practice". It uses tests as mechanism for discovery and feedback. He also added that TDD is not always the right thing to do. It depends on your application and requirements.&lt;br /&gt;&lt;br /&gt;I was surprised to know that TDD idea has been around since late 50's. The original Mercury Rocket Project uses TDD.&lt;br /&gt;&lt;br /&gt;The training inspired me and  had me started looking on the how to apply TDD in javascript. The instructor advised some framework such as jsunit, which is good, but since our FEDs (Frontend developers) uses JQuery, I have to find a framework that has less learning curve and easy to use.&lt;br /&gt;&lt;br /&gt;I searched and found out about Qunit (http://docs.jquery.com/Qunit). QUnit is a powerful, easy-to-use, JavaScript test suite. It's used by the jQuery project to test its code and plugins but is capable of testing any generic JavaScript code (and even capable of testing JavaScript code on the server-side). &lt;br /&gt;&lt;br /&gt;Qunit is cool! But I have to integrate it with our maven project. I want our "maven build" to break if javascript unit test fails. (like how JUnit works ).&lt;br /&gt;&lt;br /&gt;After further research, I found Rhino. Rhino is an open-source implementation of JavaScript written entirely in Java. It is typically embedded into Java applications to provide scripting to end users. &lt;br /&gt;&lt;br /&gt;Given these 2 technologies, I configured maven to use qunit and Rhino to do javascript unit testing, and here's how I did it. ( If you have a better solution or comments, please let me know. )&lt;br /&gt;&lt;br /&gt;One thing to keep in mind, when using this combo is that, you have to separate your javascript calculation logic from DOM-manipulation logic. You can extract them to a function or to an object, and unit test them separately. Use selenium to test the DOM-manipulation part. The reason being is that, you are executing javascript without the browser, and DOM-manipulation logic is easier to test using Selenium.&lt;br /&gt;&lt;br /&gt;Here's an example on how to do it.&lt;br /&gt;&lt;br /&gt;1) adder.js - This file is where you put the functions that you want to test.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;//function that adds.&lt;br /&gt;function adder(x,y) {&lt;br /&gt;    return x + y;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;2) adderTest.js - This file is your unitTest.&lt;br /&gt;&lt;pre&gt;test("Adding numbers works", function() {&lt;br /&gt;        expect(2);&lt;br /&gt;        ok(adder, "function exists");&lt;br /&gt;        equals(4, adder(2, 2), "2 + 2 = 4");&lt;br /&gt;            }&lt;br /&gt;);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;3) suite.js - This file is your suite. It can contain many test.js files.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;load("src/main/webapp/WEB-INF/js/qunit/qunit.js");&lt;br /&gt;&lt;br /&gt;QUnit.init();&lt;br /&gt;QUnit.config.blocking = false;&lt;br /&gt;QUnit.config.autorun = true;&lt;br /&gt;QUnit.config.updateRate = 0;&lt;br /&gt;QUnit.log = function(result, message) {&lt;br /&gt;    if(result == false) {&lt;br /&gt;        print("FAILED: " + message);&lt;br /&gt;        java.lang.System.exit(0);&lt;br /&gt;    }else {&lt;br /&gt;       print("PASS: " + message) ;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;load("src/main/webapp/WEB-INF/js/adder.js");&lt;br /&gt;load("src/main/webapp/WEB-INF/js/adderTest.js");&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;NOTE: &lt;br /&gt;a) Make sure you have downloaded qunit, and put it in your js directory. It is being referenced by suite.js&lt;br /&gt;b) since I am using Maven 2, the path should starts from your base directory. (In my setup, it's in src/main/webapp/WEB-INF/js)&lt;br /&gt;&lt;br /&gt;4) Add a dependency on Rhino and a maven plugin in your pom.xml:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;...&lt;br /&gt;&amp;lt;dependency&amp;gt;&lt;br /&gt;   &amp;lt;groupid&amp;gt;rhino&amp;lt;/groupid&amp;gt;&lt;br /&gt;    &amp;lt;artifactid&amp;gt;js&amp;lt;/artifactid&amp;gt;&lt;br /&gt;    &amp;lt;version&amp;gt;1.7R1&amp;lt;/version&amp;gt;&lt;br /&gt;&amp;lt;/dependency&amp;gt;&amp;lt;/pre&amp;gt;&lt;br /&gt;&lt;br /&gt;...&lt;br /&gt;&lt;br /&gt;&amp;lt;plugin&amp;gt;&lt;br /&gt;    &amp;lt;groupid&amp;gt;org.codehaus.mojo&amp;lt;/groupid&amp;gt;&lt;br /&gt;    &amp;lt;artifactid&amp;gt;exec-maven-plugin&amp;lt;/artifactid&amp;gt;&lt;br /&gt;    &amp;lt;version&amp;gt;1.1&amp;lt;/version&amp;gt;&lt;br /&gt;    &amp;lt;executions&amp;gt;&lt;br /&gt;        &amp;lt;execution&amp;gt;&lt;br /&gt;        &amp;lt;phase&amp;gt;test&amp;lt;/phase&amp;gt;&lt;br /&gt;        &amp;lt;goals&amp;gt;&lt;br /&gt;            &amp;lt;goal&amp;gt;java&amp;lt;/goal&amp;gt;&lt;br /&gt;        &amp;lt;/goals&amp;gt;&lt;br /&gt;        &amp;lt;/execution&amp;gt;&lt;br /&gt;    &amp;lt;/executions&amp;gt;&lt;br /&gt;    &amp;lt;configuration&amp;gt;&lt;br /&gt;        &amp;lt;mainclass&amp;gt;org.mozilla.javascript.tools.shell.Main&amp;lt;/mainclass&amp;gt;&lt;br /&gt;        &amp;lt;arguments&amp;gt;&lt;br /&gt;            &amp;lt;argument&amp;gt;-opt&amp;lt;/argument&amp;gt;&lt;br /&gt;            &amp;lt;argument&amp;gt;-1&amp;lt;/argument&amp;gt;&lt;br /&gt;            &amp;lt;argument&amp;gt;${basedir}/src/main/webapp/WEB-INF/js/suite.js&amp;lt;/argument&amp;gt;&lt;br /&gt;        &amp;lt;/arguments&amp;gt;&lt;br /&gt;    &amp;lt;/configuration&amp;gt;&lt;br /&gt;&amp;lt;/plugin&amp;gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now, when you execute "mvn test", it will execute the test suite, and run your test cases. Try adding this line in your addTest.js, and make sure to update the expect() method call.&lt;br /&gt;&lt;br /&gt;equals(10,newAddition(5,0), "5 + 0 = 5");&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;making it:&lt;br /&gt;&lt;pre&gt;test("Adding numbers works", function() {&lt;br /&gt;     expect(3); //  &lt;-- change to 3.&lt;br /&gt;     ok(adder, "function exists");&lt;br /&gt;        equals(4, adder(2, 2), "2 + 2 = 4");&lt;br /&gt;        equals(10,adder(5,0), "5 + 0 = 5");&lt;br /&gt;            }&lt;br /&gt;);&lt;br /&gt;);&lt;br /&gt;&lt;/pre&gt;It will break your maven build and tell you:&lt;br /&gt;&lt;br /&gt;PASS: function exists&lt;br /&gt;PASS: &amp;lt;span class="test-message"&amp;gt;2 + 2 = 4&amp;lt;/span&amp;gt;&lt;br /&gt;FAILED: &amp;lt;span class="test-message"&amp;gt;5 + 0 = 5&amp;lt;/span&amp;gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15934471-829539867637820679?l=liminescence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://liminescence.blogspot.com/feeds/829539867637820679/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=15934471&amp;postID=829539867637820679' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/829539867637820679'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/829539867637820679'/><link rel='alternate' type='text/html' href='http://liminescence.blogspot.com/2010/11/tdd-with-javascript-jquery-qunit-and.html' title='TDD with javascript, JQuery, QUnit and Maven'/><author><name>liminescence</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-15934471.post-305447740760715975</id><published>2010-10-07T20:18:00.000-07:00</published><updated>2010-10-07T20:18:17.622-07:00</updated><title type='text'>Pragmatic unit testing with JUnit</title><content type='html'>Here's a great slides about JUnit, Hamcrest, Parameterized Testing, JUnit Rules (Verifier, Timeout, etc), and also about naming classes.&lt;br /&gt;&lt;br /&gt;&lt;div style="width:425px" id="__ss_5389315"&gt;&lt;strong style="display:block;margin:12px 0 4px"&gt;&lt;a href="http://www.slideshare.net/liminescence/pragmatic-unittestingwithj-unit" title="Pragmatic unittestingwithj unit"&gt;Pragmatic unittestingwithj unit&lt;/a&gt;&lt;/strong&gt;&lt;object id="__sse5389315" width="425" height="355"&gt;&lt;param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=pragmaticunittestingwithjunit-101007213444-phpapp02&amp;stripped_title=pragmatic-unittestingwithj-unit&amp;userName=liminescence" /&gt;&lt;param name="allowFullScreen" value="true"/&gt;&lt;param name="allowScriptAccess" value="always"/&gt;&lt;embed name="__sse5389315" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=pragmaticunittestingwithjunit-101007213444-phpapp02&amp;stripped_title=pragmatic-unittestingwithj-unit&amp;userName=liminescence" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;div style="padding:5px 0 12px"&gt;View more &lt;a href="http://www.slideshare.net/"&gt;presentations&lt;/a&gt; from &lt;a href="http://www.slideshare.net/liminescence"&gt;liminescence&lt;/a&gt;.&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15934471-305447740760715975?l=liminescence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://liminescence.blogspot.com/feeds/305447740760715975/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=15934471&amp;postID=305447740760715975' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/305447740760715975'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/305447740760715975'/><link rel='alternate' type='text/html' href='http://liminescence.blogspot.com/2010/10/pragmatic-unit-testing-with-junit.html' title='Pragmatic unit testing with JUnit'/><author><name>liminescence</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-15934471.post-1512322145866701071</id><published>2010-09-10T08:17:00.000-07:00</published><updated>2010-09-10T08:17:03.847-07:00</updated><title type='text'>MongoDB noSQL</title><content type='html'>Here's a great noSQL resource&lt;br /&gt;&lt;br /&gt;&lt;div style="width:425px" id="__ss_4880424"&gt;&lt;strong style="display:block;margin:12px 0 4px"&gt;&lt;a href="http://www.slideshare.net/scotthernandez/mongodb-tips-trick-and-hacks" title="MongoDB: tips, trick and hacks"&gt;MongoDB: tips, trick and hacks&lt;/a&gt;&lt;/strong&gt;&lt;object id="__sse4880424" width="425" height="355"&gt;&lt;param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=mongoseattle-tipstrickandhacks-100731203134-phpapp02&amp;stripped_title=mongodb-tips-trick-and-hacks" /&gt;&lt;param name="allowFullScreen" value="true"/&gt;&lt;param name="allowScriptAccess" value="always"/&gt;&lt;embed name="__sse4880424" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=mongoseattle-tipstrickandhacks-100731203134-phpapp02&amp;stripped_title=mongodb-tips-trick-and-hacks" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;div style="padding:5px 0 12px"&gt;View more &lt;a href="http://www.slideshare.net/"&gt;presentations&lt;/a&gt; from &lt;a href="http://www.slideshare.net/scotthernandez"&gt;Scott Hernandez&lt;/a&gt;.&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15934471-1512322145866701071?l=liminescence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://liminescence.blogspot.com/feeds/1512322145866701071/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=15934471&amp;postID=1512322145866701071' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/1512322145866701071'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/1512322145866701071'/><link rel='alternate' type='text/html' href='http://liminescence.blogspot.com/2010/09/mongodb-nosql.html' title='MongoDB noSQL'/><author><name>liminescence</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-15934471.post-5809618897988881543</id><published>2010-08-27T21:17:00.000-07:00</published><updated>2010-08-27T21:17:27.660-07:00</updated><title type='text'>implementing fastinfoset using CXF</title><content type='html'>I recently experimented with FastInfoset (FI)  and I got it working using CXF. FastInfoset is a standard that specifies a binary encoding format for XML Information set. It aims to provide more efficient serialization than text-base XML format.&lt;br /&gt;&lt;br /&gt;One can think of FI as gzip for XML, though FI aims to optimize both document size and processing performance, whereas gzip optimizes only the size. While the original formatting is lost, no information is lost in the conversion from XML to FI and back to XML.&lt;br /&gt;&lt;br /&gt;The java implementation of FI is available as part of GlassFish project. ( https://fi.dev.java.net/ ).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;1) In your pom.xml make sure you get the cxf version 2.2.7 or later (Thanks to Daniel and Igor for fixing the bug promptly) and add FI dependency:&lt;br /&gt;&lt;br /&gt;      &amp;lt;dependency&amp;gt;&lt;br /&gt;        &amp;lt;groupId&amp;gt;sun-fi&amp;lt;/groupId&amp;gt;&lt;br /&gt;        &amp;lt;artifactId&amp;gt;FastInfoset&amp;lt;/artifactId&amp;gt;&lt;br /&gt;        &amp;lt;version&amp;gt;1.2.2&amp;lt;/version&amp;gt;&lt;br /&gt;      &amp;lt;/dependency&amp;gt;&lt;br /&gt;&lt;br /&gt; ....&lt;br /&gt;&lt;br /&gt;    &amp;lt;repository&amp;gt;&lt;br /&gt;      &amp;lt;id&amp;gt;fastinfoset&amp;lt;/id&amp;gt;&lt;br /&gt;      &amp;lt;url&amp;gt;http://repository.jboss.org/maven2&amp;lt;/url&amp;gt;&lt;br /&gt;    &amp;lt;/repository&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2) in your service add this annotation.&lt;br /&gt;&lt;br /&gt;  @Produces({"application/xml","application/fastinfoset" })&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;3) in your configuration, add the interceptor, customTypes for the JAXBElementProvider and define it in your service:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;bean id="fastInfosetOutInterceptor" class="org.apache.cxf.interceptor.FIStaxOutInterceptor" /&amp;gt;&lt;br /&gt;  &amp;lt;bean id="fastInfosetInInterceptor" class="org.apache.cxf.interceptor.FIStaxInInterceptor" /&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;util:list id="customTypes"&amp;gt;&lt;br /&gt;    &amp;lt;value&amp;gt;application/xml&amp;lt;/value&amp;gt;&lt;br /&gt;    &amp;lt;value&amp;gt;application/fastinfoset&amp;lt;/value&amp;gt;&lt;br /&gt;  &amp;lt;/util:list&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;bean id="jaxbProvider" class="org.apache.cxf.jaxrs.provider.JAXBElementProvider"&amp;gt;&lt;br /&gt;    &amp;lt;property name="produceMediaTypes" ref="customTypes" /&amp;gt;&lt;br /&gt;    &amp;lt;property name="consumeMediaTypes" ref="customTypes" /&amp;gt;&lt;br /&gt;  &amp;lt;/bean&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;!-- JAX-RS endpoint configuration --&amp;gt;&lt;br /&gt;  &amp;lt;jaxrs:server id="sampleService" address="/"&amp;gt;&lt;br /&gt;    &amp;lt;jaxrs:serviceBeans&amp;gt;&lt;br /&gt;      &amp;lt;ref bean="sampleServiceBean" /&amp;gt;&lt;br /&gt;    &amp;lt;/jaxrs:serviceBeans&amp;gt;&lt;br /&gt;    &amp;lt;jaxrs:providers&amp;gt;&lt;br /&gt;      &amp;lt;ref bean="jaxbProvider" /&amp;gt;&lt;br /&gt;    &amp;lt;/jaxrs:providers&amp;gt;&lt;br /&gt;    &amp;lt;jaxrs:outInterceptors&amp;gt;&lt;br /&gt;      &amp;lt;ref bean="fastInfosetOutInterceptor" /&amp;gt;&lt;br /&gt;    &amp;lt;/jaxrs:outInterceptors&amp;gt;&lt;br /&gt;    &amp;lt;jaxrs:inInterceptors&amp;gt;&lt;br /&gt;      &amp;lt;ref bean="fastInfosetInInterceptor" /&amp;gt;&lt;br /&gt;    &amp;lt;/jaxrs:inInterceptors&amp;gt;&lt;br /&gt;  &amp;lt;/jaxrs:server&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;4) When testing, make sure you add Accept header variable with value “Application/fastinfoset”, before hitting the endpoint. (Using the browser will not work).&lt;br /&gt;&lt;br /&gt;TO TEST:&lt;br /&gt;curl -H "Accept: Application/fastinfoset" http://localhost:8080/services/samples/getSample?id=9&lt;br /&gt;SampleResponse{??version@1????Samples????ResponseMetadata???Service???Name?Foo????URL?http://foo????Hostname?&lt;br /&gt;&lt;br /&gt;You can also add a FireFox Add-on called “Poster”&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15934471-5809618897988881543?l=liminescence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://liminescence.blogspot.com/feeds/5809618897988881543/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=15934471&amp;postID=5809618897988881543' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/5809618897988881543'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/5809618897988881543'/><link rel='alternate' type='text/html' href='http://liminescence.blogspot.com/2010/08/implementing-fastinfoset-using-cxf.html' title='implementing fastinfoset using CXF'/><author><name>liminescence</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-15934471.post-1896265475873338330</id><published>2009-08-13T20:47:00.000-07:00</published><updated>2009-08-13T20:47:00.383-07:00</updated><title type='text'>Groovy Closure vs. javascript closure</title><content type='html'>Coming from a javascript and java background, i've learned to use the javascript closure to its full advantage, but when we used groovy (on grails) for our new system, I was surprise that the concept of closure in groovy is different.&lt;br /&gt;&lt;br /&gt;The definition of closure in groovy (from groovy.codehaus.org) is that, a groovy Closure is like a "code block" or a method pointer. It is a piece of code that is defined and then executed at a later point. It has some special properties like implicit variables, support for currying and support for free variables (which we'll see later on). We'll ignore the nitty gritty details for now (see the formal definition if you want those) and look at some simple examples.&lt;br /&gt;&lt;br /&gt;GROOVY CODE:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;def myclosure = { println "hello world!" }&lt;br /&gt;&lt;br /&gt;println "Executing the Closure:"&lt;br /&gt;myclosure()                          //prints "hello world!"&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The &lt;a href="http://liminescence.blogspot.com/2007/11/javascript-function-closure.html"&gt;javascript closure&lt;/a&gt;  is a functionality that marks a variable, that it will be use later. So even when it goes out of scope, the data is saved in the memory. Here's an example:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;function SayHelloTo(name) {&lt;br /&gt;  var greeting = 'Hello ' + name;&lt;br /&gt;  var display = function() { alert(greeting); }&lt;br /&gt;  return display;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;var greet = new SayHelloTo("Aidan Thor");&lt;br /&gt;greet();&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This is simply defining a method with a local variable called "greeting" and another method inside called display, then it returns that method.&lt;br /&gt;&lt;br /&gt;When you instantiate "SayHelloTo", and execute it ( "greet()"), you would think that it will throw an error, because "greeting" is out of scope, but actually it will not throw an error, because the method created a closure (knowing that "greeting" will be called later).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15934471-1896265475873338330?l=liminescence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://liminescence.blogspot.com/feeds/1896265475873338330/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=15934471&amp;postID=1896265475873338330' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/1896265475873338330'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/1896265475873338330'/><link rel='alternate' type='text/html' href='http://liminescence.blogspot.com/2009/08/groovy-closure-vs-javascript-closure.html' title='Groovy Closure vs. javascript closure'/><author><name>liminescence</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-15934471.post-6962862593999477703</id><published>2009-07-29T09:53:00.000-07:00</published><updated>2009-08-09T11:32:14.068-07:00</updated><title type='text'>MVP with GWT</title><content type='html'>MVP stands for Model View Presenter. It is a front end architecture that separates your model (data object) and the view via presenter.&lt;br /&gt;&lt;br /&gt;A detailed description can be found in this link (http://www.martinfowler.com/eaaDev/uiArchs.html) written by Martin Fowler. The post is focused on why it's appropriate to use MVP than MVC in GWT project, and how to implement it.&lt;br /&gt;&lt;br /&gt;It is tough to decide whether to use MVP or MVC, because both designs solve the problem. One good example that separates the two is that with MVC, it's always the controller's responsibility to handle keyboard and mouse events, while with MVP the GUI component itself initially handle the user's input, and delegate the interpretation of that input to the presenter. (Consider Struts or Spring MVC vs. Flex/Flash ).&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_CoP9RArFn-s/SnCCmVy6zhI/AAAAAAAAEPs/KaUrKlxiips/s1600-h/mvcPattern.png"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 205px;" src="http://2.bp.blogspot.com/_CoP9RArFn-s/SnCCmVy6zhI/AAAAAAAAEPs/KaUrKlxiips/s320/mvcPattern.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5363930751395614226" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;A good friend of mine said that MVP is particularly interesting in the context of GWT when doing TDD (Test Driven Development) or just thorough testing all round. The reason is that testing widgets and widget interactions is generally slow because you need to create a UI environment (hosted mode or web mode usually) to run your tests in. By moving your application logic into the Presenter, you end up with code that can be tested fairly fast (with mock widgets). Since the widgets are simple there's less to go wrong in this harder/slower to test area.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_CoP9RArFn-s/SnCC6G3roRI/AAAAAAAAEP0/ANAvR2B-HO4/s1600-h/mvpPattern.png"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 319px;" src="http://2.bp.blogspot.com/_CoP9RArFn-s/SnCC6G3roRI/AAAAAAAAEP0/ANAvR2B-HO4/s320/mvpPattern.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5363931090986443026" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;In my opinion, the richer your client framework is (e.g. Flex/Flash, Silverlight ) the more you should favor MVP.&lt;br /&gt;&lt;br /&gt;Here are the steps you need to do in building MVP compliant project. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;1) Define a Page object. The page object represents a web page. You can even make it more granular by defining a Form object.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;br /&gt;public class Page extends Composite implements PageView {&lt;br /&gt;   private presenter;&lt;br /&gt;&lt;br /&gt;   public Page() {&lt;br /&gt;        presenter = new PagePresenter(this);&lt;br /&gt;        TextArea ta = new TextArea();&lt;br /&gt;        ta.setCharacterWidth(80);&lt;br /&gt;        ta.setVisibleLines(50);&lt;br /&gt;        add(ta);&lt;br /&gt;&lt;br /&gt;        Button b = new Button("Comment", new ClickHandler() {&lt;br /&gt;            public void onClick(ClickEvent event) {&lt;br /&gt;                presenter.submitComment(ta.getValue());&lt;br /&gt;            }&lt;br /&gt;        });&lt;br /&gt;        add(b);&lt;br /&gt;&lt;br /&gt;   } &lt;br /&gt;    //This method is defined in PageView, and its being called&lt;br /&gt;    //by the presenter.&lt;br /&gt;     public void updateView(String text) {&lt;br /&gt;        Label commentLabel = new Label(text);&lt;br /&gt;        add(commentLabel);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Your page contains the presenter object, and it implements PageView.&lt;br /&gt;&lt;br /&gt;2) Define your PageView interface. The PageView acts as a conduit between Page and the Presenter. &lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public interface PageView {&lt;br /&gt;&lt;br /&gt;    public void updateView(String text);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;3) Define your Presenter object. The presenter is the class that contains all the business logic. It has reference to the services. &lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public class PagePresenter {&lt;br /&gt;&lt;br /&gt;    private PageView pageView;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    public PagePresenter(PageView pageView ) {&lt;br /&gt;        this.pageView = pageView;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    //You can use HasClickHandlers, Hastext or HasHTML, but I prefer just passing the&lt;br /&gt;    // data, if you dont need any other functionalities.&lt;br /&gt;    public void submitComment(String comment) {&lt;br /&gt;        if(comment != null) {&lt;br /&gt;            service.submitComment(comment);&lt;br /&gt;            //Do service calls here. When done, call&lt;br /&gt;            //pageView.updateView()&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15934471-6962862593999477703?l=liminescence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://liminescence.blogspot.com/feeds/6962862593999477703/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=15934471&amp;postID=6962862593999477703' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/6962862593999477703'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/6962862593999477703'/><link rel='alternate' type='text/html' href='http://liminescence.blogspot.com/2009/07/mvp-with-gwt.html' title='MVP with GWT'/><author><name>liminescence</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_CoP9RArFn-s/SnCCmVy6zhI/AAAAAAAAEPs/KaUrKlxiips/s72-c/mvcPattern.png' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-15934471.post-7933625989694157270</id><published>2009-05-31T18:32:00.000-07:00</published><updated>2009-05-31T18:39:24.139-07:00</updated><title type='text'>what's on GWT2.0 ??</title><content type='html'>Here are a few things that I was able to capture about GWT 2.0 during google i/o 2009.&lt;br /&gt;&lt;br /&gt;with GWT 2.0, they have added RunAsync functionality. RunAsync gives you the ability to split your javascript into chunks of files. Which allows you, not to load the entire JS from the start. &lt;br /&gt;&lt;br /&gt;They have added ClientBundle functionality. ClientBundle includes ImageBundle, ResourceBundle and CssResource (The killer feature). ImageBundle combines individual images into a single image in multiple dimensions. Simply lining up images left-to-right to create an image strip is sufficient. This will make fewer HTTP round-trips. This is what the code looks like:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Interface MyBundle extends ClientBundle {&lt;br /&gt;    public static final MyBundle INSTANCE = GWT.create(MyBundle.class);&lt;br /&gt;&lt;br /&gt;    @Source(“smiley.gif”)&lt;br /&gt;    ImageResource smileyImage();&lt;br /&gt;&lt;br /&gt;    @Source(“frowny.png”)&lt;br /&gt;    ImageResource frownlyImage();&lt;br /&gt;&lt;br /&gt;    @Source(“app_config.xml”)&lt;br /&gt;    TextResource appConfig();&lt;br /&gt;&lt;br /&gt;   @Source(“wordlist.txt”)&lt;br /&gt;    ExternalTextResource wordlist();&lt;br /&gt;&lt;br /&gt;  @Source("my.css")&lt;br /&gt;  public CssResource css();&lt;br /&gt;&lt;br /&gt;  @Source("config.xml")&lt;br /&gt;  public TextResource initialConfiguration();&lt;br /&gt;&lt;br /&gt;  @Source("manual.pdf")&lt;br /&gt;  public DataResource ownersManual();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;This is how you would use it:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;  Window.alert(MyResources.INSTANCE.css().getText());&lt;br /&gt;  Frame myFrame = new Frame(MyResources.INSTANCE.ownersManual().getURL());&lt;br /&gt;TextResource configs = MyBundle.INSTANCE. InitialConfiguration();&lt;br /&gt;String configXml = configs.getText();&lt;br /&gt;Document doc = XMLParser.parse(configXml);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The CSSResource compiles  CSS with an enhanced syntax. It defines and uses constants in CSS. E.g.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;@define myBorder 8px;&lt;br /&gt;@define myColor #FDD;&lt;br /&gt;.error-border { border:myBorder solid:myColor; }&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;It also uses conditions for user agent, locale or anything.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;/* Runtime evaluation in a static context */&lt;br /&gt;@if (com.module.Foo.staticBooleanFunction()) {&lt;br /&gt;  ... css rules ...&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/* Compile-time evaluation */&lt;br /&gt;@if &lt;deferred-binding-property&gt; &lt;space-separated&gt; {&lt;br /&gt;  ... css rules ...&lt;br /&gt;}&lt;br /&gt;@if user.agent safari gecko1_8 { ... }&lt;br /&gt;@if locale en { ... }&lt;br /&gt;&lt;br /&gt;/* Negation is supported */&lt;br /&gt;@if !user.agent ie6 opera { ... }&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;GWT 2.0 have updated sets of Panel that fix the Layout. The example given is the new and improve DockPanel. It doesn’t run javascript during resize. Constraints-based layout similar to Cocoa on OSX.&lt;br /&gt;&lt;br /&gt;GWT2.0 have added option in the compiler is: -XdisableClassMetaData. Calling  obj.getClass() or clazz.getName() forces class objects and their names to be generated into javascript. It has Size, speed and obscurity benefits.&lt;br /&gt;&lt;br /&gt;GWT2.0 added options in the compiler is: -XdisableCastChecking. Nobody actually catches ClassCastException in app code. (I hope you are not doing this):&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;Void makeItQuak(Animal animal) {&lt;br /&gt;Try {&lt;br /&gt;    ((Quaker) animal).quak();&lt;br /&gt;}catch(ClassCastException c ) {&lt;br /&gt;    Window.alert(“doesn’t quak!”);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The above example generates a call like this (compiled JS)&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;DynamicCast(animal, 2).quak();&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;But when the flag is turned on, you only get this:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;animal.quak();&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;How does this help you? In real-world (and very large) google app:&lt;br /&gt;-1% script size reduction&lt;br /&gt;-10% speed improvement in performance-sensitive code.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;GWT have added RPC blacklist. Tell the RPC subsystem to skip types  that you know aren’t ever sent across the wire:&lt;br /&gt;&lt;br /&gt;&amp;lt;extend-configuration-property name="”rpc.blacklist”" value="”com.example.client.WidgetList”"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;-Added Client side stackTrace on some browsers.&lt;br /&gt;Throwable#getStackTrace() actually does something sometimes )&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;-Added interfaces on JavaScript Overlay Types.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15934471-7933625989694157270?l=liminescence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://liminescence.blogspot.com/feeds/7933625989694157270/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=15934471&amp;postID=7933625989694157270' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/7933625989694157270'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/7933625989694157270'/><link rel='alternate' type='text/html' href='http://liminescence.blogspot.com/2009/05/whats-on-gwt20.html' title='what&apos;s on GWT2.0 ??'/><author><name>liminescence</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-15934471.post-8615205793558261695</id><published>2009-05-20T09:50:00.000-07:00</published><updated>2009-05-20T09:59:57.093-07:00</updated><title type='text'>adding whitelist or blacklist option in maven GWT</title><content type='html'>If you are using Maven GWT plugin and find yourself lost in adding the whitelist or blacklist option in the configuration, do not worry, because it is not supported.&lt;br /&gt;&lt;br /&gt;At first, I thought it's just another configuration tag, so i added:&lt;br /&gt;&lt;br /&gt;&amp;lt;configuration&gt;&lt;br /&gt;&amp;lt;whitelist&gt;&amp;lt;/whitelist&gt;&lt;br /&gt;&lt;br /&gt;But it didn't work. The solution is to add it in the runTarget tag. like this:&lt;br /&gt;&lt;br /&gt;    &amp;lt;properties&gt;&lt;br /&gt;        &amp;lt;whitelist&gt;" ^http[:][/][/]sample[.]net"&amp;lt;/whitelist&gt;&lt;br /&gt;    &amp;lt;/properties&gt;&lt;br /&gt;&lt;br /&gt; &amp;lt;runtarget&gt;com.sample.app/Sample.html -whitelist ${whitelist}&amp;lt;/runtarget&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I hope this helps.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15934471-8615205793558261695?l=liminescence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://liminescence.blogspot.com/feeds/8615205793558261695/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=15934471&amp;postID=8615205793558261695' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/8615205793558261695'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/8615205793558261695'/><link rel='alternate' type='text/html' href='http://liminescence.blogspot.com/2009/05/adding-whitelist-or-blacklist-option-in.html' title='adding whitelist or blacklist option in maven GWT'/><author><name>liminescence</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-15934471.post-664967677974196472</id><published>2009-05-18T20:52:00.000-07:00</published><updated>2009-05-19T08:16:08.229-07:00</updated><title type='text'>4 steps to add facebook connect (xfbml) to google web toolkit (GWT) app</title><content type='html'>Adding facebook connect (XFBML) to your Google web toolkit (GWT) application&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This is a fast track tips on how to add facebook connect to your GWT based application.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Step 1: add a facebook application.&lt;br /&gt;If you don't have the facebook application. Just login to facebook and search for the word "developer" in the search field of the menu bar.&lt;br /&gt;&lt;br /&gt;http://screencast.com/t/43OHbcLl9&lt;br /&gt;&lt;br /&gt;select developer and add/install it. Select "Set Up New Application" , select an application name, select agree then save changes.&lt;br /&gt;The next page is the application configuration. take note of your API Key, because you will be using it. In the left menu bar, select "Connect".&lt;br /&gt;in the connect URL, add your URL. (e.g. http://localhost:8888/com.sample.facebookApp/ ). localhost will work, because facebook connect will not&lt;br /&gt;ping your server.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Step 2: adding the facebook connect library&lt;br /&gt;open your .html file and add the facebook connect name space and the javscript library.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml"&gt;&lt;br /&gt;&lt;br /&gt;...&lt;br /&gt;&lt;br /&gt;&amp;lt;body&gt;&lt;br /&gt;&amp;lt;/body&gt;&lt;br /&gt;&amp;lt;script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript"&gt;&lt;br /&gt;&lt;br /&gt;Facebook said that its faster to add the script tab below the closing body tag.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Step 3: add Cross Domain Communication Channel in  your GWT app.&lt;br /&gt;&lt;br /&gt;create a file called "xd_receiver.html" or download the file from http://www.somethingtoputhere.com/xd_receiver.htm and save it to the&lt;br /&gt;public diretory of your google web toolkit app. You will reference this file later in your code.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Step 4: adding the code in your EntryPoint.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;a) Add a static final String called FB_API_KEY and XD_RECEIVER_URL.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; public static final String FB_API_KEY = "YOUR_KEY_FROM_FROM_YOUR_FACEBOOK_APP";&lt;br /&gt; public static final String XD_RECEIVER_URL = "/xd_receiver.html";&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;b) build init method. This method initialize the facebook connect in your app. You should call this method in your onModuleLoad()&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;  private static native String initFacebook(String apiKey, String xd_receiver_url)&lt;br /&gt; /*-{&lt;br /&gt;     $wnd.FB_RequireFeatures(["XFBML"], function(){&lt;br /&gt;     $wnd.FB.Facebook.init(apiKey, xd_receiver_url); &lt;br /&gt;     });&lt;br /&gt; }-*/;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;c) Define the loginHandler. The login handler gets executed after a user login has login to facebook connect. This method should be called&lt;br /&gt;in your onModuleLoad().&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;  private native void defineFbLoginHandler() /*-{&lt;br /&gt;     var fbConn = this;&lt;br /&gt;     $wnd.facebookConnectLogin = function() {&lt;br /&gt;    //The "@com.sample.facebookApp.XfbmlPrototype" is the fully qualified name of your GWT app EntryPoint.&lt;br /&gt;    //The renderFriendsList is the method that will be executed after you login. (aka. login handler).&lt;br /&gt;&lt;br /&gt;     @com.sample.facebookApp.XfbmlPrototype::SESSION_KEY =  $wnd.FB.Facebook.apiClient.get_session().session_key;&lt;br /&gt;     fbConn.@com.sample.facebookApp.XfbmlPrototype::onLoginHandler()();&lt;br /&gt; }&lt;br /&gt; }-*/;&lt;br /&gt;&lt;br /&gt; public void onLoginHandler() {&lt;br /&gt;     Window.alert("Login is successful!!");&lt;br /&gt;     //You can start adding XFBML comments here, like welcome notes, friend selector, etc.&lt;br /&gt; }&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;d) define a parseDomTree method. Since facebook XFBML is not standard, you need to execute a method for them to render.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;  private static native void parseDomTree() /*-{&lt;br /&gt;     $wnd.FB.XFBML.Host.parseDomTree();&lt;br /&gt;  }-*/;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;e) define your login button.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt; private Widget makeFbLoginButton() {&lt;br /&gt;     String fblogin = "&lt;fb:login-button onlogin="\&amp;quot;facebookConnectLogin()\&amp;quot;"&gt;&lt;/fb:login-button&gt;";&lt;br /&gt;     HTML html = new HTML(fblogin);&lt;br /&gt;     return html;&lt;br /&gt; }&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;As you can see, in the onlogin we point it to "facebookConnectLogin()". This method is define in defineFbLoginHandler() method we created in step c.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To sum it all up, your onModuleLoad() method will look like this:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public void onModuleLoad() {&lt;br /&gt; FlowPanel loginPanel  = new FlowPanel();&lt;br /&gt; RootPanel.get().add(loginPanel);&lt;br /&gt;&lt;br /&gt; Widget fbLoginButton = makeFbLoginButton();&lt;br /&gt; loginPanel.add(fbLoginButton);&lt;br /&gt;&lt;br /&gt; initFacebook(FB_API_KEY, XD_RECEIVER_URL);&lt;br /&gt; defineFbLoginHandler();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Take note that facebook widgets doesn't render in Google Hosted mode. I tried DeferredCommand but it doesn't work. Make sure to compile and test it in a&lt;br /&gt;browser.&lt;br /&gt;&lt;br /&gt;Here's the link to all the facebook connect tags that are available:  http://wiki.developers.facebook.com/index.php/XFBML&lt;br /&gt;&lt;br /&gt;These are the books that I recommend:&lt;br /&gt; 1) &lt;a type="amzn" asin="1933988290"&gt;GWT in Practice&lt;/a&gt;&lt;br /&gt; 2) &lt;a type="amzn" asin="1933988231"&gt;GWT in Action&lt;/a&gt; &lt;br /&gt; 3) &lt;a type="amzn" asin="0321501969"&gt;Google Web Toolkit Applications (Paperback)&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15934471-664967677974196472?l=liminescence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://liminescence.blogspot.com/feeds/664967677974196472/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=15934471&amp;postID=664967677974196472' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/664967677974196472'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/664967677974196472'/><link rel='alternate' type='text/html' href='http://liminescence.blogspot.com/2009/05/4-steps-to-add-facebook-connect-xfbml.html' title='4 steps to add facebook connect (xfbml) to google web toolkit (GWT) app'/><author><name>liminescence</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-15934471.post-4810221456838377891</id><published>2009-02-16T14:15:00.000-08:00</published><updated>2009-04-23T10:00:28.817-07:00</updated><title type='text'>busy life</title><content type='html'>It's been a year since my last post. I've been very busy working on a project that involves GWT, Grails and Android. Part of it, is that I got so busy with my personal life too.&lt;br /&gt;&lt;br /&gt;With regards to the technology I'm using, it seems to me that there are lots of documentations, tutorials in the internet available already. So it doesn't make sense for me to post some introduction on these technologies since they can easily be found.&lt;br /&gt;&lt;br /&gt;Although, I will post some methodology and technique that I find interesting when I get a chance.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15934471-4810221456838377891?l=liminescence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://liminescence.blogspot.com/feeds/4810221456838377891/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=15934471&amp;postID=4810221456838377891' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/4810221456838377891'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/4810221456838377891'/><link rel='alternate' type='text/html' href='http://liminescence.blogspot.com/2009/02/busy-life.html' title='busy life'/><author><name>liminescence</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-15934471.post-7083442026950886731</id><published>2008-02-04T08:26:00.000-08:00</published><updated>2008-02-04T08:59:25.331-08:00</updated><title type='text'>Wicket IndicatingOrderByBorder component</title><content type='html'>Wicket have form components that displays a busy icon (like progress bar) whenever a button is clicked. They are the IndicatingAjaxButton, IndicatingAjaxFallbackLink, IndicatingAjaxLink and IndicatingAjaxSubmitButton objects.&lt;br /&gt;&lt;br /&gt;What is not provided though is the indicating orderByBorder component. What is OrderByBorder in the first place? It's a component to use, if you want to sort your SortableDataProvider component.&lt;br /&gt;&lt;br /&gt;Using the api OrderByBorder does the job well if your data is not big. But if you are sorting huge amount of data, its better to "Ajaxify" it. (For more information about Sorting Data View you can read it here: http://wicketstuff.org/wicket13/repeater/ ).&lt;br /&gt;&lt;br /&gt;Here's the customize code for making your own Ajax OrderByBorder:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;class IndicatingOrderByBorder extends AjaxFallbackOrderByBorder implements IAjaxIndicatorAware {&lt;br /&gt;&lt;br /&gt;    private final WicketAjaxIndicatorAppender indicatorAppender = new WicketAjaxIndicatorAppender();&lt;br /&gt;    private Form contactListForm;&lt;br /&gt;&lt;br /&gt;    public IndicatingOrderByBorder(String id, String property, ISortStateLocator&lt;br /&gt;            stateLocator, DataView dataView, Form contactListForm) {&lt;br /&gt; super(id, property, stateLocator);&lt;br /&gt; this.contactListForm = contactListForm;&lt;br /&gt; add(indicatorAppender);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    @Override&lt;br /&gt;    protected void onAjaxClick(AjaxRequestTarget target) { &lt;br /&gt;        target.addComponent(contactListForm); &lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public String getAjaxIndicatorMarkupId() { &lt;br /&gt;        return indicatorAppender.getMarkupId(); &lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;To learn that basic, you can read these books:&lt;br /&gt; 1) &lt;a type="amzn" asin="1590597222"&gt;Pro Wicket&lt;/a&gt;&lt;br /&gt; 2) &lt;a type="amzn" asin="1932394982"&gt;Wicket In Action&lt;/a&gt; (release date: July 2008)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15934471-7083442026950886731?l=liminescence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://liminescence.blogspot.com/feeds/7083442026950886731/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=15934471&amp;postID=7083442026950886731' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/7083442026950886731'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/7083442026950886731'/><link rel='alternate' type='text/html' href='http://liminescence.blogspot.com/2008/02/wicket-indicatingorderbyborder.html' title='Wicket IndicatingOrderByBorder component'/><author><name>liminescence</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-15934471.post-4080128776882665524</id><published>2007-12-28T07:45:00.000-08:00</published><updated>2007-12-28T07:46:11.870-08:00</updated><title type='text'>Books I recommend</title><content type='html'>&lt;object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="Player_8ee66d40-f7d7-403e-bbbd-8dad3272e80a" width="430px" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab" height="324px"&gt; &lt;param value="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&amp;MarketPlace=US&amp;ID=V20070822%2FUS%2Fwidgetsamazon-20%2F8003%2F8ee66d40-f7d7-403e-bbbd-8dad3272e80a&amp;Operation=GetDisplayTemplate" name="movie"/&gt;&lt;param value="high" name="quality"/&gt;&lt;param value="#FFFFFF" name="bgcolor"/&gt;&lt;param value="always" name="allowscriptaccess"/&gt;&lt;embed quality="high" allowscriptaccess="always" align="middle" type="application/x-shockwave-flash" height="324px" src="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&amp;MarketPlace=US&amp;ID=V20070822%2FUS%2Fwidgetsamazon-20%2F8003%2F8ee66d40-f7d7-403e-bbbd-8dad3272e80a&amp;Operation=GetDisplayTemplate" id="Player_8ee66d40-f7d7-403e-bbbd-8dad3272e80a" bgcolor="#ffffff" width="430px" name="Player_8ee66d40-f7d7-403e-bbbd-8dad3272e80a"/&gt; &lt;/embed&gt;&lt;/object&gt; &lt;noscript&gt;&lt;a href="http://ws.amazon.com/widgets/q?ServiceVersion=20070822&amp;MarketPlace=US&amp;ID=V20070822%2FUS%2Fwidgetsamazon-20%2F8003%2F8ee66d40-f7d7-403e-bbbd-8dad3272e80a&amp;Operation=NoScript"&gt;Amazon.com Widgets&lt;/a&gt;&lt;/noscript&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15934471-4080128776882665524?l=liminescence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://liminescence.blogspot.com/feeds/4080128776882665524/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=15934471&amp;postID=4080128776882665524' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/4080128776882665524'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/4080128776882665524'/><link rel='alternate' type='text/html' href='http://liminescence.blogspot.com/2007/12/books-i-recommend.html' title='Books I recommend'/><author><name>liminescence</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-15934471.post-1157880706743088775</id><published>2007-12-05T11:13:00.000-08:00</published><updated>2007-12-05T11:32:52.027-08:00</updated><title type='text'>Wicket HTML Table implementation</title><content type='html'>This is how you implement an html table using Wicket framework. For those of you who are new to wicket, Wicket is a component-oriented Java web application framework. It’s very different from action-/request-based frameworks like Struts, WebWork, or Spring MVC where form submission ultimately translates to a single action. In Wicket, a user action typically triggers an event on one of the form components, which in turn responds to the event through strongly typed event listeners. (See wicket.apache.org).&lt;br /&gt;&lt;br /&gt;This example shows how you render an html table that display person's data. (e.g. first name, last name and age ).&lt;br /&gt;&lt;br /&gt;1) First you need to define your HTML.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;form wicket:id="personListForm"&gt;&lt;br /&gt;  &amp;lt;table width="100%" border="0" &gt;&lt;br /&gt;    &amp;lt;tr&gt;                    &lt;br /&gt;   &amp;lt;th&gt;First Name&amp;lt;/th&gt;&lt;br /&gt;   &amp;lt;th&gt;Last Name&amp;lt;/th&gt;&lt;br /&gt;   &amp;lt;th&gt;Email Address&amp;lt;/th&gt;&lt;br /&gt;    &amp;lt;/tr&gt;&lt;br /&gt;    &amp;lt;tr wicket:id="personList"&gt;                    &lt;br /&gt;   &amp;lt;td wicket:id="firstName"&gt;[first]&amp;lt;/td&gt;&lt;br /&gt;   &amp;lt;td wicket:id="lastName"&gt;[last]&amp;lt;/td&gt;&lt;br /&gt;   &amp;lt;td wicket:id="email"&gt;[email]&amp;lt;/td&gt;&lt;br /&gt;    &amp;lt;/tr&gt;&lt;br /&gt;  &amp;lt;/table&gt;&lt;br /&gt;&amp;lt;/form&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2) In your java code where you have to define the form. You will need the following:&lt;br /&gt;&lt;br /&gt;a) Define a dataProvider - You can implement the IDataProvider interface, and define its functions. Normally, the IDataProvider is an object&lt;br /&gt;that has access to your backend service.&lt;br /&gt;&lt;br /&gt;b) Define a model - You can implement IModel, or you can use the subclasses available. ContactDetachableModel, DetachableContactModel, StringResourceModel.&lt;br /&gt;Why can't we just use the POJO directly from the backend service? Well, wicket will sometimes serialized the object to save memory when you move from one page to the other, and go back. All&lt;br /&gt;object that you will need to display, have to be wrapped/implemented IModel.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;//This is the POJO that you retrieve from your service.&lt;br /&gt;class Person implements Serializable {&lt;br /&gt;  private static final long serialVersionUID = 5934872279937101444L;&lt;br /&gt;  private String firstName;&lt;br /&gt;  private String lastName;&lt;br /&gt;  private String email;&lt;br /&gt; &lt;br /&gt;  //access methods here.&lt;br /&gt;  //getters and setters not define.&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;A detachable modelin Wicket is a model that can get rid of a large portion of its state to reduce the amount of memory it takes up and to make it cheaper to serialize when replicating it in a clustered environment. When an object is in the detached state, it contains only somevery minimal nontransient state such as an object ID that can be used to reconstitute the object from a persistent data store. When a detached object is attached, some logic in the object uses this minimal state to reconstruct the full state of the object. This typically involves restoring fields from persistent storageusing a database persistence technology&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;//This is the Wicket Model &lt;br /&gt;public class DetachablePersonModel extends LodableDechableModel {&lt;br /&gt;  //make it transient, so that it will not get serialized.&lt;br /&gt;  private transient Person person;&lt;br /&gt;  &lt;br /&gt;  @Override&lt;br /&gt;  public Object getObject() {&lt;br /&gt;    return this.person;&lt;br /&gt;  }&lt;br /&gt;  ...&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public class PersonDataProvider implements IDataProvider {&lt;br /&gt;&lt;br /&gt;  public Iterator&amp;lt;Person&gt; iterator(int first, int count) {&lt;br /&gt;   Iterator&amp;lt;Person&gt; iterator = null;&lt;br /&gt;   iterator = getPersonService().retrieveEntirePerson(first,count);&lt;br /&gt;   return iterator;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;  //Your model is used here.&lt;br /&gt;  public IModel model(Object object) { return new DetachablePersonModel((Person)object); }&lt;br /&gt; &lt;br /&gt;  public int size() {&lt;br /&gt;    int size = 0;&lt;br /&gt;    try {&lt;br /&gt;      size =  getPersonService().retrieveEntirePerson().size();&lt;br /&gt;    } catch (ServiceException e) { //implement exception here.}&lt;br /&gt; return size;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;c) Define a DataView - Data views aim to make it very simple to populate your repeating view from a database by utilizing IDataProvider to act as an interface between the database and the dataview.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Normally, you will implement DataView as an anonymous class, or an inner class, because the chances of reusing the class is minimal.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;//define as inner class&lt;br /&gt;&lt;br /&gt;private class PersonDataView extends DataView {&lt;br /&gt;&lt;br /&gt;...&lt;br /&gt;  @Override&lt;br /&gt;  protected void populateItem(Item item) { &lt;br /&gt;    Person person = (Person) item.getModelObject();&lt;br /&gt; item.setModel(new CompoundPropertyModel(person));&lt;br /&gt; item.add(new Label("firstName"));&lt;br /&gt; item.add(new Label("lastName"));&lt;br /&gt; item.add(new Label("emal"));&lt;br /&gt;  &lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;3) This is how you would define it in your page.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;final Form persontListForm = new Form("personListForm");&lt;br /&gt;final PersonDataProvider personDataProvider = new PersonDataProvider();&lt;br /&gt;final DataView personDataView = new PersonDataView("personList", personDataProvider);&lt;br /&gt;personDataView.setItemsPerPage(5);&lt;br /&gt;persontListForm.add(contactListDataView);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;For information regarding the objects used in this example visit:&lt;br /&gt;&lt;br /&gt;http://people.apache.org/~tobrien/wicket/apidocs/index.html&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Main wicket site:&lt;br /&gt;&lt;br /&gt;wicket.apache.org&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15934471-1157880706743088775?l=liminescence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://liminescence.blogspot.com/feeds/1157880706743088775/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=15934471&amp;postID=1157880706743088775' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/1157880706743088775'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/1157880706743088775'/><link rel='alternate' type='text/html' href='http://liminescence.blogspot.com/2007/12/wicket-html-table-implementation.html' title='Wicket HTML Table implementation'/><author><name>liminescence</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-15934471.post-2487914316160030816</id><published>2007-11-20T20:48:00.000-08:00</published><updated>2007-11-25T14:54:05.257-08:00</updated><title type='text'>JavaScript Function Closure</title><content type='html'>Coming from a C++/JAVA background, it was hard for me to assimilate the concept of Function Closure in JavaScript. Now that I understand it, I'd like to share it here with you. Seriously, it's best explained by example than description. Here's an example.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;var thingsToDo = {};&lt;br /&gt;&lt;br /&gt;function initializeThingsToDo() {&lt;br /&gt;  var food= {&lt;br /&gt;      name: "Ramen",&lt;br /&gt;      type: "Tokatsu"&lt;br /&gt;  };&lt;br /&gt;  thingsToDo.eat = function() {&lt;br /&gt;      alert("I'm going to eat: " + food.name);&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;//Execute&lt;br /&gt;initializeThingsToDo();&lt;br /&gt;thingsToDo.eat();&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Okay, what did I do here? First, I created an empty (global) Object called "thingsToDo", then I added a global function called "initializeThingsToDo". Inside this function I defined food object. I referenced the global object "thingsToDo" and  attached a dynamic function called "eat" in the object.&lt;br /&gt;&lt;br /&gt;After the code definitions, I ran the global function initializeThingsToDo, and called the method thingsToDo.eat().&lt;br /&gt;&lt;br /&gt;I know you would say that this is crazy because when I ran thingsToDo.eat(), the method uses the food object but it's already out of scope.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;//Execute&lt;br /&gt;initializeThingsToDo();&lt;br /&gt;thingsToDo.eat(); // When this is executed,&lt;br /&gt;                 // the food object is already out of scope!&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Na ah?! Not in JavaScript. You see, when you run the code, JavaScript will create a closure to the food object. After that, it saves it in the memory. The interpreter knows that it will be used for later. (It doesn't deallocate the food object in the memory. )&lt;br /&gt;&lt;br /&gt;The power of function closure is well executed when you use AJAX. When you define your AJAX callback function, it gets called asynchronously. It creates a closure and  call the objects/functions when it's ready.&lt;br /&gt;&lt;br /&gt;If you are not familiar with JavaScript Object and Functions, you can read these links:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://liminescence.blogspot.com/2005/11/aesthetic-mirth.html"&gt;Java vs. JavaScript object&lt;/a&gt;&lt;br /&gt;&lt;a href="http://liminescence.blogspot.com/2007/10/javascript-using-prototype.html"&gt; JavaScript usign Prototype.js&lt;/a&gt;&lt;br /&gt;&lt;a href="http://liminescence.blogspot.com/2007/11/javascript-functionprocedure-using.html"&gt;  JavaScript Function&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15934471-2487914316160030816?l=liminescence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://liminescence.blogspot.com/feeds/2487914316160030816/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=15934471&amp;postID=2487914316160030816' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/2487914316160030816'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/2487914316160030816'/><link rel='alternate' type='text/html' href='http://liminescence.blogspot.com/2007/11/javascript-function-closure.html' title='JavaScript Function Closure'/><author><name>liminescence</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-15934471.post-7068822933480188990</id><published>2007-11-05T07:19:00.000-08:00</published><updated>2007-11-05T09:44:26.536-08:00</updated><title type='text'>JavaScript function/procedure using Prototype.js framework</title><content type='html'>Prior to web2.0 and AJAX, I only use javascript for front end validation and some front end calculations.&lt;br /&gt;&lt;br /&gt;When I started using Prototype.js, I learned a lot more about javaScript, particulary with functions/procedure.&lt;br /&gt;&lt;br /&gt;If you are a java programmer, you probably write functions the traditional way.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;e.g.&lt;br /&gt;function sayHello() {&lt;br /&gt;return "hello there!";&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;But there's an alternative. You can define functions this way:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;var sayHello = function() {&lt;br /&gt;return "hello there!";&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Here we declared a global variable called sayHello, to which we have assigned a value. The value is, in this case, an anonymous function defined using the function() keyword.&lt;br /&gt;&lt;br /&gt;Take note, that the effect of both ways are the same. (The second one is similar to C/C++ pointer to a function. wink-wink ).&lt;br /&gt;&lt;br /&gt;In JavaScript, a Function is a first-class object that exists in its own right, unlike the method of an object in an object-oriented language.&lt;br /&gt;&lt;br /&gt;To give an example about Function being a first-class object, let me explain about how to call the functions.&lt;br /&gt;&lt;br /&gt;To call a function, you would use parenthesis.&lt;br /&gt;e.g.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;sayHello();&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;if you dont put the "()" it will return a reference to a function. You use that if you want to assign another name to call your function.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;var sayHelloFxn = sayHello;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;How does javascript function deal with input parameters? Consider this example&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;var animalCreator = function(species,color) {&lt;br /&gt;return { species:species, color:color }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;I created a function that returns a object (HashMap or associative array depending on how you want to call it ). What happened if I do call it like this?&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;1) var whale = animalCreator("mammal" );&lt;br /&gt;2) var frog = animalCreator("amphibian", "green");&lt;br /&gt;3) var eagle = animalCreator("bird", "white", "bald eagle" );&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;You would probably think that 1) and 3) will generate error. According to the declaration of the function "animalCreator" it accepts two arguments, called species and color. It is obviously designed to be called with two arguments, but in JavaScript (and unlike Java or C/C++/C#) this is nothing more than a guideline.&lt;br /&gt;&lt;br /&gt;For 1), since there's only one argument, the second one will be set to null. and for 3) we pass a third argument. That will simply be ignored.&lt;br /&gt;&lt;br /&gt;Okay, so much for function call. Let me explain about function as first-class object and how function changes its context.  I know its weird, but the function object itself has its own function. You can use Function.call() or Function.apply() to execute a function.&lt;br /&gt;e.g.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;var food = { meal:"bread and egg", drink: "green tea" };&lt;br /&gt;var person = {&lt;br /&gt; meal:"bacon and rice",&lt;br /&gt; drink: "coffee",&lt;br /&gt; eat: function () {&lt;br /&gt;      return "I'd like to eat " + this.meal + " and drink " + this.drink;&lt;br /&gt; }&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;1) person.eat();&lt;br /&gt;2) person.eat.call(food);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Here we define 2 objects (food and person). Person has a function called "eat". The first one will return:&lt;br /&gt;&lt;br /&gt;I'd like to eat bacon and rice and drink coffee.&lt;br /&gt;&lt;br /&gt;while the second one, since you are using call, and passing an object as an argument. The function context will use the context of food.  It will return:&lt;br /&gt;&lt;br /&gt;I'd like to eat bread and egg and drink green tea.&lt;br /&gt;&lt;br /&gt;As you noticed, the "this" changes context. This concept is very important in javaScript, because this is unlike java and C/C++/C#.&lt;br /&gt;&lt;br /&gt;The apply() method operates similarly, except that it expects all arguments to the function invocation to be bundled as an array that is passed in as the second argument to apply(). Subsequent arguments are ignored.&lt;br /&gt;&lt;br /&gt;Function Closures&lt;br /&gt;&lt;br /&gt;What is function closures?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15934471-7068822933480188990?l=liminescence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://liminescence.blogspot.com/feeds/7068822933480188990/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=15934471&amp;postID=7068822933480188990' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/7068822933480188990'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/7068822933480188990'/><link rel='alternate' type='text/html' href='http://liminescence.blogspot.com/2007/11/javascript-functionprocedure-using.html' title='JavaScript function/procedure using Prototype.js framework'/><author><name>liminescence</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-15934471.post-5370580671921617344</id><published>2007-11-02T21:08:00.000-07:00</published><updated>2007-11-03T20:45:39.138-07:00</updated><title type='text'>Free Directory Assistance?</title><content type='html'>If you need a phone number of a certain establishment you normally dial 411. It cost you about $1 (depending on your cellphone carrier).&lt;br /&gt;&lt;br /&gt;411 is old school now. There's a way to get this information (and more) for free. Call 1-800-GOOG-411 or 1-800-466-4411, and you can ask not only for the numbers, but even for address, direction, etc. You can also request to deliver it to you via SMS (text message).&lt;br /&gt;&lt;br /&gt;Kudos to Google!&lt;br /&gt;&lt;br /&gt;Now what are you waiting for? Try it out! and save it in your phone's contact!&lt;br /&gt;&lt;br /&gt;Check video below for more information.&lt;br /&gt;&lt;br /&gt;&lt;object width="425" height="366"&gt;&lt;param name="movie" value="http://www.youtube.com/v/cN0q8SvlQAk&amp;rel=1&amp;border=0"&gt;&lt;/param&gt;&lt;param name="wmode" value="transparent"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/cN0q8SvlQAk&amp;rel=1&amp;border=0" type="application/x-shockwave-flash" wmode="transparent" width="425" height="366"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15934471-5370580671921617344?l=liminescence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://liminescence.blogspot.com/feeds/5370580671921617344/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=15934471&amp;postID=5370580671921617344' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/5370580671921617344'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/5370580671921617344'/><link rel='alternate' type='text/html' href='http://liminescence.blogspot.com/2007/11/free-directory-assistant.html' title='Free Directory Assistance?'/><author><name>liminescence</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-15934471.post-7753580215839069937</id><published>2007-10-30T09:52:00.000-07:00</published><updated>2007-10-30T17:39:45.392-07:00</updated><title type='text'>The Last Supper</title><content type='html'>One of the best paintings we have in this world is the "Last Supper" by Leonardo Da Vinci. The painting is about Jesus's last meal with his 12 apostles before his death. It depicts the bread and the wine and when Jesus tells his disciples, "Do this in remembrance of me", (1 Corinthians 11:23–25).&lt;br /&gt;&lt;br /&gt;What is interesting is that Leonardo Da Vinci was a member of a hidden society called Prior of Scion (which is also related to the "Illuminati" ), and the painting has more to it than just it's religious theme.&lt;br /&gt;&lt;br /&gt;I'm not claiming that what I'm saying here is true. (So don't judge me) It maybe just a conspiracy theory. But If you look at the painting there's actually no grail in it.&lt;br /&gt;&lt;br /&gt;The theory explains that the grail (the holy cup) holds the blood of Jesus is the same cup that supposedly contains the blood of  his crucifixion; This is  seen by many as a Christian metaphor. However, many people actually believe that the grail is more than just an idea - it represents a human being that holds the child of Jesus (and possibly the merovingian blood line).&lt;br /&gt;&lt;br /&gt;To some, the latter theory is considered blasphemy - a made up story to destroy Christianity. Whatever the real story is, we may never know. In the end, it all boils down to your beliefs and convictions.&lt;br /&gt;&lt;br /&gt;Here's a link to a 16-billion pixel image of the last supper (worlds highest resolution). This is the only image that the Italian government allowed (and there will never be another one )&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.haltadefinizione.com/en/cenacolo/look.asp" target="_blank"&gt; The Last Supper Painting (click me)&lt;br /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15934471-7753580215839069937?l=liminescence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://liminescence.blogspot.com/feeds/7753580215839069937/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=15934471&amp;postID=7753580215839069937' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/7753580215839069937'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/7753580215839069937'/><link rel='alternate' type='text/html' href='http://liminescence.blogspot.com/2007/10/last-supper.html' title='The Last Supper'/><author><name>liminescence</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-15934471.post-8692314376117108378</id><published>2007-10-28T17:47:00.000-07:00</published><updated>2007-10-28T17:57:55.167-07:00</updated><title type='text'>Watch TV anywhere, anytime</title><content type='html'>I came across this device by Sling Media. Its called "Slingbox". SlingBox is device that you connect your cable/satellite and your internet connection, and it streams the signal to your computer or mobile phone. So technically, you can watch your favorite TV show to your computer anytime, anywhere and its live!&lt;br /&gt;&lt;br /&gt;What do you need? &lt;br /&gt;&lt;br /&gt;1) Broadband cable or DSL high-speed Internet connection (Minimum Upstream Network Speed of 256 kbps);&lt;br /&gt;2) Home Network Router;&lt;br /&gt;3) If your TV cable connection is located in a different place than your Internet connection, you will also need a SlingLink or Ethernet bridge, which brings network connectivity to any electrical outlet;&lt;br /&gt;4) Windows or Mac based PC and/or a Windows Mobile or Palm OS Powered PDA or phone with a 3G Data Connection or WiFi for your remote TV viewing.&lt;br /&gt;&lt;br /&gt;What solution can it provide you? Well, for example, I can setup my slingbox in Japan, then if I'm abroad I can watch my favorite show live as it is broadcasted live. Another advantage of Slingbox is that, it has no monthly fee.&lt;br /&gt;&lt;br /&gt;So, if you are subscribing to some cable company like TFC (The Filipino Channel), you can save a lot of money if you use Slingbox, that is assuming that you have internet connection and computer.&lt;br /&gt;&lt;br /&gt;Slingbox site:&lt;br /&gt;http://www.slingmedia.com/go/slingbox-pro&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15934471-8692314376117108378?l=liminescence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://liminescence.blogspot.com/feeds/8692314376117108378/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=15934471&amp;postID=8692314376117108378' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/8692314376117108378'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/8692314376117108378'/><link rel='alternate' type='text/html' href='http://liminescence.blogspot.com/2007/10/watch-tv-anywhere-anytime.html' title='Watch TV anywhere, anytime'/><author><name>liminescence</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-15934471.post-8919899745068417930</id><published>2007-10-25T17:31:00.001-07:00</published><updated>2007-10-26T14:53:21.536-07:00</updated><title type='text'>Javascript using Prototype.js framework</title><content type='html'>Prototype is a JavaScript Framework that aims to ease development of dynamic web applications. One of the objects they provided is the class object. Class is object for class-based &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_0"&gt;OOP&lt;/span&gt;. (You can learn more about Prototype.&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_1"&gt;js&lt;/span&gt; in Prototype.org )&lt;br /&gt;&lt;br /&gt;In my last post, I explained the difference between javascript object and java object. Now, I will explain how to define a class with the use of Prototype.&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_2"&gt;js&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;To use Prototype, first you must include the framework. You can either download the prototype.&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_3"&gt;js&lt;/span&gt; file or reference from it directly, like this:&lt;br /&gt;&lt;br /&gt;&amp;amp;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_4"&gt;lt&lt;/span&gt;;script type="text/javascript" &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_5"&gt;src&lt;/span&gt;="http://www.prototypejs.org/assets/2007/6/20/prototype.js"&amp;gt;&amp;amp;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_6"&gt;lt&lt;/span&gt;;/script&amp;gt;&lt;br /&gt;&lt;br /&gt;Prototype’s Class object contains a single useful helper method which is create(), that allows us to move the body of the constructor into the prototype definition. (No need to specify the prototype directly, like what I did in prev post.)&lt;br /&gt;&lt;br /&gt;The create() method does this for us by defining a constructor automatically that delegates to an initialize() method, which we then define manually.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;var &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_7"&gt;AnimalObj&lt;/span&gt; = Class.create();&lt;br /&gt;&lt;br /&gt;&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_8"&gt;AnimalObj&lt;/span&gt;.prototype = {&lt;br /&gt;&lt;br /&gt;  initialize:function() {&lt;br /&gt;       this.sound = "&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_9"&gt;grr&lt;/span&gt;!";&lt;br /&gt;  },&lt;br /&gt; &lt;span class="blsp-spelling-error" id="SPELLING_ERROR_10"&gt;playSound&lt;/span&gt;: function() {&lt;br /&gt;     alert(this.sound);&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;With prototype, you don't need a constructor (which in javascript a public global function ).  You can define everything in the initialize method it provided.&lt;br /&gt;&lt;br /&gt;Another cool feature about Prototype.&lt;span class="blsp-spelling-error" id="SPELLING_ERROR_11"&gt;js&lt;/span&gt; is the Object.extend() functionality. Object.extend() copies all properties from the source to the destination object. Used by Prototype to simulate inheritance (rather statically) by copying to prototypes.&lt;br /&gt;&lt;br /&gt;The inheritance with Object.extend() works differently if you are used to java. For example, if we want to create Horse that extends Animal. It would be like this:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;      &lt;br /&gt;var Horse = Class.create();&lt;br /&gt;&lt;br /&gt;Object.extend(Horse.prototype,AnimalObj.prototype);&lt;br /&gt;&lt;br /&gt;Object.extend(Horse.prototype, {&lt;br /&gt;      initialize:function() {&lt;br /&gt;          this.sound = "neigh!!";&lt;br /&gt;       }      &lt;br /&gt;});&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Looks weird huh? Well, first you create a class. Then you extend the methods in Animal to your Horse object. Then you define your initialization. Take note that you have to use Object.extend() in defining the initialize() method,  otherwise it will override your previous object.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15934471-8919899745068417930?l=liminescence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://liminescence.blogspot.com/feeds/8919899745068417930/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=15934471&amp;postID=8919899745068417930' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/8919899745068417930'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/8919899745068417930'/><link rel='alternate' type='text/html' href='http://liminescence.blogspot.com/2007/10/javascript-using-prototype.html' title='Javascript using Prototype.js framework'/><author><name>liminescence</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-15934471.post-8276444089907262037</id><published>2007-10-22T07:37:00.000-07:00</published><updated>2007-10-22T08:08:27.890-07:00</updated><title type='text'>Phishing: beware</title><content type='html'>5 of my friends have been victimized by phishing in their yahoo! instant messenger. But what is phishing really? According to wikipedia, phishing is an attempt to criminally and fraudulently acquire sensitive information, such as usernames, passwords and credit card details, by masquerading as a trustworthy entity in an electronic communication. eBay, PayPal and online banks are common targets. Phishing is typically carried out by email or instant messaging, and often directs users to enter details at a website, although phone contact has also been used. Phishing is an example of social engineering techniques used to fool users. Attempts to deal with the growing number of reported phishing incidents include legislation, user training, public awareness, and technical measures.&lt;br /&gt;&lt;br /&gt;What damage can it do to you? Well, first is that you lose your account (in this example you lose your yahoo email ). Your private information get exposed to the hacker and your friends account can potentially be hacked as well, because the hacker will use your account to continue the phishing process. Unfortunately, this time, the hacker have trust factor, because the hacker is pretending to be you.&lt;br /&gt;&lt;br /&gt;How to detect and prevent this? &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;1) Make sure never to login or put your account to any URL link that they gave. No matter how real it is. Take note, that sometimes, you will receive a fake email stating that you need to renew your password. If this happens, make sure to contact the website itself. (This actually happened to me. I received a fake Amazon email ).&lt;br /&gt;&lt;br /&gt;2) If a friend tries to chat with you, make sure to ask your friend's information to know if its really your friend. Hacker doesn't know you, so he/she will rely on your email for information regarding you, to victimize others.&lt;br /&gt;&lt;br /&gt;3) Always make a habit to sign-out everything you're done with your account.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15934471-8276444089907262037?l=liminescence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://liminescence.blogspot.com/feeds/8276444089907262037/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=15934471&amp;postID=8276444089907262037' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/8276444089907262037'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/8276444089907262037'/><link rel='alternate' type='text/html' href='http://liminescence.blogspot.com/2007/10/phishing-beware.html' title='Phishing: beware'/><author><name>liminescence</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-15934471.post-8991197581183837067</id><published>2007-10-20T15:20:00.000-07:00</published><updated>2007-10-20T15:50:50.949-07:00</updated><title type='text'>Flex &amp; Java</title><content type='html'>Flex (particularly Flex 2 and Flex 3 )  is a development language for RIA (Rich internet application) that run cross-platform in a ubiquitous Flash Player 9. You write code using Actionscript 3.0 and XML-based language called MXML that supports the declarative programming of GUI component targeting designers.&lt;br /&gt;&lt;br /&gt;Flex (2 and 3 ) = Actionscript 3.0 + MXML&lt;br /&gt;&lt;br /&gt;If you are a web developer, and experienced in javascript, you will not find it hard to study FLEX.&lt;br /&gt;&lt;br /&gt;I just started learning FLEX this year, and the application I develop are cool and easier to write.&lt;br /&gt;&lt;br /&gt;I will post some cool examples in here once I finalize them.&lt;br /&gt;&lt;br /&gt;The book that recommend you to read, if you want to learn FLEX are:&lt;br /&gt;&lt;br /&gt;1) &lt;a type="amzn" asin="097776222X"&gt;Rich Internet Application with Adobe FLEX &amp;amp; JAVA&lt;/a&gt;&lt;br /&gt;2) &lt;a type="amzn" asin="0596526946"&gt;Oreilly Essential Actionscript 3.0&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15934471-8991197581183837067?l=liminescence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://liminescence.blogspot.com/feeds/8991197581183837067/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=15934471&amp;postID=8991197581183837067' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/8991197581183837067'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/8991197581183837067'/><link rel='alternate' type='text/html' href='http://liminescence.blogspot.com/2007/10/flex-java.html' title='Flex &amp; Java'/><author><name>liminescence</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-15934471.post-225977936436070153</id><published>2007-10-13T20:40:00.000-07:00</published><updated>2007-10-20T15:59:21.751-07:00</updated><title type='text'>The ringnig cedar</title><content type='html'>There's this  movie (based on a book) entitled &lt;a type="amzn" asin="1841197262"&gt;As far as my feet will carry me&lt;/a&gt; that I watched recently that is really intriguing. The story is about a Nazi soldier POW who were sent to Russian prison camp in east Siberia, who escaped and was able to return home in Germany after 3 years.&lt;br /&gt;&lt;br /&gt;What struck me most is the part when he was saved by a young yakuts girl, which later on he was given a ringing cedar pendant.&lt;br /&gt;&lt;br /&gt;Actually, I never heard about ringing cedar at all, until my brother-in-law told me about it.&lt;br /&gt;&lt;br /&gt;In Siberia, if a cedar tree is about to die ( because of old age - 300-500 years old ), the tree emits a ringing sound. The shamans believe that once you cut that tree, and take a part of it with you. The energy and oil of that wood can make you feel stronger, makes your aura colorful, than any person you meet will like you.&lt;br /&gt;&lt;br /&gt;The ringing cedar idea is actually in the book of Vladimir Migre called "The ringing cedar series". Book 1 is called &lt;a type="amzn" asin="0976333309"&gt;Anastasia&lt;/a&gt; (click the link for details). This a must read book.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15934471-225977936436070153?l=liminescence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://liminescence.blogspot.com/feeds/225977936436070153/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=15934471&amp;postID=225977936436070153' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/225977936436070153'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/225977936436070153'/><link rel='alternate' type='text/html' href='http://liminescence.blogspot.com/2007/10/ringnig-cedar.html' title='The ringnig cedar'/><author><name>liminescence</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-15934471.post-113224462635015359</id><published>2005-11-17T08:18:00.000-08:00</published><updated>2007-10-26T14:50:37.869-07:00</updated><title type='text'>Javascript vs. Java class</title><content type='html'>If you are a C++ programmer shifting to Java,  you can easily migrate without a problem. But being a C++/JAVA programmer shifting to object oriented javascript its not the same.&lt;br /&gt;&lt;br /&gt;Javascript is an interpreted language and that makes it special. Prior to Web2.0, we use javascript for validating forms and some simple front end computation. Since the use of AJAX (asynchronous javascript and xml ) it totally change you use javascript.&lt;br /&gt;&lt;br /&gt;Id like to explain here how javascript objects differs from java/C++ objects.&lt;br /&gt;&lt;br /&gt;Javascript object is actually just a hash table or associative array. Its a key-value pair. You can define an object directly without defining a class.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;var animalObj = {};&lt;br /&gt;animalObj.sound = "grrr!";&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;in this case, I declared an object on the fly, and assign it to {}. which means Hash. After that I created a property called sound and assign "grr!" value to it.&lt;br /&gt;&lt;br /&gt;You can also define the object like this:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;var animalObj = new Object();&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;I know most C++/Java developer are use to that. But technically, it makes no difference.  Its just more simpler to use {}.&lt;br /&gt;&lt;br /&gt;For the methods, I can simply implement it like this:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;animalObj.playSound = function() { Alert(this.sound) }&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Take note that its just like a property,  but you assign a function to it. To call it though, you need a "()".&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;animalObj.playSound();&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The "this" keyword here is similar to JAVA/C++. But take note, sometimes, it changes reference. You'll get lots of headaches on the "this" keyword if you don't understand how it changes reference. But don't worry, I will explain it here as I continue.&lt;br /&gt;&lt;br /&gt;You  can also define this object like a hash (key-value pair). aka JSON-style&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;var animalObj = {&lt;br /&gt;   sound: "grrr!",&lt;br /&gt;  playSound: function() { alert(this.sound); }&lt;br /&gt;};&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Its simple huh? so far so good. But unfortunately, you cannot reuse this object. Everytime you need it, you have to define it again, and I guess that's bad. But luckily, you can define it as a type.  This time you have to use prototype.&lt;br /&gt;&lt;br /&gt;Prototype is a collection of properties and methods that can be automatically attached to an object when it is created.&lt;br /&gt;&lt;br /&gt;To make an object type (or a class in javascript) you have to define a public function to work as a constructor. Take note again, that object here is like Hash, its not like a class in C++/JAVA that has a constructor. The way to define you constructor is to make a public function return an object. Here's how:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;function AnimalObj2() {&lt;br /&gt;   this.sound = "grr!";&lt;br /&gt;   this.playSound = function() { alert(this.sound); }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;var myAnimal2 = new AnimalObj2();&lt;br /&gt;myAnimal2.playSound();&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This time I have a javascript AnimalObj2 type. Unfortunately, every time I instantiate or call the constructor function, I will create a new function in the memory, and this is not good, because each object has its own instance of the function. Which, Ideally the function should only be define once. So solve this problem, you have to put the method in the object's prototype. Because there's always 1 prototype in each object.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;function AnimalObj2() {&lt;br /&gt;   this.sound = "grr!";&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;AnimalObj2.prototype = {&lt;br /&gt;   this.playSound = function() { alert(this.sound); }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Where as in JAVA, you would define it like this:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;public class AnimalObj {&lt;br /&gt;    private String sound = "Grrr!";&lt;br /&gt;&lt;br /&gt;    public AnimalObj() {&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public void playSound() {&lt;br /&gt;        System.out.println(this.sound);&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Next post, I will discuss how to define javascript object using Prototype.js framework.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15934471-113224462635015359?l=liminescence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://liminescence.blogspot.com/feeds/113224462635015359/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=15934471&amp;postID=113224462635015359' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/113224462635015359'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/113224462635015359'/><link rel='alternate' type='text/html' href='http://liminescence.blogspot.com/2005/11/aesthetic-mirth.html' title='Javascript vs. Java class'/><author><name>liminescence</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-15934471.post-112534566288592048</id><published>2005-08-29T12:59:00.000-07:00</published><updated>2005-08-29T13:01:02.890-07:00</updated><title type='text'>Hello world!</title><content type='html'>Hi everybody! I just started this blog by blogger.com. it Rocks!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/15934471-112534566288592048?l=liminescence.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://liminescence.blogspot.com/feeds/112534566288592048/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=15934471&amp;postID=112534566288592048' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/112534566288592048'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/15934471/posts/default/112534566288592048'/><link rel='alternate' type='text/html' href='http://liminescence.blogspot.com/2005/08/hello-world.html' title='Hello world!'/><author><name>liminescence</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
