<?xml version="1.0" encoding="utf-8" ?>
<rdf:RDF 
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:content="http://purl.org/rss/1.0/modules/content/"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/"
   xmlns="http://my.netscape.com/rdf/simple/0.9/">
<channel>
    <title>Eduzine©</title>
    <link>http://eduzine.edujini-labs.com/</link>
    <description>Articles from Edujini Team</description>
    <dc:language>en</dc:language>
    <admin:errorReportsTo rdf:resource="mailto:" />

    <image rdf:resource="http://www.edujini-labs.com/images/newmasthead.gif" />

    <items>
      <rdf:Seq>
        <rdf:li resource="http://eduzine.edujini-labs.com/archives/38-guid.html" />
        <rdf:li resource="http://eduzine.edujini-labs.com/archives/37-guid.html" />
        <rdf:li resource="http://eduzine.edujini-labs.com/archives/36-guid.html" />
        <rdf:li resource="http://eduzine.edujini-labs.com/archives/35-guid.html" />
        <rdf:li resource="http://eduzine.edujini-labs.com/archives/34-guid.html" />
        <rdf:li resource="http://eduzine.edujini-labs.com/archives/33-guid.html" />
        <rdf:li resource="http://eduzine.edujini-labs.com/archives/32-guid.html" />
        <rdf:li resource="http://eduzine.edujini-labs.com/archives/29-guid.html" />
        <rdf:li resource="http://eduzine.edujini-labs.com/archives/31-guid.html" />
        <rdf:li resource="http://eduzine.edujini-labs.com/archives/30-guid.html" />
        <rdf:li resource="http://eduzine.edujini-labs.com/archives/28-guid.html" />
        <rdf:li resource="http://eduzine.edujini-labs.com/archives/27-guid.html" />
        <rdf:li resource="http://eduzine.edujini-labs.com/archives/26-guid.html" />
        <rdf:li resource="http://eduzine.edujini-labs.com/archives/25-guid.html" />
        <rdf:li resource="http://eduzine.edujini-labs.com/archives/24-guid.html" />
</rdf:Seq>
    </items>
</channel>

<image rdf:about="http://www.edujini-labs.com/images/newmasthead.gif">
        <url>http://www.edujini-labs.com/images/newmasthead.gif</url>
        <title>RSS: Eduzine© - Articles from Edujini Team</title>
        <link>http://eduzine.edujini-labs.com/</link>
        <width></width>
        <height></height>
    </image>
<item rdf:about="http://eduzine.edujini-labs.com/archives/38-guid.html">
    <title>DWT - Take off and Problems Galore</title>
    <link>http://eduzine.edujini-labs.com/archives/38-DWT-Take-off-and-Problems-Galore.html</link>
    <description>
&lt;p&gt;
The DWT project commenced about a fortnight back and soon hit some roadblocks.
&lt;/p&gt;

&lt;p&gt;
Firstly, the Ajax communication to the server in Google Web Toolkit is asynchronous and as such retrieving the templates in template based widgets was an issue. For which the team wrote a quick-fix to query the server synchronously. A function &lt;code&gt;getText&lt;/code&gt; was added to &lt;code&gt;com.edujinilabs.dwt.client.dojo.Dojo&lt;/code&gt; class (see &lt;a href=&quot;http://dwt.svn.sourceforge.net/viewvc/dwt/trunk/dwt/eclipse/src/com/edujinilabs/dwt/client/dojo/Dojo.java?revision=51&amp;view=markup&quot;&gt;the code here&lt;/a&gt;).
&lt;/p&gt;

&lt;p&gt;
Ok... that was an easy go. But then, we had the real fun!
&lt;/p&gt; 
&lt;p&gt;
Template-based Widgets rely on dynamically created properties (JavaScript is, after all, dynamically typed language). However, the first problem is that Java is statically typed; secondly, GWT changes the field/function names upon recompilation, and finally - Java does not support function references.
&lt;/p&gt;

&lt;p&gt;
A detailed problem description and proposed solution has been put up on the &lt;a href='http://dwt.sourceforge.net/blog/2008/08/29/template-based-widgets-in-dwt/'&gt;DWT Blog&lt;/a&gt;.
&lt;/p&gt;

&lt;p&gt;
Have you got some suggestions or inputs? Do write in...
&lt;/p&gt;

    </description>
        <dc:publisher>Eduzine©</dc:publisher>
    <dc:creator>eduzine@edujinionline.com (Eduzine)</dc:creator>
    <dc:subject>JavaScript, Dojo, Ajax, GWT, Web 2.0, Dojo GWT</dc:subject>
    <dc:date>2008-09-04T15:28:12Z</dc:date>
    <wfw:comment>http://eduzine.edujini-labs.com/wfwcomment.php?cid=38</wfw:comment>
    <slash:comments>1</slash:comments>
    <wfw:commentRss>http://eduzine.edujini-labs.com/rss.php?version=1.0&amp;type=comments&amp;cid=38</wfw:commentRss>
</item>
<item rdf:about="http://eduzine.edujini-labs.com/archives/37-guid.html">
    <title>Standard Widget Toolkit: Part 1 - Hello, World!</title>
    <link>http://eduzine.edujini-labs.com/archives/37-Standard-Widget-Toolkit-Part-1-Hello,-World!.html</link>
    <description>

&lt;h2&gt;Introduction&lt;/h2&gt;

&lt;p&gt;
With this article, we start a series on Standard Widget Toolkit (SWT) and Eclipse Plug-in Framework at Eduzine&lt;sup&gt;©&lt;/sup&gt;. It is assumed that you have already heard about Eclipse and you are gungho about exploring it and may be getting into all its details.
&lt;/p&gt;

&lt;p&gt;
SWT is the base UI toolkit to create the UI, mainly the native widgets. Then there is JFace, an abstraction that sits on top of JFace (a large part of it) and adds power to native widgets. And finally, there is Eclipse Plug-in Framework that helps creating applications in a modular fashion. Default implementation of the Eclipse Workbench (the main UI cockpit) uses SWT and JFace for its UI.
&lt;/p&gt;

&lt;p&gt;
Following the tradition started few decades back, we start with &amp;quot;Hello, World!&amp;quot; application.
&lt;/p&gt;

&lt;h2&gt;Downloads&lt;/h2&gt;

&lt;p&gt;
The downloads are available in the &lt;a href=&quot;http://downloads.edujini-labs.com&quot;&gt;Downloads&lt;/a&gt; area in the &lt;a href=&quot;http://downloads.edujini-labs.com/index.php?act=category&amp;id=28&quot;&gt;Eclise Standard Widget Toolkit&lt;/a&gt; category.
&lt;/p&gt;

 
&lt;h2&gt;Pre-requisites&lt;/h2&gt;

&lt;p&gt;
To get started, the following pre-requisites would be considered:
&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;You know Java programming langauge.&lt;/li&gt;
  &lt;li&gt;You have JDK (not only JRE) installed on your machine (from &lt;a href=&quot;http://java.sun.com&quot;&gt;http://java.sun.com&lt;/a&gt;).&lt;/li&gt;
  &lt;li&gt;You have Eclipse installed on your machine (from &lt;a href=&quot;http://www.eclipse.org&quot;&gt;http://www.eclipse.org&lt;/a&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;Case Study&lt;/h2&gt;

&lt;p&gt;
We will create our final application in multiple steps. Here's the brief overview of these steps:
&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;a href=&quot;#gvaish37-step1&quot;&gt;Step 1&lt;/a&gt;: Create a window that contains a text that reads &amp;quot;Hello, World!&amp;quot;.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#gvaish37-step2&quot;&gt;Step 2&lt;/a&gt;: Create a window that has a button on click of which we get launch other window with a text that reads, &amp;quot;Hello, World!&amp;quot;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;
And the &amp;quot;top level window&amp;quot; with a &amp;quot;Title Bar&amp;quot;, &amp;quot;Minimize&amp;quot;, &amp;quot;Maximize&amp;quot; and &amp;quot;Close&amp;quot; buttons - the one that interacts with the Desktop or &amp;quot;Window Manager&amp;quot; - is known as &lt;code&gt;Shell&lt;/code&gt; in SWT.
&lt;/p&gt;

&lt;h2&gt;Getting Started - Creating Project&lt;/h2&gt;

&lt;p&gt;
We start by creating a project using Eclipse IDE. Follow these steps to create and configure a simple Java application project.
&lt;/p&gt;

&lt;p&gt;
Step 1: In the &amp;quot;New Project&amp;quot; wizard, select &amp;quot;Java Project&amp;quot;. Click Next.
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;http://eduzine.edujini-labs.com/uploads/eclipse/swt/37.Eclipse.SWT.Hello.World-01.New.Project.jpg&quot; alt=&quot;Eduzine: Eclipse: SWT: Project&quot; title=&quot;Eduzine: Eclipse: SWT: Project&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
Step 2: Give the name of the project - &amp;quot;HelloWorldSWT&amp;quot;. Click Next.
&lt;/p&gt;
&lt;p&gt;
&lt;img src=&quot;http://eduzine.edujini-labs.com/uploads/eclipse/swt/37.Eclipse.SWT.Hello.World-02.New.Project.Name.jpg&quot; alt=&quot;Eduzine: Eclipse: SWT: Project&quot; title=&quot;Eduzine: Eclipse: SWT: Project&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
Step 3: Go to the &amp;quot;Libraries&amp;quot; Tab. Click &amp;quot;Add External Jars...&amp;quot; button.
&lt;/p&gt;
&lt;p&gt;
&lt;img src=&quot;http://eduzine.edujini-labs.com/uploads/eclipse/swt/37.Eclipse.SWT.Hello.World-03.Libraries.jpg&quot; alt=&quot;Eduzine: Eclipse: SWT: Project&quot; title=&quot;Eduzine: Eclipse: SWT: Project&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
Step 4: Browse to the &amp;quot;plugins&amp;quot; folder within the folder where Eclipse is installed. Add references to &lt;code&gt;org.eclipse.swt_&amp;lt;version&amp;gt;.jar&lt;/code&gt; and &lt;code&gt;org.eclipse.swt.win32.win32.x86_&amp;lt;version&amp;gt;.jar&lt;/code&gt;. Click Finish.
&lt;/p&gt;
&lt;p&gt;
&lt;img src=&quot;http://eduzine.edujini-labs.com/uploads/eclipse/swt/37.Eclipse.SWT.Hello.World-04.Updated.jpg&quot; alt=&quot;Eduzine: Eclipse: SWT: Project&quot; title=&quot;Eduzine: Eclipse: SWT: Project&quot; /&gt;
&lt;/p&gt;

&lt;h2&gt;Entry Point&lt;/h2&gt;

&lt;p&gt;
Now that we have the project, let us create a class &lt;code&gt;HelloWorldClass&lt;/code&gt; that will act as the entry point (through the &lt;code&gt;main&lt;/code&gt; method) for our application.
&lt;/p&gt;
&lt;p&gt;
&lt;img src=&quot;http://eduzine.edujini-labs.com/uploads/eclipse/swt/37.Eclipse.SWT.Hello.World-05.HelloWorldClass.jpg&quot; alt=&quot;Eduzine: Eclipse: SWT: Add HelloWorldClass&quot; title=&quot;Eduzine: Eclipse: SWT: Add HelloWorldClass&quot; /&gt;
&lt;/p&gt;

&lt;a name=&quot;gvaish37-step1&quot;&gt;&lt;h2&gt;Implementation: Step 1&lt;/h2&gt;&lt;/a&gt;

&lt;p&gt;
Let's get started with the implementation. The first thing that we will ever need to create the UI is an instance of &lt;code&gt;org.eclipse.swt.widgets.Display&lt;/code&gt;. The top-level window, as discussed earlier, is an instance of &lt;code&gt;org.eclipse.swt.widgets.Shell&lt;/code&gt;.
&lt;/p&gt;

&lt;p&gt;
Update the code for &lt;code&gt;HelloWorldClass&lt;/code&gt; to as follows:
&lt;/p&gt;

&lt;pre&gt;package com.edujinilabs.eduzine.eclipse.swt;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

/**
 &lt;strong&gt; Part of the Eduzine (http://eduzine.edujini-labs.com) Articles.
 &lt;/strong&gt; Downloads available at http://downloads.edujini-labs.com
 &lt;strong&gt; (C) 2008, Edujini Labs Pvt Ltd.
 &lt;/strong&gt; http://www.edujini-labs.com
 */
public class HelloWorldClass
{
  public static void main(String[] args)
  {
    Display display = new Display();
    Shell mainWindow = new Shell(display, SWT.DIALOG_TRIM);

    mainWindow.setText(&amp;quot;Eduzine: SWT Hello World&amp;quot;);
    mainWindow.open();
  }
}
&lt;/pre&gt;

&lt;p&gt;
Right click on the file and select &amp;quot;Run As...&amp;quot; -&amp;gt; &amp;quot;SWT Application&amp;quot;.
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;http://eduzine.edujini-labs.com/uploads/eclipse/swt/37.Eclipse.SWT.Hello.World-06.Launch.jpg&quot; alt=&quot;Eduzine: Eclipse: SWT: Launch Main Class&quot; title=&quot;Eduzine: Eclipse: SWT: Launch Main Class&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
While launching, keep a close eye on the monitor. What do you see?
&lt;/p&gt;

&lt;p&gt;
Ouch! The new windows seems to be launched but also lost somewhere. &lt;img src=&quot;http://eduzine.edujini-labs.com/templates/default/img/emoticons/sad.png&quot; alt=&quot;:-(&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
Well, if that's the case... you are on absolutely correct track! &lt;img src=&quot;http://eduzine.edujini-labs.com/templates/default/img/emoticons/smile.png&quot; alt=&quot;:-)&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
The reason for this behaviour is that the &lt;code&gt;open&lt;/code&gt; method is a non-blocking call meaning that it opens up the window and returns immediately. And in our code, nobody stops the controls to get transferred past-end of the &lt;code&gt;main&lt;/code&gt; causing the application to terminate.
&lt;/p&gt;

&lt;p&gt;
So, the next step is to add the code that does the following:
&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Waits indefinitely, only to be terminated if we click the close [X] button on the title-bar of the main window.&lt;/li&gt;
  &lt;li&gt;Does not use CPU cycles if no activity is to be performed.&lt;/li&gt;
  &lt;li&gt;Respond to events, if there is any activity and again go for indefinite wait.&lt;/li&gt;
  &lt;li&gt;On closing the main window, it frees up the resources used, especially OS resources like Font, Color, Pen/Brush etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
The loop that does the first-three steps mentioned above is known as &lt;em&gt;event loop&lt;/em&gt;.
&lt;/p&gt;

&lt;p&gt;
Update the &lt;code&gt;main&lt;/code&gt; method to the following code:
&lt;/p&gt;

&lt;pre&gt;public class HelloWorldClass
{
  public static void main(String[] args)
  {
    Display display = new Display();
    Shell mainWindow = new Shell(display, SWT.DIALOG_TRIM);

    mainWindow.setText(&amp;quot;Eduzine: SWT Hello World&amp;quot;);
    mainWindow.open();

    &lt;b&gt;while(!mainWindow.isDisposed())
    {
      if(!display.readAndDispatch())
      {
        display.sleep();
      }
    }
    display.dispose();&lt;/b&gt;
  }
}
&lt;/pre&gt;

&lt;p&gt;
Launch the application again. Not posting the screenshot since it's a huge window. &lt;img src=&quot;http://eduzine.edujini-labs.com/templates/default/img/emoticons/smile.png&quot; alt=&quot;:-)&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
The next step is to add a text on the window that reads &amp;quot;Hello, World!&amp;quot;. We make use of the Widget named &lt;code&gt;Label&lt;/code&gt;.
&lt;/p&gt;

&lt;p&gt;
The constructors of all basic widgets require the information about the parent container in which they will be placed - the containers referred to as &lt;code&gt;Composite&lt;/code&gt; widgets. The second parameter to the constructor is a number (integer) representing the styles. We will explore the styles soon. So, what are we waiting for? Let's update the code... And ah! We shall resize the window to a smaller size.
&lt;/p&gt;

&lt;pre&gt;public class HelloWorldClass
{
  public static void main(String[] args)
  {
    Display display = new Display();
    Shell mainWindow = new Shell(display, SWT.DIALOG_TRIM);

    &lt;b&gt;Label hwLabel = new Label(mainWindow, SWT.NONE);
    hwLabel.setText(&amp;quot;Hello, World!&amp;quot;);&lt;/b&gt;

    mainWindow.setText(&amp;quot;Eduzine: SWT Hello World&amp;quot;);
    &lt;b&gt;mainWindow.setSize(300, 200);&lt;/b&gt;
    mainWindow.open();

    while(!mainWindow.isDisposed())
    {
      if(!display.readAndDispatch())
      {
        display.sleep();
      }
    }
    display.dispose();
  }
}
&lt;/pre&gt;

&lt;p&gt;
Things look much better now except only that we are yet, unable to see the &lt;code&gt;Label&lt;/code&gt;.
&lt;/p&gt;

&lt;h2&gt;Layout Manager&lt;/h2&gt;

&lt;p&gt;
All &lt;code&gt;Composite&lt;/code&gt; widgets use a layout manager - technically a subclass of &lt;code&gt;org.eclipse.swt.layout.GridLayout&lt;/code&gt; - to layout the child widgets within themselves.
&lt;/p&gt;

&lt;p&gt;
For our purpose, we make use of &lt;code&gt;org.eclipse.swt.layout.GridLayout&lt;/code&gt;. We explore it later on. Update the code to as follows:
&lt;/p&gt;

&lt;pre&gt;    Display display = new Display();
    Shell mainWindow = new Shell(display, SWT.DIALOG_TRIM);

    &lt;b&gt;GridLayout layout = new GridLayout();
    mainWindow.setLayout(layout);&lt;/b&gt;

    Label hwLabel = new Label(mainWindow, SWT.NONE);
    hwLabel.setText(&amp;quot;Hello, World!&amp;quot;);
&lt;/pre&gt;

&lt;p&gt;
Launch the application! Voila! Got the &amp;quot;Hello, World!&amp;quot;. The expected output is as below:
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;http://eduzine.edujini-labs.com/uploads/eclipse/swt/37.Eclipse.SWT.Hello.World-07-Layout.jpg&quot; alt=&quot;Eduzine: Eclipse: SWT: Specify Layout, Final Output&quot; title=&quot;Eduzine: Eclipse: SWT: Specify Layout, Final Output&quot; /&gt;
&lt;/p&gt;

&lt;a name=&quot;gvaish37-step2&quot;&gt;&lt;h2&gt;Implementation - Step 2&lt;/h2&gt;&lt;/a&gt;

&lt;p&gt;
Now that we've got a simple but working application, let's move on to the next step, making it interactive. We replace the &lt;code&gt;Label&lt;/code&gt; with a &lt;code&gt;org.eclipse.swt.widgets.Button&lt;/code&gt; and popup a new window that reads, &amp;quot;Hello, World!&amp;quot;
&lt;/p&gt;

&lt;p&gt;
Firstly, we replace &lt;code&gt;Label&lt;/code&gt; with &lt;code&gt;Button&lt;/code&gt;. Update the code to as follows:
&lt;/p&gt;

&lt;pre&gt;package com.edujinilabs.eduzine.eclipse.swt;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
&lt;b&gt;import org.eclipse.swt.widgets.Button;&lt;/b&gt;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class HelloWorldClass
{
  public static void main(String[] args)
  {
    Display display = new Display();
    Shell mainWindow = new Shell(display, SWT.DIALOG_TRIM);

    GridLayout layout = new GridLayout();
    mainWindow.setLayout(layout);

    &lt;b&gt;Button hwBtn = new Button(mainWindow, SWT.NONE);
    hwBtn.setText(&amp;quot;Say Hello&amp;quot;);&lt;/b&gt;

    mainWindow.setText(&amp;quot;Eduzine: SWT Hello World&amp;quot;);
    mainWindow.setSize(300, 200);
    mainWindow.open();

    while(!mainWindow.isDisposed())
    {
      if(!display.readAndDispatch())
      {
        display.sleep();
      }
    }
    display.dispose();
  }
}
&lt;/pre&gt;

&lt;p&gt;
Subsequently, we create a class &lt;code&gt;HelloWorldWindow&lt;/code&gt; with similar UI as created earlier. However, this time, the new class will have a new method &lt;code&gt;open&lt;/code&gt; that will actually launch the UI. The definition of the class is as follows:
&lt;/p&gt;

&lt;pre&gt;package com.edujinilabs.eduzine.eclipse.swt;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;

public class HelloWorldWindow
{
  private Shell window;

  public HelloWorldWindow(Shell parent)
  {
    this.window = new Shell(parent, SWT.DIALOG_TRIM);

    GridLayout layout = new GridLayout();
    window.setLayout(layout);

    Label hwBtn = new Label(window, SWT.NONE);
    hwBtn.setText(&amp;quot;Hello, World!&amp;quot;);

    window.setText(&amp;quot;Eduzine: Child&amp;quot;);
    window.setSize(200, 100);
  }

  public void open()
  {
    this.window.open();
  }
}
&lt;/pre&gt;

&lt;p&gt;
Now, the only missing link is to launch this window on the click of the button! What are we waiting for then? Let's do it! Update &lt;code&gt;HelloWorldClass&lt;/code&gt; to as follows:
&lt;/p&gt;

&lt;pre&gt;  public static void main(String[] args)
  {
    Display display = new Display();
    &lt;b&gt;final&lt;/b&gt; Shell mainWindow = new Shell(display, SWT.DIALOG_TRIM);

    GridLayout layout = new GridLayout();
    mainWindow.setLayout(layout);

    Button hwBtn = new Button(mainWindow, SWT.NONE);
    hwBtn.setText(&amp;quot;Say Hello&amp;quot;);

    &lt;b&gt;hwBtn.addSelectionListener(new SelectionAdapter() {
      public void widgetSelected(SelectionEvent e)
      {
        HelloWorldWindow w = new HelloWorldWindow(mainWindow);
        w.open();
      }
    });
    &lt;/b&gt;
    ...
  }
&lt;/pre&gt;

&lt;p&gt;
On launch, the output expected is follows (Hey! Don't forget to click the button).
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;http://eduzine.edujini-labs.com/uploads/eclipse/swt/37.Eclipse.SWT.Hello.World-08-Button-Launch.jpg&quot; alt=&quot;Eduzine: Eclipse: SWT: Child Window&quot; title=&quot;Eduzine: Eclipse: SWT: Child Window&quot; /&gt;
&lt;/p&gt;

&lt;h2&gt;Summary&lt;/h2&gt;

&lt;p&gt;
In this article, we learnt how to get started with Standard Widget Toolkit, the UI Toolkit created for initially for Eclipse and now used by millions of developers worldwide!
&lt;/p&gt;

&lt;p&gt;
In subsequent articles, we explore about SWT and Eclipse, and environment around them.
&lt;/p&gt;
    </description>
        <dc:publisher>Eduzine©</dc:publisher>
    <dc:creator>eduzine@edujinionline.com (Eduzine)</dc:creator>
    <dc:subject>Eclipse, SWT, &quot;Hello, World!&quot;</dc:subject>
    <dc:date>2008-06-25T15:58:16Z</dc:date>
    <wfw:comment>http://eduzine.edujini-labs.com/wfwcomment.php?cid=37</wfw:comment>
    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://eduzine.edujini-labs.com/rss.php?version=1.0&amp;type=comments&amp;cid=37</wfw:commentRss>
</item>
<item rdf:about="http://eduzine.edujini-labs.com/archives/36-guid.html">
    <title>Exploring OOPS - JavaScript Style: Part 3 - Polymorphism</title>
    <link>http://eduzine.edujini-labs.com/archives/36-Exploring-OOPS-JavaScript-Style-Part-3-Polymorphism.html</link>
    <description>

&lt;h2&gt;Introduction&lt;/h2&gt;

&lt;p&gt;
In the third and last article of the series of &amp;quot;Exploring OOPS - JavaScript Style&amp;quot;, we look at polymorphism in JavaScript.
&lt;/p&gt;

&lt;p&gt;
Polymorphism literally means &amp;quot;multiple forms&amp;quot;. In OOAD, it means that an object reference can take different behave differently depending upon the scenario.
&lt;/p&gt;

&lt;p&gt;
Technically, there are two types of polymorphism - compile-time polymorphism and runtime polymorphism. One of the ways to implement compile-time polymorphism is method overloading while runtime polymorphism can be implemented by method overriding.
&lt;/p&gt;

&lt;h2&gt;Downloads&lt;/h2&gt;

&lt;p&gt;
The downloads are available in the &lt;a href=&quot;http://downloads.edujini-labs.com&quot;&gt;Downloads&lt;/a&gt; area.
&lt;/p&gt;

 
&lt;h2&gt;Compile-time Polymorphism&lt;/h2&gt;

&lt;p&gt;
All functions in JavaScript are overloaded by default. Surprised, isn't it? Let's take a simple code below for analysis:
&lt;/p&gt;

&lt;pre&gt;&amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;OOPS in JavaScript - Polymorphism&amp;lt;/code&amp;gt;
    &amp;lt;script language='javascript' type='text/javascript'&amp;gt;
      /**
       &lt;strong&gt; Part of the Eduzine (http://eduzine.edujini-labs.com) Articles.
       &lt;/strong&gt;
       &lt;strong&gt; Downloads available at http://downloads.edujini-labs.com
       &lt;/strong&gt;
       &lt;strong&gt; (C) 2008, Edujini Labs Pvt Ltd
       &lt;/strong&gt; http://www.edujini-labs.com
       &lt;strong&gt;/

      function addMethod(x, y)
      {
        document.writeln('x: ' + x + ', y: ' + y);
      }
    &amp;lt;/script&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
  &amp;lt;pre&amp;gt;&amp;lt;script language='javascript' type='text/javascript'&amp;gt;
      addMethod();
      addMethod(1);
      addMethod(1, 2);
      addMethod(1, 2, 3);
      addMethod(1, 2, 3, 4);
    &amp;lt;/script&amp;gt;
  &amp;lt;/pre&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/pre&gt;

&lt;p&gt;
For the time being, do not worry about the actual results. What is more important is that invocation of these methods do not result in any error whatsoever! And that's because all methods in JavaScript are, by default, overloaded. And did somebody say - that's compile-time polymorphism?
&lt;/p&gt;

&lt;p&gt;
What we provide in the parameter-list to a JavaScript function is just names to those parameters so that it is convenient to access them. All parameters passed to a function are available through an automatically-created local-variable &lt;code&gt;arguments&lt;/code&gt;. Let's redefine the same method to access all parameters passed to it, convert each into number and return the their sum (if they are not NaN).
&lt;/p&gt;

&lt;pre&gt;&amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;OOPS in JavaScript - Polymorphism&amp;lt;/code&amp;gt;
    &amp;lt;script language='javascript' type='text/javascript'&amp;gt;
      /**
       &lt;/strong&gt; Part of the Eduzine (http://eduzine.edujini-labs.com) Articles.
       &lt;strong&gt;
       &lt;/strong&gt; Downloads available at http://downloads.edujini-labs.com
       &lt;strong&gt;
       &lt;/strong&gt; (C) 2008, Edujini Labs Pvt Ltd
       &lt;strong&gt; http://www.edujini-labs.com
       &lt;/strong&gt;/

      function addMethod(x, y)
      {
        &lt;b&gt;var rv = 0;
        var length = arguments.length;
        var n;

        for(var i = 0; i &amp;lt; length; i++)
        {
          n = Number(arguments[i]);
          if(!isNaN(n))
          {
            rv += n;
          }
        }
        return rv;&lt;/b&gt;
      }
    &amp;lt;/script&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
  &amp;lt;pre&amp;gt;&amp;lt;script language='javascript' type='text/javascript'&amp;gt;
      &lt;b&gt;document.writeln(addMethod());
      document.writeln(addMethod(1));
      document.writeln(addMethod(1, 2));
      document.writeln(addMethod(1, 2, 3));
      document.writeln(addMethod(1, 2, 3, 4));&lt;/b&gt;
    &amp;lt;/script&amp;gt;
  &amp;lt;/pre&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/pre&gt;

&lt;p&gt;
&lt;code&gt;arguments&lt;/code&gt; if of the type &lt;a href=&quot;http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Functions:arguments&quot;&gt;&lt;code&gt;Arguments&lt;/code&gt;&lt;/a&gt;. Apart from other properties, one critical thing to which it provides access to is all the parameters passed to the function while invoking it.
&lt;/p&gt;

&lt;p&gt;
Though it may sound unusual for those who are used to working with languages like C, C++, Java, C# etc but probably they can relate this to &lt;code&gt;varargs&lt;/code&gt;. And the same mechanism is available for instance methods (for custom types) as well.
&lt;/p&gt;

&lt;h2&gt;Runtime Polymorphism&lt;/h2&gt;

&lt;p&gt;
Method overriding? Haven't we already discussed this in the previous article while &lt;a href=&quot;http://eduzine.edujini-labs.com/archives/35-Exploring-OOPS-JavaScript-Style-Part-2-Inheritance.html&quot;&gt;discussing about inheritance&lt;/a&gt;?
&lt;/p&gt;

&lt;h2&gt;Summary&lt;/h2&gt;

&lt;p&gt;
In this article we learnt about polymorphism in JavaScript.
&lt;/p&gt;

    </description>
        <dc:publisher>Eduzine©</dc:publisher>
    <dc:creator>eduzine@edujinionline.com (Eduzine)</dc:creator>
    <dc:subject>JavaScript, Web 2.0, RIA, OOAD</dc:subject>
    <dc:date>2008-06-18T00:34:10Z</dc:date>
    <wfw:comment>http://eduzine.edujini-labs.com/wfwcomment.php?cid=36</wfw:comment>
    <slash:comments>2</slash:comments>
    <wfw:commentRss>http://eduzine.edujini-labs.com/rss.php?version=1.0&amp;type=comments&amp;cid=36</wfw:commentRss>
</item>
<item rdf:about="http://eduzine.edujini-labs.com/archives/35-guid.html">
    <title>Exploring OOPS - JavaScript Style: Part 2 - Inheritance</title>
    <link>http://eduzine.edujini-labs.com/archives/35-Exploring-OOPS-JavaScript-Style-Part-2-Inheritance.html</link>
    <description>

&lt;h2&gt;Introduction&lt;/h2&gt;

&lt;p&gt;
In the second article of the series of &amp;quot;Exploring OOPS - JavaScript Style&amp;quot;, we look at how inheritance is implemented in JavaScript.
&lt;/p&gt;

&lt;p&gt;
Inheritance can be described as reusability by virtue of heritage. An inherited data-type automatically obtains the functionality defined in the data-types from which it inherits.
&lt;/p&gt;

&lt;p&gt;
JavaScript supports single inheritance, i.e., you can inherit from maximum one type. Also, it does not support the concept of interface introduced in languages like Java, C# to support multiple inheritance.
&lt;/p&gt;

&lt;p&gt;
In JavaScript what we have is instance-inheritance (or runtime inheritance) rather than class-inheritance (or compile-time inheritance) making inheritance more powerful than probably any other language around (barring the ones like Smalltalk)!
&lt;/p&gt;

&lt;h2&gt;Downloads&lt;/h2&gt;

&lt;p&gt;
The downloads are available in the &lt;a href=&quot;http://downloads.edujini-labs.com&quot;&gt;Downloads&lt;/a&gt; area.
&lt;/p&gt;
 
&lt;h2&gt;Getting Started&lt;/h2&gt;

&lt;p&gt;
In &lt;a href=&quot;http://eduzine.edujini-labs.com/archives/34-Exploring-OOPS-JavaScript-Style-Part-1-Encapsulation.html&quot;&gt;Part 1&lt;/a&gt;, we defined &lt;code&gt;UserProfile&lt;/code&gt; with &lt;code&gt;username&lt;/code&gt; and &lt;code&gt;password&lt;/code&gt;. In this article, we create &lt;code&gt;EmployeeProfile&lt;/code&gt; that inherits from &lt;code&gt;UserProfile&lt;/code&gt; and adds &lt;code&gt;employeeID&lt;/code&gt;. It also reimplements (override, if you like to use that word) &lt;code&gt;authenticate&lt;/code&gt; method.
&lt;/p&gt;

&lt;h2&gt;&lt;code&gt;EmployeeProfile&lt;/code&gt; Definition&lt;/h2&gt;

&lt;p&gt;
We start with defining &lt;code&gt;EmployeeProfile&lt;/code&gt; with &lt;code&gt;employeeID&lt;/code&gt; besides earlier properties. Create a file &lt;code&gt;EmployeeProfile.js&lt;/code&gt; with the following code:
&lt;/p&gt;

&lt;pre&gt;/**
 &lt;strong&gt; Part of the Eduzine (http://eduzine.edujini-labs.com) Articles.
 &lt;/strong&gt;
 &lt;strong&gt; Downloads available at http://downloads.edujini-labs.com
 &lt;/strong&gt;
 &lt;strong&gt; (C) 2008, Edujini Labs Pvt Ltd
 &lt;/strong&gt; http://www.edujini-labs.com
 &lt;strong&gt;/

function EmployeeProfile(username, password, employeeID)
{
  this.username = username;
  this.password = password;
  this.employeeID = employeeID;
}
&lt;/pre&gt;

&lt;p&gt;
The next step is to mark it inherited from &lt;code&gt;UserProfile&lt;/code&gt;. For this, we need to work with the property &lt;code&gt;prototype&lt;/code&gt; that is always available to us whenever we declare a function. (Note that all functions can be used as constructor.) Add the following additional code at the end of the code above:
&lt;/p&gt;

&lt;pre&gt;EmployeeProfile.prototype = new UserProfile();
&lt;/pre&gt;

&lt;p&gt;
Note the following:
&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The inerhitance is defined not through the data-type &lt;code&gt;UserProfile&lt;/code&gt; but through its instance.&lt;/li&gt;
  &lt;li&gt;The instance of &lt;code&gt;UserProfile&lt;/code&gt; has been created without passing any parameters to the method.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;Testing the Definition&lt;/h2&gt;

&lt;p&gt;
So, it's time to test the definition so far... Let's create &lt;code&gt;EmployeeProfile.html&lt;/code&gt; with the following content:
&lt;/p&gt;

&lt;pre&gt;&amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;OOPS in JavaScript - Inheritance&amp;lt;/code&amp;gt;
    &amp;lt;script language='javascript' type='text/javascript' src='UserProfile.js'&amp;gt;&amp;lt;/script&amp;gt;
    &lt;b&gt;&amp;lt;script language='javascript' type='text/javascript' src='EmployeeProfile.js'&amp;gt;&amp;lt;/script&amp;gt;&lt;/b&gt;
    &amp;lt;script language='javascript' type='text/javascript'&amp;gt;
      /**
       &lt;/strong&gt; Part of the Eduzine (http://eduzine.edujini-labs.com) Articles.
       &lt;strong&gt;
       &lt;/strong&gt; Downloads available at http://downloads.edujini-labs.com
       &lt;strong&gt;
       &lt;/strong&gt; (C) 2008, Edujini Labs Pvt Ltd
       &lt;strong&gt; http://www.edujini-labs.com
       &lt;/strong&gt;/
      function validateUser()
      {
        &lt;b&gt;var eid = document.getElementById('i').value;&lt;/b&gt;
        var uname = document.getElementById('u').value;
        var pwd = document.getElementById('p').value;

        var e = document.getElementById('result');

        &lt;b&gt;var ep = new EmployeeProfile(uname, pwd, eid);
        e.innerHTML = 'Username: ' + ep.username
          + '&amp;lt;br/&amp;gt;Password: ' + ep.password
          + '&amp;lt;br/&amp;gt;EmployeeID: ' + ep.employeeID
          + '&amp;lt;br/&amp;gt;Authenticate: ' + ep.authenticate();&lt;/b&gt;
      }
    &amp;lt;/script&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
  Employee ID: &amp;lt;input type='text' name='i' id='i' /&amp;gt;
  &amp;lt;br/&amp;gt;
  Username: &amp;lt;input type='text' name='u' id='u' /&amp;gt;
  &amp;lt;br/&amp;gt;
  Password: &amp;lt;input type='password' name='p' id='p' /&amp;gt;
  &amp;lt;br/&amp;gt;

  &amp;lt;button onclick='validateUser(); return false;'&amp;gt;Login&amp;lt;/button&amp;gt;

  &amp;lt;div id='result'&amp;gt;&amp;lt;/div&amp;gt;

  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/pre&gt;

&lt;p&gt;
I think the code is self explanatory. What we get is not only the three properties but also automatic definition of &lt;code&gt;authenticate&lt;/code&gt; method for &lt;code&gt;EmployeeProfile&lt;/code&gt;. After all, that's that inheritance is all about. In the definition of &lt;code&gt;EmployeeProfile&lt;/code&gt;, we never mention about it but it is automatically available to it through its parent object &lt;code&gt;UserProfile&lt;/code&gt;.
&lt;/p&gt;

&lt;h2&gt;&lt;code&gt;instanceof&lt;/code&gt; Operator&lt;/h2&gt;

&lt;p&gt;
We'll explore method overriding and other complex (unexplored, not mentioned so far) things in a while. We take a short while to look at &lt;code&gt;instanceof&lt;/code&gt; operator.
&lt;/p&gt;

&lt;p&gt;
It is a binary operator. The left operand is the object-reference and the right operand is the function-definition (data-type reference). The operator returns a boolean value indicating &lt;i&gt;whether the object is an instance of the corresponding type or not&lt;/i&gt;.
&lt;/p&gt;

&lt;pre&gt;if(ep &lt;b&gt;instanceof&lt;/b&gt; UserProfile)
{
  alert('ep is an instance of type UserProfile');
} else
{
  alert('ep is NOT an instance of type UserProfile');
}
&lt;/pre&gt;

&lt;p&gt;
You can add this code to the method &lt;code&gt;validateUser&lt;/code&gt;. In our case, it must return &lt;code&gt;true&lt;/code&gt;. Similarly, &lt;code&gt;&lt;em&gt;obj instanceof Object&lt;/em&gt;&lt;/code&gt; for any non-&lt;code&gt;null&lt;/code&gt; value for &lt;code&gt;obj&lt;/code&gt; will return &lt;code&gt;true&lt;/code&gt;.
&lt;/p&gt;

&lt;h2&gt;Method Reference and Optimization&lt;/h2&gt;

&lt;p&gt;
And a very crutial item before we get back on to our main agenda.
&lt;/p&gt;

&lt;p&gt;
Depending upon how we write the code, the methods may be loaded in memory multiple times. Which is bad for the appliation. We do not want identical piece of code to be loaded in memory multiple times. The code must be loaded only once and be executed in the context of the corresponding object. What am I talking? Update the code for the method &lt;code&gt;validateUser&lt;/code&gt; to as follows:
&lt;/p&gt;

&lt;pre&gt;function validateUser()
{
  var eid = document.getElementById('i').value;
  var uname = document.getElementById('u').value;
  var pwd = document.getElementById('p').value;

  &lt;b&gt;var ep1 = new EmployeeProfile(uname, pwd, eid);
  var ep2 = new EmployeeProfile(uname, pwd, eid);&lt;/b&gt;

  alert('Are references same? ' + (ep1.authenticate == ep2.authenticate));
}
&lt;/pre&gt;

&lt;p&gt;
You are bound to get a &lt;code&gt;false&lt;/code&gt;! It hurts. &lt;img src=&quot;http://eduzine.edujini-labs.com/templates/default/img/emoticons/sad.png&quot; alt=&quot;:-(&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
Everytime we instantiate &lt;code&gt;EmployeeProfile&lt;/code&gt; (or even &lt;code&gt;UserProfile&lt;/code&gt; for that matter), code for the method &lt;code&gt;authenticate&lt;/code&gt; is loaded into memory. Imagine if we have 1000 instances. Not only the properties are loaded into memory 1000 times, but also the code for the method. It's just too bad.
&lt;/p&gt;

&lt;p&gt;
Let's fix this up...
&lt;/p&gt;

&lt;p&gt;
Update the code for &lt;code&gt;UserProfile&lt;/code&gt; to as follows:
&lt;/p&gt;

&lt;pre&gt;function UserProfile(username, password)
{
  this.username = username;
  this.password = password;
}

&lt;b&gt;UserProfile.prototype.authenticate = function()
{
  if(this.username == 'gvaish' &amp;amp;&amp;amp; this.password == 'edujini')
  {
    return true;
  }
  return false;
}&lt;/b&gt;
&lt;/pre&gt;

&lt;p&gt;
Notice the use of &lt;code&gt;prototype&lt;/code&gt; property once again. That holds the key! That's probably - &lt;i&gt;The Key&lt;/i&gt; property in JavaScript.
&lt;/p&gt;

&lt;p&gt;
Now, execute the test case once again. &lt;code&gt;ep1.authenticate == ep1.authenticate&lt;/code&gt; must return true in this case! Detailed discussion around &lt;code&gt;prototype&lt;/code&gt; is out of the scope of this article... but will have one some time soon.
&lt;/p&gt;

&lt;h2&gt;Method Overriding&lt;/h2&gt;

&lt;p&gt;
Next, we explore how to override the method &lt;code&gt;authenticate&lt;/code&gt;. Update the definition of &lt;code&gt;EmployeeProfile&lt;/code&gt; to as given below:
&lt;/p&gt;

&lt;pre&gt;function EmployeeProfile(username, password, employeeID)
{
  this.username = username;
  this.password = password;
  this.employeeID = employeeID;
}

EmployeeProfile.prototype = new UserProfile();

&lt;b&gt;EmployeeProfile.prototype.authenticate = function()
{
  if(this.employeeID == 123 &amp;amp;&amp;amp; this.username == 'gvaish'
                  &amp;amp;&amp;amp; this.password == 'edujini')
  {
    return true;
  }
  return false;
}&lt;/b&gt;
&lt;/pre&gt;

&lt;p&gt;
Go ahead and authenticate with various compbinations of the &lt;code&gt;employeeID&lt;/code&gt;, &lt;code&gt;username&lt;/code&gt; and &lt;code&gt;password&lt;/code&gt;. Hurray! The method has been overridden (using the line of hierarchy of the object &lt;code&gt;prototype&lt;/code&gt;).
&lt;/p&gt;

&lt;p&gt;
The last thing that we see in method overriding is how to invoke the base-type method in the sub-type method. Well, the solution again lies in &lt;code&gt;prototype&lt;/code&gt;!
&lt;/p&gt;

&lt;p&gt;
Let us define the business logic for an employee's authentication as follows:
&lt;/p&gt;

&lt;ol&gt;
	&lt;li&gt;It checks for the authentication results from &lt;code&gt;UserProfile&lt;/code&gt;. If it has failed, the result is failure.&lt;/li&gt;
	&lt;li&gt;It additionally checks for &lt;code&gt;employeeID&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;
This way we keep &lt;code&gt;EmployeeProfile&lt;/code&gt; independent of how the &lt;code&gt;UserProfile&lt;/code&gt; authenticates itself. Modify &lt;code&gt;EmployeeProfile&lt;/code&gt; to as follows:
&lt;/p&gt;

&lt;pre&gt;function EmployeeProfile(username, password, employeeID)
{
  this.username = username;
  this.password = password;
  this.employeeID = employeeID;
}

EmployeeProfile.prototype = new UserProfile();

&lt;b&gt;EmployeeProfile.prototype._authenticate = EmployeeProfile.prototype.authenticate;&lt;/b&gt;

EmployeeProfile.prototype.authenticate = function()
{
  &lt;b&gt;if(this._authenticate())
  {
    return this.employeeID == 123;
  }
  return false;&lt;/b&gt;
}
&lt;/pre&gt;

&lt;p&gt;
Note that this is one of the various possible ways of achieving our target. We create a reference &lt;code&gt;_authenticate&lt;/code&gt; to the original &lt;code&gt;authenticate&lt;/code&gt; method (but did we get it from &lt;code&gt;EmployeeProfile&lt;/code&gt; since we defined it in &lt;code&gt;UserProfile&lt;/code&gt; - that's the magic of &lt;code&gt;prototype&lt;/code&gt; in JavaScript).
&lt;/p&gt;

&lt;p&gt;
Rerun your test case... Wow! We get what we expect...
&lt;/p&gt;

&lt;h2&gt;Summary&lt;/h2&gt;

&lt;p&gt;
In this article we learnt how encapsulation is implemented in JavaScript. To summarize, we explored the following:
&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Inheritance in JavaScript.&lt;/li&gt;
  &lt;li&gt;Use of &lt;code&gt;prototype&lt;/code&gt; property to mark inheritance.&lt;/li&gt;
  &lt;li&gt;Defining new methods in the inherited type.&lt;/li&gt;
  &lt;li&gt;Override existing methods, optionally also calling the original method.&lt;/li&gt;
  &lt;li&gt;&lt;code&gt;instanceof&lt;/code&gt; operator to check the underlying data-type inheritance hierarchy.&lt;/li&gt;
&lt;/ul&gt;

    </description>
        <dc:publisher>Eduzine©</dc:publisher>
    <dc:creator>eduzine@edujinionline.com (Eduzine)</dc:creator>
    <dc:subject>JavaScript, Web 2.0, RIA</dc:subject>
    <dc:date>2008-06-17T21:33:51Z</dc:date>
    <wfw:comment>http://eduzine.edujini-labs.com/wfwcomment.php?cid=35</wfw:comment>
    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://eduzine.edujini-labs.com/rss.php?version=1.0&amp;type=comments&amp;cid=35</wfw:commentRss>
</item>
<item rdf:about="http://eduzine.edujini-labs.com/archives/34-guid.html">
    <title>Exploring OOPS - JavaScript Style: Part 1 - Encapsulation</title>
    <link>http://eduzine.edujini-labs.com/archives/34-Exploring-OOPS-JavaScript-Style-Part-1-Encapsulation.html</link>
    <description>

&lt;h2&gt;Introduction&lt;/h2&gt;

&lt;p&gt;
As promised in one of the earlier articles, we discuss about how the various pillars of OOPS are implemented in JavaScript.
&lt;/p&gt;

&lt;p&gt;
Obect Oriented Programming - as defined by Grady Booch - stands on three pillars:
&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Encapsulation&lt;/li&gt;
  &lt;li&gt;Inheritance&lt;/li&gt;
  &lt;li&gt;Polymorphism&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
Here, we explore how all three - Yes! All Three Pillars of OOPS - are implemented in JavaScript.
&lt;/p&gt;

&lt;h2&gt;Downloads&lt;/h2&gt;

&lt;p&gt;
The downloads are available in the &lt;a href=&quot;http://downloads.edujini-labs.com&quot;&gt;Downloads&lt;/a&gt; area.
&lt;/p&gt;

 
&lt;h2&gt;Getting Started&lt;/h2&gt;

&lt;p&gt;
To get started, it is assumed that you are already familiar with basic JavaScript. If not you can look on the web for some tutorials on JavaScript 101 tutorials or the like. To be specific, the following fundamentals are assume:
&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Declaring variables - &lt;code&gt;var&lt;/code&gt; keyword.&lt;/li&gt;
  &lt;li&gt;Basic data types supported - &lt;code&gt;Object&lt;/code&gt;, &lt;code&gt;Array&lt;/code&gt;, &lt;code&gt;Boolean&lt;/code&gt;, &lt;code&gt;Number&lt;/code&gt;, &lt;code&gt;String&lt;/code&gt; and &lt;code&gt;Function&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Writing functions - well, you got to be really very strong in functions!&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;4-Sutras while working with JavaScript&lt;/h2&gt;

&lt;p&gt;
While working with JavaScript, always keep in mind the following, as &lt;a href=&quot;http://www.mastergaurav.com/&quot;&gt;Gaurav Vaish&lt;/a&gt; calls them, &lt;a href=&quot;http://blogs.mastergaurav.com/2008/06/16/4-sutras-to-work-with-javascript/&quot;&gt;&amp;quot;4-Sutras&amp;quot;&lt;/a&gt;:
&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;All data-types are infinitely flexible.&lt;/li&gt;
  &lt;li&gt;All objects (references; instances) are infinitely extensible.&lt;/li&gt;
  &lt;li&gt;Objects are associative arrays.&lt;/li&gt;
  &lt;li&gt;It's all about functions.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;
&amp;quot;In JavaScript, whenever you run into any problem related to implementation or structuring of the code, these four sutras will help you out&amp;quot;, says &lt;a href=&quot;http://blogs.mastergaurav.com/2008/06/16/4-sutras-to-work-with-javascript/&quot;&gt;Gaurav&lt;/a&gt;.
&lt;/p&gt;

&lt;h2&gt;Encapsulation&lt;/h2&gt;

&lt;p&gt;
Encapsulation - in simplest terms - can be defined as putting the related items together. Structures in C is a way to implement encapsulation. Classes in C++, Java, C# etc is another way to implement encapsulation.
&lt;/p&gt;

&lt;p&gt;
Let us see how encapsulation is implemented in JavaScript.
&lt;/p&gt;

&lt;h2&gt;Welcome, Functions!&lt;/h2&gt;

&lt;p&gt;
Gaurav's 4&lt;sup&gt;th&lt;/sup&gt; Sutra comes into action here - &amp;quot;It's all about functions&amp;quot;.
&lt;/p&gt;

&lt;p&gt;
Let us define a data-type &lt;code&gt;UserProfile&lt;/code&gt; that encapsulates the following three items:
&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;code&gt;username&lt;/code&gt;: Property to hold the username of the user.&lt;/li&gt;
  &lt;li&gt;&lt;code&gt;password&lt;/code&gt;: Property to hold the password of the user.&lt;/li&gt;
  &lt;li&gt;&lt;code&gt;authenticate&lt;/code&gt;: Method to authenticate the user. Returns &lt;code&gt;true&lt;/code&gt; if successful, &lt;code&gt;false&lt;/code&gt; otherwise.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;
Let us implement the &lt;code&gt;UserProfile&lt;/code&gt; with a constructor that takes the two properties as parameters and initializes itself. Create a file &lt;code&gt;UserProfile.js&lt;/code&gt; (strictly speaking, the filename doesn't really matter) with the following code.
&lt;/p&gt;

&lt;pre&gt;/**&lt;br /&gt; &lt;strong&gt; Part of the Eduzine (http://eduzine.edujini-labs.com) Articles.&lt;br /&gt; &lt;/strong&gt;&lt;br /&gt; &lt;strong&gt; Downloads available at http://downloads.edujini-labs.com&lt;br /&gt; &lt;/strong&gt;&lt;br /&gt; &lt;strong&gt; (C) 2008, Edujini Labs Pvt Ltd&lt;br /&gt; &lt;/strong&gt; http://www.edujini-labs.com&lt;br /&gt; &lt;strong&gt;/&lt;br /&gt;&lt;br /&gt;function UserProfile(username, password)&lt;br /&gt;{&lt;br /&gt;  this.username = username;&lt;br /&gt;  this.password = password;&lt;br /&gt;&lt;br /&gt;  this.authenticate = function()&lt;br /&gt;  {&lt;br /&gt;    if(this.username == 'gvaish' &amp;amp;&amp;amp; this.password == 'edujini')&lt;br /&gt;    {&lt;br /&gt;      return true;&lt;br /&gt;    }&lt;br /&gt;    return false;&lt;br /&gt;  }&lt;br /&gt;}&lt;/pre&gt;

&lt;p&gt;
Notice the use of &lt;code&gt;this&lt;/code&gt; keyword. Does it remind you of someting? Yes! You got it right... &lt;code&gt;function&lt;/code&gt; is the way to implement the concept of &lt;code&gt;class&lt;/code&gt;, or to speak - encapsulation.
&lt;/p&gt;

&lt;h2&gt;Test Case&lt;/h2&gt;

&lt;p&gt;
Ok... so, how do we use this new data-type that we just defined? Let's create a HTML file that will serve as the playground for our case-studies around the &lt;code&gt;UserProfile&lt;/code&gt;. Create a file &lt;code&gt;UserProfile.html&lt;/code&gt; (again, filename is not important at all) with the following content:
&lt;/p&gt;

&lt;pre&gt; 1 &amp;lt;html&amp;gt;&lt;br /&gt; 2   &amp;lt;head&amp;gt;&lt;br /&gt; 3     &amp;lt;title&amp;gt;OOPS in JavaScript- Encapsulation&amp;lt;/code&amp;gt;&lt;br /&gt; 4     &amp;lt;script language='javascript' type='text/javascript' src='UserProfile.js'&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt; 5     &amp;lt;script language='javascript' type='text/javascript'&amp;gt;&lt;br /&gt; 6       /**&lt;br /&gt; 7        &lt;/strong&gt; Part of the Eduzine (http://eduzine.edujini-labs.com) Articles.&lt;br /&gt; 8        &lt;strong&gt;&lt;br /&gt; 9        &lt;/strong&gt; Downloads available at http://downloads.edujini-labs.com&lt;br /&gt;10        &lt;strong&gt;&lt;br /&gt;11        &lt;/strong&gt; (C) 2008, Edujini Labs Pvt Ltd&lt;br /&gt;12        &lt;strong&gt; http://www.edujini-labs.com&lt;br /&gt;13        &lt;/strong&gt;/&lt;br /&gt;14       function validateUser()&lt;br /&gt;15       {&lt;br /&gt;16         var uname = document.getElementById('u').value;&lt;br /&gt;17         var pwd = document.getElementById('p').value;&lt;br /&gt;18&lt;br /&gt;19         var e = document.getElementById('result');&lt;br /&gt;20&lt;br /&gt;21         var u = new UserProfile(uname, pwd);&lt;br /&gt;22         var result = u.authenticate();&lt;br /&gt;23         e.innerHTML = 'Result: ' + result;&lt;br /&gt;24       }&lt;br /&gt;25     &amp;lt;/script&amp;gt;&lt;br /&gt;26   &amp;lt;/head&amp;gt;&lt;br /&gt;27   &amp;lt;body&amp;gt;&lt;br /&gt;28&lt;br /&gt;29   Username: &amp;lt;input type='text' name='u' id='u' /&amp;gt;&lt;br /&gt;30   &amp;lt;br/&amp;gt;&lt;br /&gt;31   Password: &amp;lt;input type='password' name='p' id='p' /&amp;gt;&lt;br /&gt;32   &amp;lt;br/&amp;gt;&lt;br /&gt;33&lt;br /&gt;34   &amp;lt;button onclick='validateUser(); return false;'&amp;gt;Login&amp;lt;/button&amp;gt;&lt;br /&gt;35&lt;br /&gt;36   &amp;lt;div id='result'&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;37&lt;br /&gt;38   &amp;lt;/body&amp;gt;&lt;br /&gt;30 &amp;lt;/html&amp;gt;&lt;/pre&gt;

&lt;h2&gt;Analysis&lt;/h2&gt;

&lt;p&gt;
Let's just analyze the code that we just wrote.
&lt;/p&gt;

&lt;p&gt;
We have designed a simple form comprising of inputs for username and password, and a button to trigger validation.
&lt;/p&gt;

&lt;p&gt;
The function &lt;code&gt;validateUser&lt;/code&gt; defined at line 14-24 triggers the validation by extracting the values of username and password (lines 16-17).
&lt;/p&gt;

&lt;p&gt;
At line 21, &lt;code&gt;UserProfile&lt;/code&gt; is instantiated. Notice a very important thing - the function definition has been used as the constructor. Yes! That's where functions are so important in JavaScript. The functions in JavaScript are higher order functions (similar to that in Smalltalk), that can be used to retain the state.
&lt;/p&gt;

&lt;p&gt;
At line 22, we invoke the method &lt;code&gt;authenticate&lt;/code&gt; that returns a value &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt; depending upon what we enter in the form.
&lt;/p&gt;

&lt;p&gt;
So, go ahead and try out with different combinations of username and password, and checkout the results!
&lt;/p&gt;

&lt;h2&gt;Summary&lt;/h2&gt;

&lt;p&gt;
In this article we learnt how encapsulation is implemented in JavaScript. To summarize, we explored the following:
&lt;/p&gt;

&lt;ul&gt;
	&lt;li&gt;Encapsulation in JavaScript.&lt;/li&gt;
	&lt;li&gt;Use of &lt;code&gt;this&lt;/code&gt; keyword within the type definition.&lt;/li&gt;
	&lt;li&gt;Defining properties and methods in JavaScript.&lt;/li&gt;
&lt;/ul&gt;

    </description>
        <dc:publisher>Eduzine©</dc:publisher>
    <dc:creator>eduzine@edujinionline.com (Eduzine)</dc:creator>
    <dc:subject>JavaScript, Web 2.0, RIA, OOAD</dc:subject>
    <dc:date>2008-06-16T21:53:49Z</dc:date>
    <wfw:comment>http://eduzine.edujini-labs.com/wfwcomment.php?cid=34</wfw:comment>
    <slash:comments>3</slash:comments>
    <wfw:commentRss>http://eduzine.edujini-labs.com/rss.php?version=1.0&amp;type=comments&amp;cid=34</wfw:commentRss>
</item>
<item rdf:about="http://eduzine.edujini-labs.com/archives/33-guid.html">
    <title>Creating Custom Widget in Dojo - Part 2: Templated Widgets</title>
    <link>http://eduzine.edujini-labs.com/archives/33-Creating-Custom-Widget-in-Dojo-Part-2-Templated-Widgets.html</link>
    <description>

&lt;h2&gt;Introduction&lt;/h2&gt;

&lt;p&gt;
In the &lt;a href=&quot;http://eduzine.edujini-labs.com/archives/32-Creating-Custom-Widget-in-Dojo-Part-1.html&quot;&gt;Part 1&lt;/a&gt; of the series, we learnt how to get started with creating custom UI widgets using &lt;a href=&quot;http://dojotoolkit.org&quot;&gt;Dojo Toolkit&lt;/a&gt;. In Part 2, learn to separate the UI from the business logic. Technically, we learn how to use templates to design the UI using simple HTML while keeping the functionality as separate JavaScript code.
&lt;/p&gt;

&lt;h2&gt;Downloads&lt;/h2&gt;

&lt;p&gt;
The downloads, as ever, are available in the &lt;a href=&quot;http://downloads.edujini-labs.com&quot;&gt;downloads area&lt;/a&gt;.
&lt;/p&gt;

&lt;h2&gt;Templated Widgets&lt;/h2&gt;

&lt;p&gt;
Dijit sub-framework in Dojo Toolkit provides a support for templated widgets through the object &lt;code&gt;dijit._Templated&lt;/code&gt;. Well, we do not inherit this but use as a mixin and choose &lt;code&gt;dijit._Widget&lt;/code&gt; as the parent object.
&lt;/p&gt;
 
&lt;h2&gt;Widget Definition&lt;/h2&gt;

&lt;p&gt;
For our purpose of demonstration, we create a simple anchor widget. Yes, it's the &lt;code&gt;&amp;lt;a href='...'&amp;gt;...&amp;lt;/a&amp;gt;&lt;/code&gt; thing!
&lt;/p&gt;

&lt;p&gt;
The widget supports the following properties:
&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;code&gt;href&lt;/code&gt;: The hyperlink to point to.&lt;/li&gt;
  &lt;li&gt;&lt;code&gt;text&lt;/code&gt;: The text to be displayed to the end user.&lt;/li&gt;
  &lt;li&gt;&lt;code&gt;target&lt;/code&gt;: The target window for the anchor (Optional).&lt;/li&gt;
  &lt;li&gt;&lt;code&gt;title&lt;/code&gt;: Title for the anchor element (Optional).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;Widget Implementation&lt;/h2&gt;

&lt;p&gt;
Assuming that you have the folder layout as in the previous article (&lt;a href=&quot;http://eduzine.edujini-labs.com/archives/32-Creating-Custom-Widget-in-Dojo-Part-1.html&quot;&gt;see here for reference&lt;/a&gt;), create a file &lt;code&gt;/home/edujini/eduzine/dojo/edujini/Anchor.js&lt;/code&gt; with the following contents.
&lt;/p&gt;

&lt;pre&gt;/**
 &lt;strong&gt; Part of the Eduzine (http://eduzine.edujini-labs.com) Articles.
 &lt;/strong&gt;
 &lt;strong&gt; Downloads available at http://downloads.edujini-labs.com
 &lt;/strong&gt;
 &lt;strong&gt; (C) 2008, Edujini Labs Pvt Ltd
 &lt;/strong&gt; http://www.edujini-labs.com
 &lt;strong&gt;/

dojo.provide(&amp;quot;edujini.Anchor&amp;quot;);
dojo.require(&amp;quot;dijit._Widget&amp;quot;);
dojo.require(&amp;quot;dijit._Templated&amp;quot;);

dojo.declare(&amp;quot;edujini.Anchor&amp;quot;, [dijit._Widget, dijit._Templated],
{
  text: '',
  href: '',
  target: '',
  title: '',

  templateString  : null,
  templatePath    : dojo.moduleUrl('edujini', 'templates/Anchor.html'),
});
&lt;/pre&gt;

&lt;p&gt;
Notice the following things in the component definition:
&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;The parent object is not a single entry &lt;code&gt;dijit._Wiget&lt;/code&gt; but an array comprising of &lt;code&gt;dijit._Widget&lt;/code&gt; and &lt;code&gt;dijit._Templated&lt;/code&gt;.&lt;/li&gt;
	&lt;li&gt;It contains two properties - &lt;code&gt;templateString&lt;/code&gt; and &lt;code&gt;templatePath&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;
The intepretatin of the items in the array is as follows:
&lt;/p&gt;

&lt;ol&gt;
	&lt;li&gt;The first entry indicates the parent object - in this case, &lt;code&gt;dijit._Widget&lt;/code&gt;.&lt;/li&gt;
	&lt;li&gt;The subsequent entries - in this case, only, &lt;code&gt;dijit._Templated&lt;/code&gt; - indicate the objects from where the properties have to be &amp;quot;borrowed&amp;quot; or &amp;quot;overridden&amp;quot;. For example, if both &lt;code&gt;dijit._Widget&lt;/code&gt; and &lt;code&gt;dijit._Templated&lt;/code&gt; have the method &lt;code&gt;buildRendering&lt;/code&gt;, the final definition that will survive is that of &lt;code&gt;dijit._Templated&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;Template Definition&lt;/h2&gt;

&lt;p&gt;
How that we have initial definition (components) of the &lt;code&gt;edujini.Anchor&lt;/code&gt; widget ready, let's go ahead and design the layout. Create a file &lt;code&gt;/home/edujini/eduzine/dojo/edujini/templates/Anchor.html&lt;/code&gt; with the following contents:
&lt;/p&gt;

&lt;pre&gt;&amp;lt;span class='edujiniAnchor' dojoAttachPoint='domNode'
  &amp;gt;&amp;lt;a href='${href}' dojoAttachPoint='anchorNode'&amp;gt;${text}&amp;lt;/a&amp;gt;&amp;lt;/span&amp;gt;
&lt;/pre&gt;

&lt;p&gt;
Ensure that there is not trailing newline after &lt;code&gt;&amp;lt;/span&amp;gt;&lt;/code&gt;
&lt;/p&gt;

&lt;p&gt;
The interpretation of the layout is as follows:
&lt;/p&gt;

&lt;ul&gt;
	&lt;li&gt;The complete definition is encapsulated in a &lt;code&gt;span&lt;/code&gt; which comprises of the anchor element.&lt;/li&gt;
	&lt;li&gt;The &lt;code&gt;href&lt;/code&gt; attribute of the anchor element has the value as that of the property &lt;code&gt;href&lt;/code&gt; of the object &lt;code&gt;edujini.Anchor&lt;/code&gt; (Syntax &lt;code&gt;${href}&lt;/code&gt;).&lt;/li&gt;
	&lt;li&gt;The content within the anchor element has the value as that of the property &lt;code&gt;text&lt;/code&gt; of the &lt;code&gt;edujini.Anchor&lt;/code&gt; object.&lt;/li&gt;
	&lt;li&gt;Note that we have still not made use of &lt;code&gt;target&lt;/code&gt; and &lt;code&gt;title&lt;/code&gt; properties. We need to have logic for it!&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;Test Case&lt;/h2&gt;

&lt;p&gt;
Let's create a file &lt;code&gt;/home/edujini/eduzine/dojo/test-templated-widget.html&lt;/code&gt; with the following content:
&lt;/p&gt;

&lt;pre&gt;&amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;Edujini Tempalted Widget Test Case&amp;lt;/title&amp;gt;

    &amp;lt;script type=&amp;quot;text/javascript&amp;quot; language='javascript' src=&amp;quot;dojo/dojo/dojo.js&amp;quot; djConfig=&amp;quot;isDebug: true, parseOnLoad: true&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;script type='text/javascript' language='javascript'&amp;gt;
      dojo.require('dijit.form.Button');
      dojo.require('edujini.Anchor');
    &amp;lt;/script&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
  &amp;lt;!--
    /**
     &lt;/strong&gt; Part of the Eduzine (http://eduzine.edujini-labs.com) Articles.
     &lt;strong&gt;
     &lt;/strong&gt; Downloads available at http://downloads.edujini-labs.com
     &lt;strong&gt;
     &lt;/strong&gt; (C) 2008, Edujini Labs Pvt Ltd
     &lt;strong&gt; http://www.edujini-labs.com
     &lt;/strong&gt;/
  --&amp;gt;
    &amp;lt;div id='a1' text='Hello, Edujini World!' href='http://www.edujini-labs.com' dojoType='edujini.Anchor'&amp;gt;&amp;lt;/div&amp;gt;
  &amp;lt;/body&amp;gt;

&amp;lt;/html&amp;gt;
&lt;/pre&gt;

&lt;p&gt;
Launch the HTML file in the browser... expected UI is:
&lt;br /&gt;
&lt;img border=&quot;1&quot; src=&quot;http://eduzine.edujini-labs.com/uploads/technology/javascript/dojo/33.Dojo.Custom.Widget-2.01.Initial.UI.jpg&quot; alt=&quot;Eduzine - Dojo - Custom Widget - Anchor&quot; title=&quot;Eduzine - Dojo - Custom Widget - Anchor&quot; /&gt;
&lt;/p&gt;


&lt;h2&gt;Finishing Touches&lt;/h2&gt;

&lt;p&gt;
The only functionality that remains is adding &lt;code&gt;target&lt;/code&gt; and/or &lt;code&gt;title&lt;/code&gt;, if provided. For that, we override the method &lt;code&gt;postCreate&lt;/code&gt; in &lt;code&gt;edujini.Anchor&lt;/code&gt;. The updated definition of the object is:
&lt;/p&gt;

&lt;pre&gt;dojo.declare(&amp;quot;edujini.Anchor&amp;quot;, [dijit._Widget, dijit._Templated],
{
  text: '',
  href: '',
  target: '',
  title: '',

  templateString  : null,
  templatePath    : dojo.moduleUrl('edujini', 'templates/Anchor.html'),

  &lt;b&gt;postCreate: function()
  {
    if(this.target)
    {
      this.anchorNode.setAttribute('target', this.target);
    }

    if(this.title)
    {
      this.anchorNode.setAttribute('title', this.title);
    }
  }&lt;/b&gt;
});
&lt;/pre&gt;

&lt;p&gt;
Let's also update the test case:
&lt;/p&gt;

&lt;pre&gt;&amp;lt;div id='a1' text='Hello, Edujini World!'
  &lt;b&gt;target='_edujini'
  title='Edujini Labs Home Page'&lt;/b&gt;
  href='http://www.edujini-labs.com'
  dojoType='edujini.Anchor'&amp;gt;&amp;lt;/div&amp;gt;
&lt;/pre&gt;

&lt;p&gt;
The expected UI is (after updates) is:
&lt;br /&gt;
&lt;img border=&quot;1&quot; src=&quot;http://eduzine.edujini-labs.com/uploads/technology/javascript/dojo/33.Dojo.Custom.Widget-2.02.Updated.UI.jpg&quot; alt=&quot;Eduzine - Dojo - Custom Widget - Anchor&quot; title=&quot;Eduzine - Dojo - Custom Widget - Anchor&quot; /&gt;
&lt;/p&gt;

&lt;h2&gt;Summary&lt;/h2&gt;

&lt;p&gt;
In this article, we learnt the following:
&lt;/p&gt;

&lt;ol&gt;
	&lt;li&gt;Create widgets with separated implementation for the layout (JavaScript) and the logic (HTML) - the &amp;quot;templated widgets&amp;quot;.&lt;/li&gt;
	&lt;li&gt;Declare properties in the widget definition (JavaScript) and use them in the template (HTML) - syntax being &lt;code&gt;${&lt;i&gt;property-name&lt;/i&gt;}&lt;/code&gt;.&lt;/li&gt;
	&lt;li&gt;How to set the attributes of the elements (well, that was plain vanilla W3C XML DOM API implementation in JavaScript), conditionally.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;Next Steps...&lt;/h2&gt;

&lt;p&gt;
Well, from this side... the next steps would be fulfill the earlier promise of an article on JavaScript - demonstrating the OOPS implementation in JavaScript.
&lt;/p&gt;

    </description>
        <dc:publisher>Eduzine©</dc:publisher>
    <dc:creator>eduzine@edujinionline.com (Eduzine)</dc:creator>
    <dc:subject>Dojo, Web 2.0, RIA</dc:subject>
    <dc:date>2008-06-14T00:00:00Z</dc:date>
    <wfw:comment>http://eduzine.edujini-labs.com/wfwcomment.php?cid=33</wfw:comment>
    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://eduzine.edujini-labs.com/rss.php?version=1.0&amp;type=comments&amp;cid=33</wfw:commentRss>
</item>
<item rdf:about="http://eduzine.edujini-labs.com/archives/32-guid.html">
    <title>Creating Custom Widget in Dojo - Part 1</title>
    <link>http://eduzine.edujini-labs.com/archives/32-Creating-Custom-Widget-in-Dojo-Part-1.html</link>
    <description>

&lt;p&gt;
Did you know that the &lt;a href=&quot;http://blogs.edujini-labs.com&quot;&gt;Edujini Gang&lt;/a&gt; is working on Dojo for more than a year now! Surprising right? Since there has been not a single entry on Dojo until the recent the &lt;a href=&quot;http://eduzine.edujini-labs.com/archives/29-Dojo-on-Google-Web-Toolkit.html&quot;&gt;recent announcement&lt;/a&gt; of the Project DWT (Dojo on Google Web Toolkit).
&lt;/p&gt;

&lt;h2&gt;Introduction&lt;/h2&gt;

&lt;p&gt;
&lt;a href=&quot;http://dojotoolkit.org&quot;&gt;Dojo Toolkit&lt;/a&gt; offers a simple yet powerful architecture to be able to create custom widgets. In Part 1 of the series of articles, we look at how to create a custom widget - probably with minimal styling and functionality.
&lt;/p&gt;

&lt;h2&gt;Downloads&lt;/h2&gt;

&lt;p&gt;
Yo! Buddy. The downloads are available in the &lt;a href=&quot;http://downloads.edujini-labs.com&quot;&gt;downloads area&lt;/a&gt;.
&lt;/p&gt;

 
&lt;h2&gt;What you should know...&lt;/h2&gt;

&lt;p&gt;
Well, you should be very comfortable with the following:
&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;JavaScript - By the way, did you know that JavaScript is Object Oriented? No? Ok... Will provide some articles soon.&lt;/li&gt;
  &lt;li&gt;Defining custom objects (I will not use the term class) in JavaScript using Dojo Toolkit. If not, you can have a peek in at &lt;a href=&quot;http://api.dojotoolkit.org/jsdoc/dojo/HEAD/dojo.declare&quot;&gt;Dojo Documentation&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;Getting Started&lt;/h2&gt;

&lt;p&gt;
Well, the first thing that you will need it Dojo Toolkit itself. You can download it from &lt;a href=&quot;http://dojotoolkit.org/downloads&quot;&gt;Dojo Downloads&lt;/a&gt;. And then, just a simple vanilla text editor - Notepad, TextPad, EditPlus, Notepad++ - just anything. &lt;img src=&quot;http://eduzine.edujini-labs.com/templates/default/img/emoticons/smile.png&quot; alt=&quot;:-)&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;
&lt;/p&gt;

&lt;h2&gt;Widget Definition&lt;/h2&gt;

&lt;p&gt;
Let us create a simple widget that will just say &amp;quot;Hello, World!&amp;quot; (hard-coded) to start with, and subsequently, the content will be customizable.
&lt;/p&gt;


&lt;h2&gt;Widget Implementation&lt;/h2&gt;

&lt;p&gt;
I assume that the Dojo Toolkit library (downloaded earlier) has been extracted in the folder &lt;code&gt;/home/edujini/eduzine/dojo&lt;/code&gt;. Let us create another folder &lt;code&gt;/home/edujini/eduzine/dojo/edujini&lt;/code&gt;. I will not discuss, here in this article, on how to specify a custom location for custom definitions in Dojo. That is out of scope of this article.
&lt;/p&gt;

&lt;p&gt;
Within this sub-folder, create a file &lt;code&gt;CustomWidget.js&lt;/code&gt; with the following contents:
&lt;/p&gt;

&lt;pre&gt;/**&lt;br /&gt; &lt;strong&gt; Part of the Eduzine (http://eduzine.edujini-labs.com) Articles.&lt;br /&gt; &lt;/strong&gt;&lt;br /&gt; &lt;strong&gt; Downloads available at http://downloads.edujini-labs.com&lt;br /&gt; &lt;/strong&gt;&lt;br /&gt; &lt;strong&gt; (C) 2008, Edujini Labs Pvt Ltd&lt;br /&gt; &lt;/strong&gt; http://www.edujini-labs.com&lt;br /&gt; &lt;strong&gt;/&lt;br /&gt;&lt;br /&gt;dojo.provide('edujini.CustomWidget');&lt;br /&gt;dojo.require('dijit._Widget');&lt;br /&gt;&lt;br /&gt;dojo.declare(&amp;quot;edujini.CustomWidget&amp;quot;, dijit._Widget,&lt;br /&gt;{&lt;br /&gt;  postCreate : function()&lt;br /&gt;  {&lt;br /&gt;    this.domNode.innerHTML = 'Hello, World!';&lt;br /&gt;  }&lt;br /&gt;});&lt;/pre&gt;

&lt;p&gt;
One of the more important functions of the object &lt;code&gt;dijit._Widget&lt;/code&gt; is &lt;code&gt;postCreate&lt;/code&gt;. We override the method to provide our implementation and that is to simply set the &lt;code&gt;innerHTML&lt;/code&gt; of the container to the text &lt;code&gt;Hello, World!&lt;/code&gt;.
&lt;/p&gt;

&lt;h2&gt;Using Custom Widget&lt;/h2&gt;

&lt;p&gt;
Ok... now that we have got the widget, we do not know how and if it works. So, let's just write a simple test page (HTML) to use it. Create a file &lt;code&gt;/home/edujini/eduzine/custom-widget-test.html&lt;/code&gt; with the following contents.
&lt;/p&gt;

&lt;pre&gt;&amp;lt;html&amp;gt;&lt;br /&gt;  &amp;lt;head&amp;gt;&lt;br /&gt;    &amp;lt;title&amp;gt;Edujini Custom Widget Test&amp;lt;/title&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;script type=&amp;quot;text/javascript&amp;quot; language='javascript' src=&amp;quot;dojo/dojo/dojo.js&amp;quot; djConfig=&amp;quot;isDebug: true, parseOnLoad: true&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;    &amp;lt;script type='text/javascript' language='javascript'&amp;gt;&lt;br /&gt;      dojo.require('dijit.form.Button');&lt;br /&gt;      dojo.require('edujini.CustomWidget');&lt;br /&gt;    &amp;lt;/script&amp;gt;&lt;br /&gt;  &amp;lt;/head&amp;gt;&lt;br /&gt;  &amp;lt;body&amp;gt;&lt;br /&gt;  &amp;lt;!--&lt;br /&gt;    /**&lt;br /&gt;     &lt;/strong&gt; Part of the Eduzine (http://eduzine.edujini-labs.com) Articles.&lt;br /&gt;     &lt;strong&gt;&lt;br /&gt;     &lt;/strong&gt; Downloads available at http://downloads.edujini-labs.com&lt;br /&gt;     &lt;strong&gt;&lt;br /&gt;     &lt;/strong&gt; (C) 2008, Edujini Labs Pvt Ltd&lt;br /&gt;     &lt;strong&gt; http://www.edujini-labs.com&lt;br /&gt;     &lt;/strong&gt;/&lt;br /&gt;  --&amp;gt;&lt;br /&gt;    &amp;lt;div id='w1' dojoType='edujini.CustomWidget'&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;  &amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/pre&gt;

&lt;p&gt;
With this, the response that we expect is something as given below (I've highlighted the output using the red-ellipse. You'll not get it):
&lt;/p&gt;

&lt;p&gt;
&lt;img title=&quot;Eduzine - Dojo - Custom Widget - Simple - Output&quot; alt=&quot;Eduzine - Dojo - Custom Widget - Simple - Output&quot; src=&quot;http://eduzine.edujini-labs.com/uploads/technology/javascript/dojo/32.Dojo.Custom.Widget-1-01.Output.jpg&quot; /&gt;
&lt;/p&gt;

&lt;h2&gt;Customizing the Widget&lt;/h2&gt;

&lt;p&gt;
The next step is to customize the &lt;code&gt;Hello, World!&lt;/code&gt; with a user defined content. Let's say that the default value of the content to be displayed is &lt;code&gt;Hello, World!&lt;/code&gt;. To this effect, update the &lt;code&gt;CustomWidget.js&lt;/code&gt; as follows (changes highlighted in bold):
&lt;/p&gt;

&lt;pre&gt;dojo.declare(&amp;quot;edujini.CustomWidget&amp;quot;, dijit._Widget,&lt;br /&gt;{&lt;br /&gt;  &lt;b&gt;text: 'Hello, World!',&lt;/b&gt;

  postCreate : function()
  {
    this.domNode.innerHTML = &lt;b&gt;this.text;&lt;/b&gt;
  }
});
&lt;/pre&gt;

&lt;p&gt;
Simultaneously, we update the &lt;code&gt;custom-widget-test.html&lt;/code&gt; file to as follows:
&lt;/p&gt;

&lt;pre&gt;  &amp;lt;body&amp;gt;&lt;br /&gt;    &amp;lt;div id='w1' &lt;b&gt;text='Hello, Edujini World!'&lt;/b&gt; dojoType='edujini.CustomWidget'&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;  &amp;lt;/body&amp;gt;&lt;/pre&gt;

&lt;p&gt;
And that's it! Look at the HTML file in the browser...
&lt;br /&gt;
&lt;img title=&quot;Eduzine - Dojo - Custom Widget - Simple - Custom Property&quot; alt=&quot;Eduzine - Dojo - Custom Widget - Simple - Custom Property&quot; src=&quot;http://eduzine.edujini-labs.com/uploads/technology/javascript/dojo/32.Dojo.Custom.Widget-1-02.Property.jpg&quot; /&gt;
&lt;/p&gt;

&lt;h2&gt;Summary&lt;/h2&gt;

&lt;p&gt;
In this article, we learnt:
&lt;/p&gt;

&lt;ul&gt;
	&lt;li&gt;To create a custom widget using Dojo Toolkit.&lt;/li&gt;
	&lt;li&gt;To create a property that can be used subsequently in the widget.&lt;/li&gt;
	&lt;li&gt;Had a brief venture into the method &lt;code&gt;postCreate&lt;/code&gt; - one of the key methods. It it called after all entries from the HTML have been read and parsed. We shall look into the details of this method later on when we explore the lifecycle of Dojo Widgets.&lt;/li&gt;
&lt;/ul&gt;

    </description>
        <dc:publisher>Eduzine©</dc:publisher>
    <dc:creator>eduzine@edujinionline.com (Eduzine)</dc:creator>
    <dc:subject>Dojo, Ajax, Web 2.0, RIA</dc:subject>
    <dc:date>2008-06-12T00:00:00Z</dc:date>
    <wfw:comment>http://eduzine.edujini-labs.com/wfwcomment.php?cid=32</wfw:comment>
    <slash:comments>3</slash:comments>
    <wfw:commentRss>http://eduzine.edujini-labs.com/rss.php?version=1.0&amp;type=comments&amp;cid=32</wfw:commentRss>
</item>
<item rdf:about="http://eduzine.edujini-labs.com/archives/29-guid.html">
    <title>Dojo on Google Web Toolkit</title>
    <link>http://eduzine.edujini-labs.com/archives/29-Dojo-on-Google-Web-Toolkit.html</link>
    <description>

&lt;p&gt;
&lt;b&gt;This is the updated version of the announcement - the License has been changed to &lt;a href=&quot;http://www.opensource.org/licenses/bsd-license.php&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 255);&quot;&gt;New BSD&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;
&lt;/p&gt;

&lt;p&gt;
To take the development experience with &lt;a href=&quot;http://dojotoolkit.org&quot;&gt;Dojo Toolkit&lt;/a&gt; on to the next level using &lt;a href=&quot;http://code.google.com/webtoolkit&quot;&gt;Google Web Toolkit&lt;/a&gt;, Edujini Labs plans to port Dojo Toolkit for GWT.
&lt;/p&gt;

&lt;p&gt;
The project would soon be hosted at SourceForge under both &lt;strike&gt;GPL v2/3&lt;/strike&gt; New BSD and commercial license. We have sought for the project name &amp;quot;DWT&amp;quot; (applied under APT process, and may take 2-3 weeks for complete takeover).
&lt;/p&gt;

&lt;br /&gt;

&lt;p&gt;
The project would be led by Gaurav Vaish, initially supported by core team comprising of
&lt;/p&gt;&lt;ul&gt;
  &lt;li&gt;Abdul Prodhani&lt;/li&gt;
  &lt;li&gt;Hair S Nair&lt;/li&gt;
  &lt;li&gt;Shake Sajan&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;

&lt;/p&gt;&lt;p&gt;
To get started, a quick proof-of-concept demo has been created. It's not a very clean implementation - just a get started stuff.
&lt;/p&gt;

&lt;p&gt;
&lt;object width=&quot;425&quot; height=&quot;350&quot;&gt; &lt;param name=&quot;movie&quot; value=&quot;http://www.youtube.com/v/SdEdJskMe0g&quot; /&gt;  &lt;embed width=&quot;425&quot; height=&quot;350&quot; src=&quot;http://www.youtube.com/v/SdEdJskMe0g&quot; type=&quot;application/x-shockwave-flash&quot; /&gt;  &lt;/object&gt;
&lt;/p&gt;

&lt;p&gt;
The video for the demo is available can be &lt;a href=&quot;http://eduzine.edujini-labs.com/uploads/edujini/dwt/01.Dojo-GWT-Hello-World.avi&quot;&gt;downloaded here&lt;/a&gt;.
&lt;/p&gt;

&lt;p&gt;
You can support this project by spreading the word, to start with &lt;img src=&quot;http://eduzine.edujini-labs.com/templates/default/img/emoticons/smile.png&quot; alt=&quot;:-)&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;. Just &amp;quot;Digg It&amp;quot;.&lt;br /&gt; Some people have reported problems with Digging the articles on Eduzine... if that's the case with you, &amp;quot;Digg This&amp;quot; - &lt;a href=&quot;http://blogs.edujini-labs.com/2008/05/30/dwt/&quot;&gt;http://blogs.edujini-labs.com/2008/05/30/dwt/&lt;/a&gt;
&lt;/p&gt;


     </description>
        <dc:publisher>Eduzine©</dc:publisher>
    <dc:creator>eduzine@edujinionline.com (Eduzine)</dc:creator>
    <dc:subject>JavaScript, Dojo, Ajax, GWT, Web 2.0, Edujini, Dojo GWT</dc:subject>
    <dc:date>2008-06-11T11:15:00Z</dc:date>
    <wfw:comment>http://eduzine.edujini-labs.com/wfwcomment.php?cid=29</wfw:comment>
    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://eduzine.edujini-labs.com/rss.php?version=1.0&amp;type=comments&amp;cid=29</wfw:commentRss>
</item>
<item rdf:about="http://eduzine.edujini-labs.com/archives/31-guid.html">
    <title>Flex Data Driven Controls - Part 2</title>
    <link>http://eduzine.edujini-labs.com/archives/31-Flex-Data-Driven-Controls-Part-2.html</link>
    <description>

&lt;h2&gt;Introduction&lt;/h2&gt;

&lt;p&gt;
In Part 2 of the series of articles on &amp;quot;Flex Data Driven Controls&amp;quot;, we learn about how to provide custom rendering to a data bound control. And we choose &lt;code&gt;List&lt;/code&gt;.
&lt;/p&gt;

&lt;p&gt;
In the previous article, &lt;a href=&quot;http://eduzine.edujini-labs.com/archives/30-Flex-Data-Driven-Controls-Part-1.html&quot;&gt;Part 1&lt;/a&gt; of the series, we got ourselves started with data driven controls - &lt;code&gt;ComboBox&lt;/code&gt; and &lt;code&gt;DataGrid&lt;/code&gt;. In this article, we will lean to cutomize the how the items are finally presented to the end user.
&lt;/p&gt;

&lt;p&gt;
The source code for this article is available in the &lt;a href=&quot;http://downloads.edujini-labs.com&quot;&gt;Downloads&lt;/a&gt; area.
&lt;/p&gt;

 
&lt;h2&gt;Getting Started&lt;/h2&gt;

&lt;p&gt;
We reuse the previous definition of &lt;code&gt;UserProfile&lt;/code&gt;. For completeness, the definition below is re-represented below:
&lt;/p&gt;

&lt;pre&gt;package com.edujinilabs.eduzine.tutorials.flex.core
{
  /**
   &lt;strong&gt; Part of the Eduzine (http://eduzine.edujini-labs.com) Articles.
   &lt;/strong&gt;
   &lt;strong&gt; Downloads available at http://downloads.edujini-labs.com
   &lt;/strong&gt;
   &lt;strong&gt; (C) 2008, Edujini Labs Pvt Ltd
   &lt;/strong&gt; http://www.edujini-labs.com
   */
  public class UserProfile
  {
    private var _employeeID : int;
    private var _employeeName: String;
    private var _departmentName: String;

    public function UserProfile(eid: int = 0, name: String = null, deptName: String = null)
    {
      this._employeeID = eid;
      this._employeeName = name;
      this._departmentName = deptName;
    }

    public function get employeeID(): int
    {
      return _employeeID;
    }

    public function set employeeID(eid: int) : void
    {
      this._employeeID = eid;
    }

    public function get employeeName(): String
    {
      return _employeeName;
    }

    public function set employeeName(name: String) : void
    {
      this._employeeName = name;
    }

    public function get departmentName(): String
    {
      return _departmentName;
    }

    public function set departmentName(name: String) : void
    {
      this._departmentName = name;
    }
  }
}
&lt;/pre&gt;

&lt;p&gt;
As far the user interface is concerned, we replace the &lt;code&gt;ComboBox&lt;/code&gt; with &lt;code&gt;List&lt;/code&gt; and remove &lt;code&gt;DataGrid&lt;/code&gt; from the previous MXML definition. There would be a need to customize the layout a bit. The final definition looks as follows (important changes have been marked in bold):
&lt;/p&gt;

&lt;pre&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;
&amp;lt;mx:Application xmlns:mx=&amp;quot;http://www.adobe.com/2006/mxml&amp;quot; layout=&amp;quot;absolute&amp;quot;
  height=&amp;quot;426&amp;quot; width=&amp;quot;400&amp;quot; borderThickness=&amp;quot;2&amp;quot; borderStyle=&amp;quot;solid&amp;quot;
  backgroundColor=&amp;quot;#F0F0F0&amp;quot; cornerRadius=&amp;quot;8&amp;quot;&amp;gt;

  &amp;lt;mx:Label text=&amp;quot;Edujini Labs Pvt Ltd&amp;quot; fontSize=&amp;quot;14&amp;quot; fontFamily=&amp;quot;Georgia&amp;quot;
  	fontWeight=&amp;quot;bold&amp;quot; fontStyle=&amp;quot;normal&amp;quot; color=&amp;quot;#F5A83B&amp;quot; left=&amp;quot;20&amp;quot; top=&amp;quot;20&amp;quot;/&amp;gt;

  &amp;lt;mx:Label x=&amp;quot;20&amp;quot; y=&amp;quot;64&amp;quot; text=&amp;quot;Edujini Team&amp;quot; fontFamily=&amp;quot;Verdana&amp;quot; fontSize=&amp;quot;10&amp;quot; fontWeight=&amp;quot;bold&amp;quot;/&amp;gt;

  &lt;b&gt;&amp;lt;mx:List id='eList' x=&amp;quot;20&amp;quot; y=&amp;quot;90&amp;quot; dataProvider=&amp;quot;{employees}&amp;quot; labelField=&amp;quot;employeeName&amp;quot;
  	cornerRadius=&amp;quot;4&amp;quot; width=&amp;quot;344&amp;quot; height=&amp;quot;265&amp;quot;&amp;gt;&lt;/b&gt;
  &amp;lt;/mx:List&amp;gt;

  &amp;lt;mx:Label x=&amp;quot;20&amp;quot; text=&amp;quot;© 2008, Edujini Labs Pvt Ltd&amp;quot; fontFamily=&amp;quot;Verdana&amp;quot;
  	fontSize=&amp;quot;10&amp;quot; fontWeight=&amp;quot;bold&amp;quot; bottom=&amp;quot;20&amp;quot;/&amp;gt;

  &amp;lt;mx:Script&amp;gt;
    &amp;lt;![CDATA[
      import com.edujinilabs.eduzine.tutorials.flex.core.UserProfile;
      import mx.collections.ArrayCollection;

      [Bindable]
      private var employees: ArrayCollection = new ArrayCollection(
      [
        new UserProfile(11, &amp;quot;Shake Sajan&amp;quot;, &amp;quot;Product Dev&amp;quot;),
        new UserProfile(24, &amp;quot;Meera&amp;quot;, &amp;quot;Training&amp;quot;),
        new UserProfile(23, &amp;quot;Neelam&amp;quot;, &amp;quot;Training&amp;quot;),
        new UserProfile(12, &amp;quot;Hari S Nair&amp;quot;, &amp;quot;Product Dev&amp;quot;),
        new UserProfile(13, &amp;quot;Abdul Prodhani&amp;quot;, &amp;quot;Product Dev&amp;quot;),
        new UserProfile(21, &amp;quot;Ashish Vaish&amp;quot;, &amp;quot;Training&amp;quot;),
        new UserProfile(10, &amp;quot;Gaurav Vaish&amp;quot;, &amp;quot;Technology&amp;quot;),
        new UserProfile(32, &amp;quot;Jagadish&amp;quot;, &amp;quot;Marketing&amp;quot;),
        new UserProfile(33, &amp;quot;Anshu&amp;quot;, &amp;quot;Marketing&amp;quot;),
        new UserProfile(22, &amp;quot;Padma Raviee&amp;quot;, &amp;quot;Training&amp;quot;),
        new UserProfile(14, &amp;quot;Rajesh&amp;quot;, &amp;quot;Technology&amp;quot;),
        new UserProfile(31, &amp;quot;Yashwanth C&amp;quot;, &amp;quot;Management&amp;quot;),
        new UserProfile(34, &amp;quot;Ramesh&amp;quot;, &amp;quot;Finance&amp;quot;)
      ]);
    ]]&amp;gt;
  &amp;lt;/mx:Script&amp;gt;
&amp;lt;/mx:Application&amp;gt;
&lt;/pre&gt;

&lt;p&gt;
With this, the UI that we expect is as follows:
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;http://eduzine.edujini-labs.com/uploads/flex/31.Flex.Data-Driven.Renderer.01.Initial.UI.jpg&quot; alt=&quot;Eduzine - Flex List - Renderer - Initial UI&quot; title=&quot;Eduzine - Flex List - Renderer - Initial UI&quot; /&gt;
&lt;/p&gt;

&lt;h2&gt;Flex Item Renderers&lt;/h2&gt;

&lt;p&gt;
This interface is decently fine. Let's get something more out of this. How about change the UI to not only display the employees' names but also their Employee ID and the Department Name. And showing them a little formatted - say, in two lines rather than in a single line.
&lt;/p&gt;

&lt;p&gt;
Adobe Flex data driven controls work internally with the so called item renderers to represent a &amp;quot;list of items&amp;quot;. The external presentation may be linear, grid, tree or a combination of these.
&lt;/p&gt;

&lt;p&gt;
To get started, let us define a simple renderer for our &lt;code&gt;List&lt;/code&gt;. Modify the &lt;code&gt;List&lt;/code&gt; definition to as follows:
&lt;/p&gt;

&lt;pre&gt;  &amp;lt;mx:List id='eList' x=&amp;quot;20&amp;quot; y=&amp;quot;90&amp;quot; dataProvider=&amp;quot;{employees}&amp;quot; labelField=&amp;quot;employeeName&amp;quot;
    cornerRadius=&amp;quot;4&amp;quot; width=&amp;quot;344&amp;quot; height=&amp;quot;265&amp;quot;&amp;gt;
    &lt;b&gt;&amp;lt;mx:itemRenderer&amp;gt;
      &amp;lt;mx:Component&amp;gt;
        &amp;lt;mx:VBox&amp;gt;
          &amp;lt;mx:Label text=&amp;quot;ID: {data.employeeID}&amp;quot; /&amp;gt;
          &amp;lt;mx:HBox width=&amp;quot;100%&amp;quot;&amp;gt;
            &amp;lt;mx:Label text=&amp;quot;Name: {data.employeeName}&amp;quot; width=&amp;quot;50%&amp;quot; /&amp;gt;
            &amp;lt;mx:Label text=&amp;quot;Department: {data.departmentName}&amp;quot; width=&amp;quot;50%&amp;quot; /&amp;gt;
          &amp;lt;/mx:HBox&amp;gt;
        &amp;lt;/mx:VBox&amp;gt;
      &amp;lt;/mx:Component&amp;gt;
    &amp;lt;/mx:itemRenderer&amp;gt;&lt;/b&gt;
  &amp;lt;/mx:List&amp;gt;
&lt;/pre&gt;

&lt;p&gt;
The &lt;code&gt;itemRenderer&lt;/code&gt; comprises of one &lt;code&gt;VBox&lt;/code&gt; with two entries - a &lt;code&gt;Label&lt;/code&gt; to display the Employee ID, and a &lt;code&gt;HBox&lt;/code&gt; comprising of details for Employee Name and the Department Name.
&lt;/p&gt;

&lt;p&gt;
Note that the &lt;code&gt;itemRenderer&lt;/code&gt; element can contain only a definition of the &lt;code&gt;Component&lt;/code&gt; which in turn can comprise of only one component. For example, it is not possible to have a &lt;code&gt;Component&lt;/code&gt; with two &lt;code&gt;Label&lt;/code&gt; elements directly within itself. These &lt;code&gt;Labels&lt;/code&gt; must be enclosed in a container layout, like &lt;code&gt;VBox&lt;/code&gt; in this case.
&lt;/p&gt;

&lt;p&gt;
Also note that the controls are bount to values of the type &lt;code&gt;{data.*}&lt;/code&gt;. &lt;code&gt;data&lt;/code&gt; is a special variable in this case - it refers to the &lt;code&gt;item&lt;/code&gt; being rendered. For each iteration corresponding to the entry in the &lt;code&gt;dataProvider&lt;/code&gt;, &lt;code&gt;data&lt;/code&gt; takes up the corresponding value. The type of the value referred to by &lt;code&gt;data&lt;/code&gt; is same as that in the &lt;code&gt;dataProvider&lt;/code&gt;, which in our case is &lt;code&gt;com.edujinilabs.eduzine.tutorials.flex.core.UserProfile&lt;/code&gt;.
&lt;/p&gt;

&lt;p&gt;
The UI expected is as below:
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;http://eduzine.edujini-labs.com/uploads/flex/31.Flex.Data-Driven.Renderer.02.Simple.Renderer.jpg&quot; alt=&quot;Eduzine - Flex List - Custom Rendered Definition&quot; title=&quot;Eduzine - Flex List - Custom Rendered Definition&quot; /&gt;
&lt;/p&gt;

&lt;h2&gt;Flex Item Editors&lt;/h2&gt;

&lt;p&gt;
Let's further fancy the UI and give the HR department an ease to be able to edit the details inline. When the HR personnel clicks on any entry, it should get into the edit mode and display the items as below:
&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Employee ID: Must be shown in a &lt;code&gt;Label&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Employee Name: Must be shown in a &lt;code&gt;TextInput&lt;/code&gt;, so that it may be updated.&lt;/li&gt;
&lt;li&gt;Employee ID: Must be shown as a &lt;code&gt;ComboBox&lt;/code&gt;, with a list of options available.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
Now that we already know how to data-bind the controls, we can directly jump on to looking at the updated &lt;code&gt;List&lt;/code&gt; definition in the MXML:
&lt;/p&gt;

&lt;pre&gt;  &amp;lt;mx:List id='eList' x=&amp;quot;20&amp;quot; y=&amp;quot;90&amp;quot; dataProvider=&amp;quot;{employees}&amp;quot; labelField=&amp;quot;employeeName&amp;quot;
    cornerRadius=&amp;quot;4&amp;quot; width=&amp;quot;344&amp;quot; height=&amp;quot;265&amp;quot; editable=&amp;quot;true&amp;quot; itemEditEnd=&amp;quot;event.preventDefault()&amp;quot;&amp;gt;
    &amp;lt;mx:itemRenderer&amp;gt;
      &amp;lt;mx:Component&amp;gt;
        &amp;lt;mx:VBox&amp;gt;
          &amp;lt;mx:Label text=&amp;quot;ID: {data.employeeID}&amp;quot; /&amp;gt;
          &amp;lt;mx:HBox width=&amp;quot;100%&amp;quot;&amp;gt;
            &amp;lt;mx:Label text=&amp;quot;Name: {data.employeeName}&amp;quot; width=&amp;quot;50%&amp;quot; /&amp;gt;
            &amp;lt;mx:Label text=&amp;quot;Department: {data.departmentName}&amp;quot; width=&amp;quot;50%&amp;quot; /&amp;gt;
          &amp;lt;/mx:HBox&amp;gt;
        &amp;lt;/mx:VBox&amp;gt;
      &amp;lt;/mx:Component&amp;gt;
    &amp;lt;/mx:itemRenderer&amp;gt;
    &lt;b&gt;&amp;lt;mx:itemEditor&amp;gt;
      &amp;lt;mx:Component&amp;gt;
        &amp;lt;mx:VBox&amp;gt;
          &amp;lt;mx:Label text=&amp;quot;ID: {data.employeeID}&amp;quot; /&amp;gt;
          &amp;lt;mx:HBox width=&amp;quot;100%&amp;quot;&amp;gt;
            &amp;lt;mx:TextInput text=&amp;quot;{data.employeeName}&amp;quot; width=&amp;quot;50%&amp;quot; /&amp;gt;
            &amp;lt;mx:ComboBox width=&amp;quot;50%&amp;quot; selectedItem=&amp;quot;{data.departmentName}&amp;quot;&amp;gt;
              &amp;lt;mx:dataProvider&amp;gt;
                &amp;lt;mx:String&amp;gt;Product Dev&amp;lt;/mx:String&amp;gt;
                &amp;lt;mx:String&amp;gt;Training&amp;lt;/mx:String&amp;gt;
                &amp;lt;mx:String&amp;gt;Technology&amp;lt;/mx:String&amp;gt;
                &amp;lt;mx:String&amp;gt;Finance&amp;lt;/mx:String&amp;gt;
                &amp;lt;mx:String&amp;gt;Management&amp;lt;/mx:String&amp;gt;
              &amp;lt;/mx:dataProvider&amp;gt;
            &amp;lt;/mx:ComboBox&amp;gt;
          &amp;lt;/mx:HBox&amp;gt;
        &amp;lt;/mx:VBox&amp;gt;
      &amp;lt;/mx:Component&amp;gt;
    &amp;lt;/mx:itemEditor&amp;gt;&lt;/b&gt;
  &amp;lt;/mx:List&amp;gt;
&lt;/pre&gt;

&lt;p&gt;
The updates in the code, now, must be self explanatory. You would also notice alternate form of specifying the &lt;code&gt;dataProvider&lt;/code&gt; for the &lt;code&gt;ComboBox&lt;/code&gt;. If you select any entry in the list, it must get into the edit-mode. The expected UI is as given below:
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;http://eduzine.edujini-labs.com/uploads/flex/31.Flex.Data-Driven.Renderer.03.Item.Editor.jpg&quot; alt=&quot;Eduzine - Flex List - Custom Item Editor Definition&quot; title=&quot;Eduzine - Flex List - Custom Item Editor Definition&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
So, we seem to have got everything... except that the names / department names, if updated, do not effect the original items (the model). We shall explore this in our next article.
&lt;/p&gt;

&lt;h2&gt;Summary&lt;/h2&gt;

&lt;p&gt;
In this article, we learnt to:
&lt;/p&gt;&lt;ol&gt;
 &lt;li&gt;Use Flex Item Renderers in data driven controls to create a rich UI to render the business objects.&lt;/li&gt;
 &lt;li&gt;Use Flex Item Editors to edit the business objects. We have left the task of updating the business objects to the next article.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;

&lt;/p&gt;    </description>
        <dc:publisher>Eduzine©</dc:publisher>
    <dc:creator>eduzine@edujinionline.com (Eduzine)</dc:creator>
    <dc:subject>Web 2.0, RIA, Flex, ActionScript</dc:subject>
    <dc:date>2008-06-10T10:19:00Z</dc:date>
    <wfw:comment>http://eduzine.edujini-labs.com/wfwcomment.php?cid=31</wfw:comment>
    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://eduzine.edujini-labs.com/rss.php?version=1.0&amp;type=comments&amp;cid=31</wfw:commentRss>
</item>
<item rdf:about="http://eduzine.edujini-labs.com/archives/30-guid.html">
    <title>Flex Data Driven Controls - Part 1</title>
    <link>http://eduzine.edujini-labs.com/archives/30-Flex-Data-Driven-Controls-Part-1.html</link>
    <description>

&lt;h2&gt;Introduction&lt;/h2&gt;

&lt;p&gt;
Data driven controls are key to any UI toolkit, and Adobe Flex is no different.
&lt;/p&gt;

&lt;p&gt;
In this article, we explore some data driven controls in Flex and look at their basic functionalities, especially the data binding and custom rendering.
&lt;/p&gt;

&lt;p&gt;
In case you need a professional support on RIA, Web 2.0 and/or Adobe Flex, feel free to mail
&lt;script type=&quot;text/javascript&quot; language=&quot;javascript&quot;&gt;
  (function()
  {
    var _ej = 'y' + 'a' + 's' + 'h' + 'w' + 'a' + 'n' + 't' + 'h' + '@' + 'edujini' + '-' + 'labs' + '.com';
    document.write('&lt;a href=&quot;mailto:' + _ej + '?Subject=Flex / Web 2.0 Support&quot;&gt;' + _ej + '&lt;/a&gt;');
  })();
&lt;/script&gt;
&lt;/p&gt;

&lt;p&gt;
Downloads are available in the &lt;a href=&quot;http://downloads.edujini-labs.com&quot;&gt;Downloads&lt;/a&gt; section.
&lt;/p&gt;

 
&lt;h2&gt;The Scenario&lt;/h2&gt;

&lt;p&gt;
Let's take a fictitious but practical scenario. The HR department at Edujini Labs to be given a dashboard to:
&lt;/p&gt;&lt;ul&gt;
 &lt;li&gt;Display employee names&lt;/li&gt;
 &lt;li&gt;Dispaly employee details&lt;/li&gt;
&lt;/ul&gt;
&lt;p /&gt;

&lt;p&gt;
Other complexities like capabilities to edit the employee details, paginate the listing if the list is long et al can be added later on.
&lt;/p&gt;

&lt;h2&gt;Getting Started...&lt;/h2&gt;

&lt;p&gt;
To get started, let's freeze on the following UI:
&lt;/p&gt;&lt;ul&gt;
 &lt;li&gt;For the employee list, we use a simple &lt;a href=&quot;http://livedocs.adobe.com/flex/3/langref/mx/controls/ComboBox.html&quot;&gt;ComboBox&lt;/a&gt; to get started with. Later we'd explore other options&lt;/li&gt;
 &lt;li&gt;For the details, we use &lt;a href=&quot;http://livedocs.adobe.com/flex/3/langref/mx/controls/DataGrid.html&quot;&gt;DataGrid&lt;/a&gt;.
&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;

&lt;/p&gt;&lt;p&gt;
&lt;img src=&quot;http://eduzine.edujini-labs.com/uploads/flex/30.Flex.Data-Driven.01.UI.Definition.jpg&quot; alt=&quot;flex - datagrid/combobox - Edujini Labs HR Department UI&quot; title=&quot;flex - datagrid/combobox - Edujini Labs HR Department UI&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
The above UI can be generated using the following application definition (You will need Adobe Flex Builder to design it WSISYG or you can download the Adobe Flex SDK and use the MXML compiler to compile it at command line):
&lt;/p&gt;

&lt;pre&gt;&amp;lt;mx:Application xmlns:mx=&amp;quot;http://www.adobe.com/2006/mxml&amp;quot; layout=&amp;quot;absolute&amp;quot;
  height=&amp;quot;280&amp;quot; width=&amp;quot;600&amp;quot; borderThickness=&amp;quot;2&amp;quot; borderStyle=&amp;quot;solid&amp;quot;
  backgroundColor=&amp;quot;#F0F0F0&amp;quot; cornerRadius=&amp;quot;8&amp;quot;&amp;gt;

  &amp;lt;mx:Label text=&amp;quot;Edujini Labs Pvt Ltd&amp;quot; fontSize=&amp;quot;14&amp;quot;
      fontFamily=&amp;quot;Georgia&amp;quot; fontWeight=&amp;quot;bold&amp;quot; fontStyle=&amp;quot;normal&amp;quot;
      color=&amp;quot;#F5A83B&amp;quot; left=&amp;quot;20&amp;quot; top=&amp;quot;20&amp;quot;/&amp;gt;

  &amp;lt;mx:Label x=&amp;quot;21&amp;quot; y=&amp;quot;64&amp;quot; text=&amp;quot;Edujini Team&amp;quot; fontFamily=&amp;quot;Verdana&amp;quot;
      fontSize=&amp;quot;10&amp;quot; fontWeight=&amp;quot;bold&amp;quot;/&amp;gt;

  &amp;lt;mx:ComboBox x=&amp;quot;21&amp;quot; y=&amp;quot;90&amp;quot;&amp;gt;&amp;lt;/mx:ComboBox&amp;gt;

  &amp;lt;mx:DataGrid x=&amp;quot;218&amp;quot; y=&amp;quot;92&amp;quot; width=&amp;quot;368&amp;quot;&amp;gt;
    &amp;lt;mx:columns&amp;gt;
      &amp;lt;mx:DataGridColumn headerText=&amp;quot;Employee ID&amp;quot; dataField=&amp;quot;employeeID&amp;quot;/&amp;gt;
      &amp;lt;mx:DataGridColumn headerText=&amp;quot;Employee Name&amp;quot; dataField=&amp;quot;employeeName&amp;quot;/&amp;gt;
      &amp;lt;mx:DataGridColumn headerText=&amp;quot;Department&amp;quot; dataField=&amp;quot;departmentName&amp;quot;/&amp;gt;
    &amp;lt;/mx:columns&amp;gt;
  &amp;lt;/mx:DataGrid&amp;gt;

  &amp;lt;mx:Label x=&amp;quot;21&amp;quot; y=&amp;quot;248&amp;quot; text=&amp;quot;© 2008, Edujini Labs Pvt Ltd&amp;quot;
      ontFamily=&amp;quot;Verdana&amp;quot; fontSize=&amp;quot;10&amp;quot; fontWeight=&amp;quot;bold&amp;quot;/&amp;gt;

&amp;lt;/mx:Application&amp;gt;
&lt;/pre&gt;

&lt;p&gt;
Note the definition of the &lt;code&gt;DataGrid&lt;/code&gt;. It contains a bunch of &lt;code&gt;DataGridColumn&lt;/code&gt; definitions. Each &lt;code&gt;DataGridColumn&lt;/code&gt; has been specified a &lt;code&gt;headerText&lt;/code&gt; - header of the column, and &lt;code&gt;dataField&lt;/code&gt; - the property of the object whose value is to be displayed.
&lt;/p&gt;

&lt;p&gt;
To model our data, let's create a class &lt;code&gt;UserProfile&lt;/code&gt; in package, say, &lt;code&gt;com.edujinilabs.eduzine.tutorials.flex.core&lt;/code&gt;. It comprises of the Employee ID, Employee Name and the Department Name.
&lt;/p&gt;

&lt;pre&gt;package com.edujinilabs.eduzine.tutorials.flex.core
{
  /**
   &lt;strong&gt; Part of the Eduzine (http://eduzine.edujini-labs.com) Articles.
   &lt;/strong&gt; Downloads available at http://downloads.edujini-labs.com
   &lt;strong&gt;
   &lt;/strong&gt; (C) 2008, Edujini Labs Pvt Ltd
   &lt;strong&gt; http://www.edujini-labs.com
   &lt;/strong&gt;/
  public class UserProfile
  {
    private var _employeeID : int;
    private var _employeeName: String;
    private var _departmentName: String;

    public function UserProfile(eid: int = 0,
                           name: String = null, deptName: String = null)
    {
      this._employeeID = eid;
      this._employeeName = name;
      this._departmentName = deptName;
    }

    public function get employeeID(): int
    {
      return _employeeID;
    }

    public function set employeeID(eid: int) : void
    {
      this._employeeID = eid;
    }

    public function get employeeName(): String
    {
      return _employeeName;
    }

    public function set employeeName(name: String) : void
    {
      this._employeeName = name;
    }

    public function get departmentName(): String
    {
      return _departmentName;
    }

    public function set departmentName(name: String) : void
    {
      this._departmentName = name;
    }
  }
}
&lt;/pre&gt;

&lt;p&gt;
Notice that the property names have been purposely chosen to match the values of &lt;code&gt;dataField&lt;/code&gt; of the &lt;code&gt;DataGridColumn&lt;/code&gt;'s defined earlier.
&lt;/p&gt;

&lt;h2&gt;Data Model&lt;/h2&gt;

&lt;p&gt;
Employee list would be represented using the variable &lt;code&gt;employees&lt;/code&gt; of type &lt;code&gt;mx.collections.ArrayCollection&lt;/code&gt;. Ensure that it is &lt;code&gt;Bindable&lt;/code&gt;. Finally, let's popupate it with some data, as given below. Add the code directly into the MXML Application created.
&lt;/p&gt;

&lt;pre&gt;  &amp;lt;mx:Script&amp;gt;
    &amp;lt;![CDATA[
      import com.edujinilabs.eduzine.tutorials.flex.core.UserProfile;
      import mx.collections.ArrayCollection;

      [Bindable]
      private var employees: ArrayCollection = new ArrayCollection(
      [
        new UserProfile(11, &amp;quot;Shake Sajan&amp;quot;, &amp;quot;Product Dev&amp;quot;),
        new UserProfile(24, &amp;quot;Meera&amp;quot;, &amp;quot;Training&amp;quot;),
        new UserProfile(23, &amp;quot;Neelam&amp;quot;, &amp;quot;Training&amp;quot;),
        new UserProfile(12, &amp;quot;Hari S Nair&amp;quot;, &amp;quot;Product Dev&amp;quot;),
        new UserProfile(13, &amp;quot;Abdul Prodhani&amp;quot;, &amp;quot;Product Dev&amp;quot;),
        new UserProfile(21, &amp;quot;Ashish Vaish&amp;quot;, &amp;quot;Training&amp;quot;),
        new UserProfile(10, &amp;quot;Gaurav Vaish&amp;quot;, &amp;quot;Technology&amp;quot;),
        new UserProfile(32, &amp;quot;Jagadish&amp;quot;, &amp;quot;Marketing&amp;quot;),
        new UserProfile(33, &amp;quot;Anshu&amp;quot;, &amp;quot;Marketing&amp;quot;),
        new UserProfile(22, &amp;quot;Padma Raviee&amp;quot;, &amp;quot;Training&amp;quot;),
        new UserProfile(14, &amp;quot;Rajesh&amp;quot;, &amp;quot;Technology&amp;quot;),
        new UserProfile(31, &amp;quot;Yashwanth C&amp;quot;, &amp;quot;Management&amp;quot;),
        new UserProfile(34, &amp;quot;Ramesh&amp;quot;, &amp;quot;Finance&amp;quot;)
      ]);
    ]]&amp;gt;
  &amp;lt;/mx:Script&amp;gt;
&lt;/pre&gt;

&lt;h2&gt;Data Binding&lt;/h2&gt;

&lt;p&gt;
The next step is to bind the employee list to &lt;code&gt;ComboBox&lt;/code&gt; and the &lt;code&gt;DataGrid&lt;/code&gt;. Update the definition to as following:
&lt;/p&gt;

&lt;pre&gt;&amp;lt;mx:ComboBox x=&amp;quot;21&amp;quot; y=&amp;quot;90&amp;quot; &lt;b&gt;dataProvider=&amp;quot;{employees}&amp;quot;&lt;/b&gt;&amp;gt;&amp;lt;/mx:ComboBox&amp;gt;
&amp;lt;mx:DataGrid x=&amp;quot;230&amp;quot; y=&amp;quot;92&amp;quot; width=&amp;quot;302&amp;quot; &lt;b&gt;dataProvider=&amp;quot;{employees}&amp;quot;&lt;/b&gt;&amp;gt;
&lt;/pre&gt;

&lt;p&gt;
Note the special syntax - the variable &lt;code&gt;employees&lt;/code&gt; has been enclosed in the curly-braces &lt;code&gt;{}&lt;/code&gt;. This the data-binding syntax. It is a two step process:
&lt;/p&gt;&lt;ol&gt;
 &lt;li&gt;Declare a variable with the attribute &lt;code&gt;Bindable&lt;/code&gt;.&lt;/li&gt;
 &lt;li&gt;In MXML, use it within the curly braces.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;

&lt;/p&gt;&lt;p&gt;
After binding, the UI should appear as given below:
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;http://eduzine.edujini-labs.com/uploads/flex/30.Flex.Data-Driven.02.After.Binding.jpg&quot; alt=&quot;Eduzine - Edujini Labs Employees - Data Binding Flex - UI&quot; title=&quot;Eduzine - Edujini Labs Employees - Data Binding Flex - UI&quot; /&gt;
&lt;/p&gt;

&lt;h2&gt;&lt;code&gt;ComboBox&lt;/code&gt; Configuration&lt;/h2&gt;

&lt;p&gt;
Everything looks fine except for that the &lt;code&gt;ComboBox&lt;/code&gt; does not exactly display what we require. It displays the &lt;code&gt;String&lt;/code&gt; representation of the &lt;code&gt;UserProfile&lt;/code&gt; using the &lt;code&gt;toString()&lt;/code&gt; method.
&lt;/p&gt;

&lt;p&gt;
All we need to configure is the &lt;code&gt;labelField&lt;/code&gt; of the &lt;code&gt;ComboBox&lt;/code&gt; to tell it that it must pickup the text to be displayed to the UI from the corresponding property / field of the individual object of the collection. The default value of &lt;code&gt;labelField&lt;/code&gt; is &lt;code&gt;label&lt;/code&gt;.
&lt;/p&gt;

&lt;p&gt;
Update the definition of the &lt;code&gt;ComboBox&lt;/code&gt; used to as follows:
&lt;/p&gt;

&lt;pre&gt;  &amp;lt;mx:ComboBox x=&amp;quot;21&amp;quot; y=&amp;quot;90&amp;quot; dataProvider=&amp;quot;{employees}&amp;quot;
       labelField=&amp;quot;employeeName&amp;quot;&amp;gt;
  &amp;lt;/mx:ComboBox&amp;gt;
&lt;/pre&gt;

&lt;p&gt;
Voila! The UI is exactly as what we want:
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;http://eduzine.edujini-labs.com/uploads/flex/30.Flex.Data-Driven.03.Custom.LabelField.jpg&quot; alt=&quot;Flex ComboBox Data Binding with custom LabelField&quot; title=&quot;Flex ComboBox Data Binding with custom LabelField&quot; /&gt;
&lt;/p&gt;

&lt;h2&gt;Summary&lt;/h2&gt;

&lt;p&gt;
In this article, we learnt to:
&lt;/p&gt;&lt;ol&gt;
 &lt;li&gt;Use data binding in Adobe Flex.&lt;/li&gt;
 &lt;li&gt;Bind data to the Flex controls &lt;code&gt;ComboBox&lt;/code&gt; and &lt;code&gt;DataGrid&lt;/code&gt;.&lt;/li&gt;
 &lt;li&gt;Display custom objects in the Flex control &lt;code&gt;ComboBox&lt;/code&gt;.&lt;/li&gt;
 &lt;li&gt;Display custom objects in the Flex control &lt;code&gt;DataGrid&lt;/code&gt; in multiple columns.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;

&lt;/p&gt;    </description>
        <dc:publisher>Eduzine©</dc:publisher>
    <dc:creator>eduzine@edujinionline.com (Eduzine)</dc:creator>
    <dc:subject>Web 2.0, RIA, Flex, ActionScript</dc:subject>
    <dc:date>2008-06-07T22:39:44Z</dc:date>
    <wfw:comment>http://eduzine.edujini-labs.com/wfwcomment.php?cid=30</wfw:comment>
    <slash:comments>1</slash:comments>
    <wfw:commentRss>http://eduzine.edujini-labs.com/rss.php?version=1.0&amp;type=comments&amp;cid=30</wfw:commentRss>
</item>
<item rdf:about="http://eduzine.edujini-labs.com/archives/28-guid.html">
    <title>Google Web Toolkit says, &quot;Hello, World!&quot; - Part 2</title>
    <link>http://eduzine.edujini-labs.com/archives/28-Google-Web-Toolkit-says,-Hello,-World!-Part-2.html</link>
    <description>

&lt;h2&gt;Introduction&lt;/h2&gt;

&lt;p&gt;
In the second article in the series - Google Web Toolkit says, &amp;quot;Hello, World!&amp;quot; - we learn how to do the same stuff in, probably, a more structured manner: use Eclipse IDE to write the code, compile and launch. So that we don't have to switch across the Java editor, command prompt and the browser.
&lt;/p&gt;

&lt;p&gt;And the code - available at downloads in the &lt;a href=&quot;http://downloads.edujini-labs.com/index.php?act=category&amp;id=26&quot;&gt;GWT&lt;/a&gt; category.
&lt;/p&gt; 
&lt;h2&gt;Getting Started&lt;/h2&gt;

&lt;p&gt;
The software required are:
&lt;/p&gt;&lt;ul&gt;
	&lt;li&gt;Java SDK from &lt;a href=&quot;http://java.sun.com/javase&quot;&gt;Sun Java&lt;/a&gt; Website&lt;/li&gt;
	&lt;li&gt;Eclipse IDE from &lt;a href=&quot;http://www.eclipse.org&quot;&gt;Eclipse&lt;/a&gt; website. If you are confused what to download, get the Eclipse IDE for Java EE developers &lt;a href=&quot;http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/europa/winter/eclipse-jee-europa-winter-win32.zip&quot;&gt;directly from here&lt;/a&gt;.&lt;/li&gt;
	&lt;li&gt;Google Web Toolkit from &lt;a href=&quot;http://code.google.com/webtoolkit/&quot;&gt;Google Code&lt;/a&gt; Website&lt;/li&gt;
	&lt;li&gt;Apache Tomcat from &lt;a href=&quot;http://tomcat.apache.org&quot;&gt;Apache&lt;/a&gt; Website&lt;/li&gt;
	&lt;li&gt;Cypal Studio &lt;a href=&quot;http://www.cypal.in/studio&quot;&gt;here&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;

&lt;/p&gt;&lt;h2&gt;Step 1: Creating Web Application&lt;/h2&gt;

&lt;p&gt;
First step is to create a &amp;quot;Dynamic Web Project&amp;quot; in Eclipse.
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;http://eduzine.edujini-labs.com/uploads/technology/javascript/gwt/28.GWT.HelloWorld-Cypal-01.NewProject.jpg&quot; alt=&quot;create a &quot; title=&quot;create a &quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
Choose Web -&amp;gt; Dynamic Web Project.
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;http://eduzine.edujini-labs.com/uploads/technology/javascript/gwt/28.GWT.HelloWorld-Cypal-02.DWP.jpg&quot; alt=&quot;create a &quot; title=&quot;create a &quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
Select appropriate Web Server Runtime - the &amp;quot;Target Runtime&amp;quot;. [If the only entry that you get is &amp;lt;none&amp;gt;, create a &amp;quot;New...&amp;quot; one. Point it to the Apache Tomcat folder.] From the &amp;quot;Configurations&amp;quot;, select &amp;quot;Cypal Studio GWT Project&amp;quot;.
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;http://eduzine.edujini-labs.com/uploads/technology/javascript/gwt/28.GWT.HelloWorld-Cypal-03.Cypal.Config.jpg&quot; alt=&quot;create a &quot; title=&quot;create a &quot; /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://eduzine.edujini-labs.com/uploads/technology/javascript/gwt/28.GWT.HelloWorld-Cypal-04.Cypal.Facet.jpg&quot; alt=&quot;create a &quot; title=&quot;create a &quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
Finally, provide a meaningful &amp;quot;Context Root&amp;quot;, or leave it as it.
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;http://eduzine.edujini-labs.com/uploads/technology/javascript/gwt/28.GWT.HelloWorld-Cypal-05.Web.Config.jpg&quot; alt=&quot;create a &quot; title=&quot;create a &quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
Open the &amp;quot;Project Explorer&amp;quot; view. You should see similar to as shown below.
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;http://eduzine.edujini-labs.com/uploads/technology/javascript/gwt/28.GWT.HelloWorld-Cypal-06.Project.Explorer.jpg&quot; alt=&quot;create a &quot; title=&quot;create a &quot; /&gt;
&lt;/p&gt;

&lt;h2&gt;Step 2: Adding a Module&lt;/h2&gt;

&lt;p&gt;
Our web application is now ready. What we now need is to add the &amp;quot;HelloWorld&amp;quot; module as what we did through the &lt;code&gt;applicationCreator.cmd&lt;/code&gt; utility earlier. However, this time we will use the GUI.
&lt;/p&gt;

&lt;p&gt;
We need to add a new &amp;quot;GWT Module&amp;quot; to our application. Follow these steps:
&lt;/p&gt;

&lt;p&gt;
&lt;/p&gt;&lt;ul&gt;
&lt;li&gt;
Add a new item:&lt;br /&gt;
&lt;img src=&quot;http://eduzine.edujini-labs.com/uploads/technology/javascript/gwt/28.GWT.HelloWorld-Cypal-07.AddItem.jpg&quot; alt=&quot;Eclipse: Add a New Item&quot; title=&quot;Eclipse: Add a New Item&quot; /&gt;
&lt;/li&gt;
&lt;li&gt;
Add a new Module:&lt;br /&gt;
&lt;img src=&quot;http://eduzine.edujini-labs.com/uploads/technology/javascript/gwt/28.GWT.HelloWorld-Cypal-08.Module.jpg&quot; alt=&quot;Eclipse: Add a New Item&quot; title=&quot;Eclipse: Add a New Item&quot; /&gt;
&lt;/li&gt;
&lt;li&gt;
Give the name of the package as &lt;code&gt;com.edujinilabs.tutorials.gwt.hw&lt;/code&gt; (note that there is no &lt;code&gt;'client'&lt;/code&gt; as we had earlier), and the name of the class as &lt;code&gt;HelloWorld&lt;/code&gt;.
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;

&lt;/p&gt;&lt;p&gt;
The module has been added. The following artifacts would have been generated:
&lt;/p&gt;&lt;ul&gt;
	&lt;li&gt;Module definition file: &lt;code&gt;com/edujinilabs/tutorials/gwt/hw/HelloWorld.gwt.xml&lt;/code&gt;&lt;/li&gt;
	&lt;li&gt;HTML file: &lt;code&gt;com/edujinilabs/tutorials/gwt/hw/public/HelloWorld.html&lt;/code&gt;&lt;/li&gt;
	&lt;li&gt;Implementation Code: &lt;code&gt;com/edujinilabs/tutorials/gwt/hw/client/HelloWorld.java&lt;/code&gt;&lt;/li&gt;
	&lt;li&gt;Empty package &lt;code&gt;com.edujinilabs.tutorials.gwt.hw.server&lt;/code&gt;
&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;

&lt;/p&gt;&lt;h2&gt;Step 3: Hello World Implementation&lt;/h2&gt;

&lt;p&gt;
We, now, have the skeleton to push in our code. What we shall do is have a simple &lt;code&gt;Button&lt;/code&gt; on the click of which we shall show a simple &lt;code&gt;alert&lt;/code&gt;. Update the class &lt;code&gt;HelloWorld&lt;/code&gt; to the following code:
&lt;/p&gt;

&lt;pre&gt;package com.edujinilabs.tutorials.gwt.hw.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;

public class HelloWorld implements EntryPoint
{
    public void onModuleLoad()
    {
        Button helloBtn = new Button();
        helloBtn.setText(&amp;quot;Say Hello&amp;quot;);

        helloBtn.addClickListener(new ClickListener() {
            public void onClick(Widget sender)
            {
                Window.alert(&amp;quot;Hello, World!&amp;quot;);
            }
        });

        RootPanel.get().add(helloBtn);
    }
}
&lt;/pre&gt;

&lt;h2&gt;Step 4: Launching the Application&lt;/h2&gt;

&lt;p&gt;
We need to configure two things to launch and run the application. First, create a new &amp;quot;Run&amp;quot; configuration. Go to Run -&amp;gt; Run..., and follow these steps:
&lt;/p&gt;

&lt;p&gt;
&lt;/p&gt;&lt;ul&gt;
&lt;li&gt;
Add a new configuration:&lt;br /&gt;
&lt;img src=&quot;http://eduzine.edujini-labs.com/uploads/technology/javascript/gwt/28.GWT.HelloWorld-Cypal-12.Run.Configurations.jpg&quot; alt=&quot;Eclipse: Add a New Run Configuration for GWT&quot; title=&quot;Eclipse: Add a New Run Configuration for GWT&quot; /&gt;
&lt;/li&gt;
&lt;li&gt;
Provide a meaningful name to the configuration. Choose the project (if not already chosen) and the module.&lt;br /&gt;
&lt;img src=&quot;http://eduzine.edujini-labs.com/uploads/technology/javascript/gwt/28.GWT.HelloWorld-Cypal-13.New.Configuration.jpg&quot; alt=&quot;Eclipse: Add a New Run Configuration for GWT&quot; title=&quot;Eclipse: Add a New Run Configuration for GWT&quot; /&gt;
&lt;/li&gt;
&lt;li&gt;
Select the &amp;quot;Parameters&amp;quot; tab and configure the memory to be provided on the heap:&lt;br /&gt;
&lt;img src=&quot;http://eduzine.edujini-labs.com/uploads/technology/javascript/gwt/28.GWT.HelloWorld-Cypal-14.RAM.Configuration.jpg&quot; alt=&quot;Eclipse: Add a New Run Configuration for GWT&quot; title=&quot;Eclipse: Add a New Run Configuration for GWT&quot; /&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;

&lt;/p&gt;&lt;p&gt;
Click, optionally &lt;code&gt;Apply&lt;/code&gt; and then, &lt;code&gt;Run&lt;/code&gt;.
&lt;/p&gt;

&lt;p&gt;
Voila! We again the got the Google Web Toolkit Development Shell! Great, isn't it - noting that we did not touch anything outside Eclipse IDE this time.
&lt;/p&gt;

&lt;p&gt;
What next? Click on the button and &amp;quot;Say Hello&amp;quot;. &lt;img src=&quot;http://eduzine.edujini-labs.com/templates/default/img/emoticons/smile.png&quot; alt=&quot;:-)&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;http://eduzine.edujini-labs.com/uploads/technology/javascript/gwt/28.GWT.HelloWorld-Cypal-15.Output.jpg&quot; alt=&quot;Google Web Toolkit says, &quot; title=&quot;Google Web Toolkit says, &quot; /&gt;
&lt;/p&gt;


&lt;h2&gt;Summary&lt;/h2&gt;

&lt;p&gt;
We can use the Cypal Studio plug-in for Eclipse to ease our life working with GWT. Well, of course, the power lies with GWT.
&lt;/p&gt;

&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    </description>
        <dc:publisher>Eduzine©</dc:publisher>
    <dc:creator>eduzine@edujinionline.com (Eduzine)</dc:creator>
    <dc:subject>JavaScript, Ajax, GWT, Web 2.0, &quot;Hello, World!&quot;</dc:subject>
    <dc:date>2008-05-27T15:31:49Z</dc:date>
    <wfw:comment>http://eduzine.edujini-labs.com/wfwcomment.php?cid=28</wfw:comment>
    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://eduzine.edujini-labs.com/rss.php?version=1.0&amp;type=comments&amp;cid=28</wfw:commentRss>
</item>
<item rdf:about="http://eduzine.edujini-labs.com/archives/27-guid.html">
    <title>Google Web Toolkit says, &quot;Hello, World!&quot; - Part 1</title>
    <link>http://eduzine.edujini-labs.com/archives/27-Google-Web-Toolkit-says,-Hello,-World!-Part-1.html</link>
    <description>

&lt;h2&gt;Introduction&lt;/h2&gt;

&lt;p&gt;
Google Web Toolkit (from Google, at &lt;a href=&quot;http://code.google.com/webtoolkit/&quot;&gt;Google Code&lt;/a&gt;) is a fantastic framework with a very interesting concept - write in Java run in JavaScript! This article demonstrates how to get started with Google Web Toolkit.
&lt;/p&gt;

&lt;p&gt;
The first part of the article demonstrates how to use the default tools provided in GWT to write the &amp;quot;Hello World&amp;quot; application. The second in the series will demonstrate how to use &lt;a href=&quot;http://www.cypal.in/studio&quot;&gt;Cypal Studio Plug-in&lt;/a&gt; for &lt;a href=&quot;http://www.eclipse.org&quot;&gt;Eclipse&lt;/a&gt; to make your life easy when it comes to creating, compiling and running GWT applications.
&lt;/p&gt;

&lt;p&gt;As usual, the code is available in the &lt;a href=&quot;http://downloads.edujini-labs.com&quot;&gt;Downloads&lt;/a&gt; section. Direct link to the Google Web Toolkit category is &lt;a href=&quot;http://downloads.edujini-labs.com/index.php?act=category&amp;id=26&quot;&gt;here&lt;/a&gt;.

&lt;/p&gt; 
&lt;h2&gt;What you need to know&lt;/h2&gt;

&lt;p&gt;
You will need to know Java, at the least because, as I mentioned earlier, majority of the code is written in Java. And please, no generics.
&lt;/p&gt;

&lt;h2&gt;Step 1: Getting Started&lt;/h2&gt;

&lt;p&gt;
Well, the first step is to download Java SDK, if you already don't have one. And then, you will need GWT.
&lt;/p&gt;

&lt;p&gt;
Here's the list, bulleted:
&lt;/p&gt;&lt;ul&gt;
	&lt;li&gt;Java SDK from &lt;a href=&quot;http://java.sun.com/javase&quot;&gt;Sun Java&lt;/a&gt; Website&lt;/li&gt;
	&lt;!--
	&lt;li&gt;Eclipse IDE from &lt;a href='http://www.eclipse.org'&gt;Eclipse&lt;/a&gt; website. If you are confused what to download, get the Eclipse IDE for Java EE developers &lt;a href='http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/europa/winter/eclipse-jee-europa-winter-win32.zip'&gt;directly from here&lt;/a&gt;.&lt;/li&gt;
	--&gt;
	&lt;li&gt;Google Web Toolkit from &lt;a href=&quot;http://code.google.com/webtoolkit/&quot;&gt;Google Code&lt;/a&gt; Website&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;

&lt;/p&gt;&lt;p&gt;I don't think there should be any trouble to download and install.&lt;/p&gt;

&lt;br /&gt;

&lt;h2&gt;Step 2: Looking at GWT&lt;/h2&gt;

&lt;p&gt;
Browse to the folder where you extracted Google Web Toolkit. The folder structure should be similar to shown below.
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;http://eduzine.edujini-labs.com/uploads/technology/javascript/gwt/01.GWT.HelloWorld-01-Folder-Structure.jpg&quot; title=&quot;Folder Structure of Google Web Toolkit&quot; alt=&quot;Folder Structure of Google Web Toolkit&quot; /&gt;
&lt;/p&gt;

&lt;br /&gt;

&lt;h2&gt;Step 3: Creating GWT Application&lt;/h2&gt;

&lt;p&gt;
The very first step that you will do with GWT, after all installation, is to create a GWT Application.
&lt;/p&gt;

&lt;p&gt;
If you look at the files, you will notice a file &lt;code&gt;applicationCreator.cmd&lt;/code&gt;. You guessed it right, that's our starting point.
&lt;/p&gt;

&lt;p&gt;
At the command prompt, go the folder and issue the following command:
&lt;/p&gt;

&lt;pre&gt;applicationCreator.cmd -out gwt-hello-world com.edujinilabs.tutorials.gwt.hw.clent.HelloWorld
&lt;/pre&gt;

&lt;p&gt;
&lt;img src=&quot;http://eduzine.edujini-labs.com/uploads/technology/javascript/gwt/01.GWT.HelloWorld-02-ApplicationCreator.jpg&quot; alt=&quot;Google Web Toolkit; applicationCreator.cmd -out gwt-hello-world com.edujinilabs.tutorials.gwt.hw.client.HelloWorld&quot; title=&quot;Google Web Toolkit; applicationCreator.cmd -out gwt-hello-world com.edujinilabs.tutorials.gwt.hw.client.HelloWorld&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
You will notice a set of files created for you.
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;http://eduzine.edujini-labs.com/uploads/technology/javascript/gwt/01.GWT.HelloWorld-03-CreatedFiles.jpg&quot; alt=&quot;Google Web Toolkit; applicationCreator.cmd -out gwt-hello-world com.edujinilabs.tutorials.gwt.hw.client.HelloWorld; Created Files&quot; title=&quot;Google Web Toolkit; applicationCreator.cmd -out gwt-hello-world com.edujinilabs.tutorials.gwt.hw.client.HelloWorld; Created Files&quot; /&gt;
&lt;/p&gt;

&lt;br /&gt;

&lt;h2&gt;Step 4: Launching Application in 'Hosted' Mode&lt;/h2&gt;

&lt;p&gt;
Descend into the folder &lt;code&gt;gwt-hello-world&lt;/code&gt;. You will notice two files - &lt;code&gt;HelloWorld-compile.cmd&lt;/code&gt; and &lt;code&gt;HelloWorld-shell.cmd&lt;/code&gt;
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;http://eduzine.edujini-labs.com/uploads/technology/javascript/gwt/01.GWT.HelloWorld-04-FolderHW.jpg&quot; title=&quot;Google Web Toolkit; Hello World&quot; alt=&quot;Google Web Toolkit; Hello World&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
Launch &lt;code&gt;HelloWorld-shell.cmd&lt;/code&gt;. You will notice two windows opened - one titled &amp;quot;Google Web Toolkit Development Shell / Port 8888&amp;quot; and the other titled &amp;quot;Wrapper HTML for HelloWorld&amp;quot;.
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;http://eduzine.edujini-labs.com/uploads/technology/javascript/gwt/01.GWT.HelloWorld-05-WindowOne.jpg&quot; alt=&quot;Google Web Toolkit Development Shell / Port 8888&quot; title=&quot;Google Web Toolkit Development Shell / Port 8888&quot; /&gt;
&lt;br /&gt;
&lt;img src=&quot;http://eduzine.edujini-labs.com/uploads/technology/javascript/gwt/01.GWT.HelloWorld-06-WindowTwo.jpg&quot; alt=&quot;Wrapper HTML for HelloWorld&quot; title=&quot;Wrapper HTML for HelloWorld&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
In the second window, click the button that reads &amp;quot;Click me&amp;quot;. Voila! It says, &amp;quot;Hello World!&amp;quot;.
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;http://eduzine.edujini-labs.com/uploads/technology/javascript/gwt/01.GWT.HelloWorld-07-SayHello.jpg&quot; alt=&quot;Google Web Toolkit says, &quot; title=&quot;Google Web Toolkit says, &quot; /&gt;
&lt;/p&gt;

&lt;h2&gt;Where's the code?&lt;/h2&gt;

&lt;p&gt;
If you go into the folder &lt;code&gt;gwt-hello-world/src/com/edujinilabs/tutorials/gwt/hw/client&lt;/code&gt;, you will notice &lt;code&gt;HelloWorld.java&lt;/code&gt;. Yes, that's where the original code is.
&lt;/p&gt;

&lt;h2&gt;Where's the JavaScript?&lt;/h2&gt;

&lt;p&gt;
Ok! I agree. Browsers do not, yet, natively run Java code. So, where's the JavaScript? It's hidden right now. Let's generate.
On the command prompt, issue the following command (in the same folder as where you issued &lt;code&gt;HelloWorld-shell.cmd&lt;/code&gt;:
&lt;/p&gt;

&lt;pre&gt;HelloWorld-compile.cmd
&lt;/pre&gt;

&lt;p&gt;
&lt;img src=&quot;http://eduzine.edujini-labs.com/uploads/technology/javascript/gwt/01.GWT.HelloWorld-08-Compile.jpg&quot; alt=&quot;Google Web Toolkit; HelloWorld-compile.cmd&quot; title=&quot;Google Web Toolkit; HelloWorld-compile.cmd&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
Descend into the folder &lt;code&gt;www/com.edujinilabs.tutorials.gwt.hw.HelloWorld&lt;/code&gt;. You will notice two files - &lt;code&gt;HelloWorld.html&lt;/code&gt; and &lt;code&gt;com.edujinilabs.tutorials.gwt.hw.HelloWorld.nocache.js&lt;/code&gt;. Now, that's where the code is.
&lt;/p&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;
Well, without getting into even a single line of code, we have been able to say, &amp;quot;Hello World!&amp;quot; using Google Web Toolkit. We have been able to get a peek into where the original Java code resides, and where do we get the compiled / generated JavaScript and HTML content.
&lt;/p&gt;

&lt;p&gt;
We shall explore Google Web Toolkit in greater depth in next articles. Keep watching the category &lt;a href=&quot;http://eduzine.edujini-labs.com/categories/20-GWT&quot;&gt;Google Web Toolkit / GWT&lt;/a&gt;
&lt;/p&gt;

&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;

    </description>
        <dc:publisher>Eduzine©</dc:publisher>
    <dc:creator>eduzine@edujinionline.com (Eduzine)</dc:creator>
    <dc:subject>JavaScript, Ajax, GWT, Web 2.0, &quot;Hello, World!&quot;</dc:subject>
    <dc:date>2008-05-26T15:34:00Z</dc:date>
    <wfw:comment>http://eduzine.edujini-labs.com/wfwcomment.php?cid=27</wfw:comment>
    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://eduzine.edujini-labs.com/rss.php?version=1.0&amp;type=comments&amp;cid=27</wfw:commentRss>
</item>
<item rdf:about="http://eduzine.edujini-labs.com/archives/26-guid.html">
    <title>Introduction to Windows Management Instrumentation</title>
    <link>http://eduzine.edujini-labs.com/archives/26-Introduction-to-Windows-Management-Instrumentation.html</link>
    <description>


&lt;h2&gt;Introduction&lt;/h2&gt;

&lt;p&gt;
Web Based Enterprise Mangaement (WBEM) is an industry initiative that establishes management infrastructure standards
and provides a way to combine information from various hardware and software management systems. It specifies standards
for a unified architecture allowing access to data from multiple underlying technologies and platforms and presenting
it in a consistent fashion.
&lt;/p&gt;

 
&lt;p&gt;
Microsoft Windows Management Instrumentation (WMI) is WBEM-compliant. It provides a consistent and descriptive model
of the configuration, status and operational aspects of Microsoft Windows.
&lt;/p&gt;

&lt;p&gt;
In essence, WMI provides:
&lt;/p&gt;&lt;ul&gt;
	&lt;li&gt;Consitent model of Windows configuration, operation and status&lt;/li&gt;
	&lt;li&gt;A COM API providing a single point access to all management functions&lt;/li&gt;
	&lt;li&gt;Flexible architecture allowing vendors to extend the information model to cover new devices,
		applications, and other enhancements by writing WMI providers&lt;/li&gt;
	&lt;li&gt;WMI Query Language, WQL, that enables detailed queries of the information model&lt;/li&gt;
	&lt;li&gt;Scripting support, through Visual Basic, VBA, VBScript and JScript&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;

&lt;/p&gt;&lt;p&gt;
In this article, we take the route of VBScript to discover some possibilities in WMI.
&lt;/p&gt;

&lt;h2&gt;What do we do?&lt;/h2&gt;

&lt;p&gt;
Let's create a simple VBScript to query WMI regarding the disks.
&lt;/p&gt;


&lt;h2&gt;Code and Analysis&lt;/h2&gt;

&lt;p&gt;
The first method that would ever used is to get the reference to the COM Object - winmgmts (CLSID: 172BDDF8-CEEA-11D1-8B05-00600806D9B6).
This is the &amp;quot;Wbem Scripting Object Path&amp;quot; / &amp;quot;Wbem Object Path 1.0&amp;quot; Component. The complete code is:
&lt;/p&gt;

&lt;pre&gt;GetObject(&amp;quot;winmgmts:\\{machine-name}\root\cimv2&amp;quot;)&lt;/pre&gt;

&lt;p&gt;
In the code above, {machine-name} refers to the machine where the query is to be performed subsequently. Should you wish to perform the
query on local machine, you can specify the name as &amp;quot;.&amp;quot; (dot).
&lt;/p&gt;

&lt;p&gt;
Now, I mentioned about WQL earlier. It's very similar to SQL, if you know that. To get started, it's identical. Let's query our machine
to some basic information.
&lt;/p&gt;

&lt;pre&gt; 1 Option Explicit&lt;br /&gt; 2 Dim objWMIService, objItem, colItems, strComputer&lt;br /&gt; 3&lt;br /&gt; 4 strComputer = &amp;quot;.&amp;quot;&lt;br /&gt; 5&lt;br /&gt; 6 Set objWMIService = GetObject(&amp;quot;winmgmts:\\&amp;quot; &amp;amp; strComputer &amp;amp; &amp;quot;\root\cimv2&amp;quot;)&lt;br /&gt; 7 Set colItems = objWMIService.ExecQuery(&amp;quot;Select &lt;strong&gt; from Win32_ComputerSystem&amp;quot;)&lt;br /&gt; 8&lt;br /&gt; 9 For Each objItem in colItems&lt;br /&gt;10    Wscript.Echo &lt;u&gt;&lt;br /&gt;11        &amp;quot;Name: &amp;quot; &amp;amp; objItem.Name &amp;amp; vbCr &amp;amp; &lt;/u&gt;&lt;br /&gt;12        &amp;quot;System Type: &amp;quot; &amp;amp; objItem.SystemType &amp;amp; vbCr &amp;amp; &lt;u&gt;&lt;br /&gt;13        &amp;quot;Manufacturer: &amp;quot; &amp;amp; objItem.Manufacturer &amp;amp; vbCr &amp;amp; &lt;/u&gt;&lt;br /&gt;14        &amp;quot;Model: &amp;quot; &amp;amp; objItem.Model &amp;amp; vbCr &amp;amp; &lt;u&gt;&lt;br /&gt;15        &amp;quot;# Processors: &amp;quot; &amp;amp; objItem.NumberOfProcessors &amp;amp; vbCr &amp;amp; &lt;/u&gt;&lt;br /&gt;16        &amp;quot;RAM: &amp;quot; &amp;amp; CInt(objItem.TotalPhysicalMemory / (1024 &lt;/strong&gt; 1024)) &amp;amp; &amp;quot; MB&amp;quot; &amp;amp; vbCr &amp;amp; &lt;u&gt;&lt;br /&gt;17        &amp;quot;Username: &amp;quot; &amp;amp; objItem.UserName &amp;amp; vbCr &amp;amp; &lt;/u&gt;&lt;br /&gt;18        &amp;quot;Timezone: &amp;quot; &amp;amp; objItem.CurrentTimeZone &amp;amp; &amp;quot; mins from GMT&amp;quot; &amp;amp; vbCr&lt;br /&gt;19 Next&lt;br /&gt;20&lt;br /&gt;21 WSCript.Quit&lt;/pre&gt;

&lt;p&gt;
At line 6, we get a reference to the COM Object for the root CIM v2 for the machine. CIMv2 stands for Common Information Model Version 2.
&lt;br /&gt;
At line 7, we query the service for the class Win32_ComputerSystem.
&lt;br /&gt;
Subsequently, we iterate through all the items and extract the information. In this case, the loop iterates only once because
there is only one Computer System. &lt;img src=&quot;http://eduzine.edujini-labs.com/templates/default/img/emoticons/smile.png&quot; alt=&quot;:-)&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;
&lt;br /&gt;
And the result is something as below:
&lt;/p&gt;

&lt;img src=&quot;http://eduzine.edujini-labs.com/uploads/technology/mstech/WMI.001.Win32_ComputerSystem.jpg&quot; title=&quot;WMI Computer System Information&quot; alt=&quot;WMI Computer System Information&quot; /&gt;

&lt;p&gt;
Now, how about querying the information about the disk drive?
&lt;/p&gt;

&lt;pre&gt; 1 Option Explicit&lt;br /&gt; 2 Dim objWMIService, objItem, colItems, strComputer, intDrive&lt;br /&gt; 3&lt;br /&gt; 4 strComputer = &amp;quot;.&amp;quot;&lt;br /&gt; 5&lt;br /&gt; 6 Set objWMIService = GetObject(&amp;quot;winmgmts:\\&amp;quot; &amp;amp; strComputer &amp;amp; &amp;quot;\root\cimv2&amp;quot;)&lt;br /&gt; 7 Set colItems = objWMIService.ExecQuery(&amp;quot;Select &lt;strong&gt; from Win32_DiskDrive&amp;quot;)&lt;br /&gt; 8&lt;br /&gt; 9 For Each objItem in colItems&lt;br /&gt;10    intDrive = intDrive + 1&lt;br /&gt;11    Wscript.Echo &lt;u&gt;&lt;br /&gt;12        &amp;quot;DiskDrive: &amp;quot; &amp;amp; intDrive &amp;amp; vbCr &amp;amp; &lt;/u&gt;&lt;br /&gt;13        &amp;quot;Caption: &amp;quot; &amp;amp; objItem.Caption &amp;amp; VbCr &amp;amp; &lt;u&gt;&lt;br /&gt;14        &amp;quot;Description: &amp;quot; &amp;amp; objItem.Description &amp;amp; VbCr &amp;amp; &lt;/u&gt;&lt;br /&gt;15        &amp;quot;Manufacturer: &amp;quot; &amp;amp; objItem.Manufacturer &amp;amp; VbCr &amp;amp; &lt;u&gt;&lt;br /&gt;16        &amp;quot;Model: &amp;quot; &amp;amp; objItem.Model &amp;amp; VbCr &amp;amp; &lt;/u&gt;&lt;br /&gt;17        &amp;quot;Name: &amp;quot; &amp;amp; objItem.Name &amp;amp; VbCr &amp;amp; &lt;u&gt;&lt;br /&gt;18        &amp;quot;Partitions: &amp;quot; &amp;amp; objItem.Partitions &amp;amp; VbCr &amp;amp; &lt;/u&gt;&lt;br /&gt;19        &amp;quot;Size: &amp;quot; &amp;amp; CInt(objItem.Size / (1024 &lt;/strong&gt; 1024 * 1024)) &amp;amp; &amp;quot; GB&amp;quot; &amp;amp; VbCr &amp;amp; _&lt;br /&gt;20        &amp;quot;SystemName: &amp;quot; &amp;amp; objItem.SystemName &amp;amp; VbCr&lt;br /&gt;21 Next&lt;br /&gt;22&lt;br /&gt;23 WSCript.Quit&lt;/pre&gt;

&lt;p&gt;
I don't think I need to explain the code above. Everything should be self-explanatory. The result is similar to the following:
&lt;/p&gt;

&lt;img src=&quot;http://eduzine.edujini-labs.com/uploads/technology/mstech/WMI.002.Win32_DiskDrive.jpg&quot; title=&quot;WMI Computer System Information&quot; alt=&quot;WMI Computer System Information&quot; /&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;
WMI provides a great way to manipulate all system information, including software and hardware.
What more - WMI Scripting provides a simple yet powerful mechanism for the same.
&lt;/p&gt;
    </description>
        <dc:publisher>Eduzine©</dc:publisher>
    <dc:creator>eduzine@edujinionline.com (Eduzine)</dc:creator>
    <dc:subject>Win32</dc:subject>
    <dc:date>2008-05-05T23:15:02Z</dc:date>
    <wfw:comment>http://eduzine.edujini-labs.com/wfwcomment.php?cid=26</wfw:comment>
    <slash:comments>1</slash:comments>
    <wfw:commentRss>http://eduzine.edujini-labs.com/rss.php?version=1.0&amp;type=comments&amp;cid=26</wfw:commentRss>
</item>
<item rdf:about="http://eduzine.edujini-labs.com/archives/25-guid.html">
    <title>Web Service Specifications</title>
    <link>http://eduzine.edujini-labs.com/archives/25-Web-Service-Specifications.html</link>
    <description>

&lt;h2&gt;Introduction&lt;/h2&gt;
&lt;p&gt;
This article enlists the various specifications related to web services. The list covers both the first generation specifications as well as second generation specifications.
&lt;/p&gt;

&lt;p&gt;
The article also provides hyperlinks to the specifications and their maintainers.
&lt;/p&gt;


 
&lt;h2&gt;1&lt;sup&gt;st&lt;/sup&gt; Generation Specifications&lt;/h2&gt;

&lt;p&gt;
The web-service framework by W3C consists of a foundation built on three core XML-based specifications: WSDL, SOAP, and UDDI. The standards, in conjunction with SO-Design Principles, form a basic XML-based web-service driven SOA.
&lt;/p&gt;

&lt;p&gt;
The 1&lt;sup&gt;st&lt;/sup&gt; generation architecture allows for the creation of independent web-services. It has several limitations addressed in 2&lt;sup&gt;nd&lt;/sup&gt; generation specifications.
&lt;/p&gt;

&lt;p&gt;
&lt;b&gt;Simple Object Acccess Protocol&lt;/b&gt;: Establishes a standard message format that consists of an XML document capable of hosting RPC and document-centric data.
&lt;/p&gt;&lt;ul&gt;
  &lt;li&gt;SOAP v1.1: Maintained by W3C. Specification is available &lt;a href=&quot;http://www.w3.org/TR/2000/NOTE-SOAP-20000508/&quot;&gt;here&lt;/a&gt;.&lt;/li&gt;

  &lt;li&gt;SOAP v1.2: Maintained by W3C. Specification is divided in four parts - &lt;a href=&quot;http://www.w3.org/TR/soap12-part0/&quot;&gt;Primer&lt;/a&gt;, &lt;a href=&quot;http://www.w3.org/TR/soap12-part1/&quot;&gt;Messaging&lt;/a&gt;, &lt;a href=&quot;http://www.w3.org/TR/soap12-part2/&quot;&gt;Adjuncts&lt;/a&gt; and &lt;a href=&quot;http://www.w3.org/TR/soap12-part3/&quot;&gt;Assertions and Test Collection&lt;/a&gt;
&lt;/li&gt;

&lt;/ul&gt;
&lt;p&gt;

&lt;/p&gt;&lt;p&gt;
&lt;b&gt;Web Service Description Language&lt;/b&gt;: Providing the foremost language for the description of Web service definitions.
&lt;/p&gt;&lt;ul&gt;
  &lt;li&gt;WSDL v1.1: Mantained by W3C. Specification available &lt;a href=&quot;http://www.w3.org/TR/wsdl&quot;&gt;here&lt;/a&gt;
  &lt;/li&gt;&lt;li&gt; WSDL v1.2: Maintained by W3C. Specification available in two parts - &lt;a href=&quot;http://www.w3.org/TR/wsdl20/&quot;&gt;Core Language&lt;/a&gt; and &lt;a href=&quot;http://www.w3.org/TR/wsdl20-patterns/&quot;&gt;Message Patterns&lt;/a&gt;.
&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;


&lt;/p&gt;&lt;h2&gt;2&lt;sup&gt;nd&lt;/sup&gt; Generation Specifications&lt;/h2&gt;

&lt;p&gt;
The 2&lt;sup&gt;nd&lt;/sup&gt; generation specifications position SOA as a viable successor to the prior distributed-platforms.
&lt;/p&gt;

&lt;p&gt;
&lt;b&gt;Reliability and Messaging&lt;/b&gt;: Propose features that deal with reliabile delivery, self-governing messaging, message attachments, and message transmission performance.
&lt;/p&gt;&lt;ul&gt;
  &lt;li&gt;WS-ReliableMessaging: Available at &lt;a href=&quot;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnglobspec/html/wsrmspecindex.asp&quot;&gt;MSDN&lt;/a&gt; and &lt;a href=&quot;http://www-128.ibm.com/developerworks/webservices/library/specification/ws-rm/&quot;&gt;DeveloperWorks&lt;/a&gt;
  &lt;/li&gt;
  &lt;li&gt;WS-Addressing: Available at &lt;a href=&quot;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnglobspec/html/wsmsgspecindex.asp&quot;&gt;MSDN&lt;/a&gt;
  &lt;/li&gt;
  &lt;li&gt;MTOM, DIME: Available at &lt;a href=&quot;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnglobspec/html/wsmsgspecindex.asp&quot;&gt;MSDN&lt;/a&gt;
  &lt;/li&gt;
  &lt;li&gt;MTOM and XOP: Available at &lt;a href=&quot;http://www.w3.org/2000/xp/Group/&quot;&gt;W3C&lt;/a&gt; &lt;/li&gt;
   &lt;li&gt;WS-Attachments: Available at &lt;a href=&quot;http://www-128.ibm.com/developerworks/library/specification/ws-attach/&quot;&gt;DeveloperWorks&lt;/a&gt;
&lt;/li&gt;&lt;/ul&gt;

&lt;p&gt;
&lt;b&gt;Policies and Metadata&lt;/b&gt;: The WS-Policy framework comprises of a set of specifications that allow for the description of policies like business-rules, security etc
&lt;/p&gt;&lt;ul&gt;
 &lt;li&gt;WS-Policy: Available at &lt;a href=&quot;http://schemas.xmlsoap.org/ws/2004/09/policy&quot;&gt;XML-SOAP.org&lt;/a&gt;, and a newer proposed version at &lt;a href=&quot;http://www.w3.org/Submission/WS-Policy/&quot;&gt;W3C&lt;/a&gt;. Also available at &lt;a href=&quot;http://www-128.ibm.com/developerworks/library/specification/ws-polfram/&quot;&gt;DeveloperWorks&lt;/a&gt; &lt;/li&gt;
 &lt;li&gt;WS-PolicyAssertions: Available at &lt;a href=&quot;http://www.ibm.com/developerworks/library/specification/ws-polas/&quot;&gt;DeveloperWorks&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;WS-MetadatExchange: Aavailable at &lt;a href=&quot;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnglobspec/html/wsmetaspecindex.asp&quot;&gt;MSDN&lt;/a&gt;
  &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;

&lt;/p&gt;&lt;p&gt;
&lt;b&gt;Security&lt;/b&gt;: The WS-Security framework provides a thorough security model consisting of a host of specifications
&lt;/p&gt;&lt;ul&gt;
 &lt;li&gt;WS-Security: Maintained by &lt;a href=&quot;http://www.oasis-open.org/committees/wss&quot;&gt;OASIS&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;WS-SecureConversation, WS-Federation, WS-Trust: All maintained by &lt;a href=&quot;http://www.oasis-open.org/specs/&quot;&gt;OASIS&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;XML Encryption, XML Signature, XKMS, XACML, SAML: Maintained by &lt;a href=&quot;http://www.w3.org/Consortium/siteindex.html#X&quot;&gt;W3C&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;WS-I Basic Security Profile: Maintained by &lt;a href=&quot;http://www.ws-i.org/deliverables/workinggroup.aspx?wg=basicsecurity&quot;&gt;WS-I&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;
&lt;b&gt;Context and Transaction Management&lt;/b&gt;: The WS-Coordination specification provides a context management system. Supports atomic and long-running transactions.
&lt;/p&gt;&lt;ul&gt;
 &lt;li&gt;WS-Coordination: Maintained by &lt;a href=&quot;http://docs.oasis-open.org/ws-tx/wscoor/2006/06/&quot;&gt;OASIS&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;WS-Transaction: Maintained by &lt;a href=&quot;http://www.oasis-open.org/committees/ws-tx/&quot;&gt;OASIS&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;WS-AtomicTransaction: Maintained by &lt;a href=&quot;http://docs.oasis-open.org/ws-tx/wsat/2006/06&quot;&gt;OASIS&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;WS-BusinessActivity: Maintained by &lt;a href=&quot;http://docs.oasis-open.org/ws-tx/wsba/2006/06&quot;&gt;OASIS&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;

&lt;/p&gt;&lt;p&gt;
&lt;b&gt;Business Process Definitions&lt;/b&gt;: Provides support for workflow - orchestration and choreography.
&lt;/p&gt;&lt;ul&gt;
 &lt;li&gt;BPEL: Maintained by &lt;a href=&quot;http://docs.oasis-open.org/wsbpel/2.0/wsbpel-v2.0.pdf&quot;&gt;OASIS&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;WSCI: Maintained by &lt;a href=&quot;http://www.w3.org/TR/wsci/&quot;&gt;W3C&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;BPML: Maintained by &lt;a href=&quot;http://www.bpmi.org/&quot;&gt;BPMI&lt;/a&gt; (Note that there are not many takers for BPML. BPEL has a wider acceptance.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt; &lt;/p&gt;
    </description>
        <dc:publisher>Eduzine©</dc:publisher>
    <dc:creator>eduzine@edujinionline.com (Eduzine)</dc:creator>
    <dc:subject>Web Services</dc:subject>
    <dc:date>2007-06-30T00:08:27Z</dc:date>
    <wfw:comment>http://eduzine.edujini-labs.com/wfwcomment.php?cid=25</wfw:comment>
    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://eduzine.edujini-labs.com/rss.php?version=1.0&amp;type=comments&amp;cid=25</wfw:commentRss>
</item>
<item rdf:about="http://eduzine.edujini-labs.com/archives/24-guid.html">
    <title>HOWTO: Configure Microsoft SQL Server for Mixed Mode Authentication</title>
    <link>http://eduzine.edujini-labs.com/archives/24-HOWTO-Configure-Microsoft-SQL-Server-for-Mixed-Mode-Authentication.html</link>
    <description>

&lt;h2&gt;Introduction&lt;/h2&gt;

&lt;p&gt;
At times, Windows Authentication in Microsoft SQL Server is not enough. One of the requirements is in ASP.Net as
described in the FAQ &lt;a href=&quot;http://faqs.edujini-labs.com/5_2_en.html&quot;&gt;here&lt;/a&gt;.
This article descibes how to setup mixed mode authentication, also known as SQL Authentication, in Microsoft SQL Server 2000, 2005 and 2005 Express Edition.
&lt;/p&gt;

&lt;p&gt;
Now of course, the need does not arise if the care is taken during installation of SQL Server 2000 and 2005. But for
SQL Server 2005, it becomes mandatory. We explore all versions anyway.
&lt;/p&gt;

 
&lt;h2&gt;Mixed Mode Authentication for SQL Server 2000&lt;/h2&gt;

&lt;p&gt;
Launch Enterprise Manager for SQL Server 2000. Browse to the server node that you are interested in as shown below.
&lt;/p&gt;

&lt;img border=&quot;0&quot; src=&quot;http://eduzine.edujini-labs.com/uploads/technology/mstech/1_mma_2000_01.jpg&quot; /&gt;

&lt;p&gt;
Right click and select the option &lt;code&gt;Properties&lt;/code&gt; or from the &lt;code&gt;Action&lt;/code&gt; menu, select &lt;code&gt;Properties&lt;/code&gt;.
&lt;/p&gt;
&lt;div align=&quot;right&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://eduzine.edujini-labs.com/uploads/technology/mstech/1_mma_2000_02.jpg&quot; /&gt;

&lt;/div&gt;&lt;p&gt;
Go to the &lt;code&gt;Security&lt;/code&gt; tab and select &lt;code&gt;SQL Server and Windows&lt;/code&gt; option for &lt;code&gt;Authentication&lt;/code&gt;.
&lt;/p&gt;
&lt;img border=&quot;0&quot; src=&quot;http://eduzine.edujini-labs.com/uploads/technology/mstech/1_mma_2000_03.jpg&quot; /&gt;

&lt;p&gt;
You may need to restart the server.
&lt;/p&gt;

&lt;h2&gt;Mixed Mode Authentication for SQL Server 2005 Express Edition&lt;/h2&gt;

&lt;p&gt;
For SQL Server 2005 Express Edition, there is not GUI tool available to configure the server. You need to go it manually.
The first step is to change the login-mode.
&lt;/p&gt;

&lt;p&gt;
Open registry editor (launch application &lt;code&gt;%WINDIR%\regedit.exe&lt;/code&gt;) and go to
&lt;code&gt;HKLM\Software\Microsoft\Microsoft SQL Server\MSSQL.1\MSSQLServer&lt;/code&gt; in the tree on the left.
&lt;/p&gt;

&lt;p&gt;
On the right, look for an entry named &lt;code&gt;LoginMode. The default value, when installed is &lt;code&gt;1&lt;/code&gt;.
Update it to &lt;code&gt;2&lt;/code&gt;. The next step is to restart the service.
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;
Launch your Service Manager (&lt;code&gt;Start -&amp;gt; Run -&amp;gt; Type services.msc&lt;/code&gt;)
and look for a service named &lt;code&gt;MSSQL Server (SQLEXPRESS)&lt;/code&gt;. Restart the service.
&lt;/p&gt;

&lt;p&gt;
Hey! We are not done  yet... at least practically. We need to add a user with administrative priviledges
so that the database can be accessed from ASP.Net.
&lt;br /&gt;
On the command prompt, login to SQL Server command prompt using the &lt;code&gt;osql&lt;/code&gt; utility. SQL Server 2005
Express Edition is installed with the instance name &lt;code&gt;SQLEXPRESS&lt;/code&gt;. Use the following command to login:
&lt;/p&gt;
&lt;pre&gt;osql -E -S .\SQLEXPRESS&lt;/pre&gt;

&lt;p&gt;
One the SQL-command prompt, execute the following?
&lt;/p&gt;

&lt;pre&gt;1&amp;gt; exec sp_addlogin 'username', 'password'&lt;br /&gt;2&amp;gt; go&lt;br /&gt;1&amp;gt; exec sp_addsrvrolemember 'username', 'sysadmin'&lt;br /&gt;2&amp;gt; go&lt;br /&gt;1&amp;gt; quit&lt;/pre&gt;

&lt;p&gt;
Replace the &lt;code&gt;username&lt;/code&gt; and &lt;code&gt;password&lt;/code&gt; but not forget the quotes.
To verify, try login using the following on the command prompt:
&lt;/p&gt;

&lt;pre&gt;osql -S .\SQLExpress -U username&lt;/pre&gt;

&lt;p&gt;
Provide the password when asked for and you should be through!
&lt;/p&gt;

&lt;h2&gt;Mixed Mode Authentication for SQL Server 2000&lt;/h2&gt;

&lt;p&gt;
Launch SQL Server Management Studio. Connect using Windows Authentication. Ensure that you are logged in
as with administrative privileges. On the machine node in &lt;code&gt;Object Explorer&lt;/code&gt;,
right click and select option &lt;code&gt;Properties&lt;/code&gt;.
&lt;/p&gt;

&lt;img border=&quot;0&quot; src=&quot;http://eduzine.edujini-labs.com/uploads/technology/mstech/1_mma_2005_01.jpg&quot; /&gt;

&lt;p&gt;
Go to the &lt;code&gt;Security&lt;/code&gt; page and select &lt;code&gt;SQL Server and Windows Authentication Mode&lt;/code&gt;
for the &lt;code&gt;Server Authentication&lt;/code&gt;.
&lt;/p&gt;

&lt;img border=&quot;0&quot; src=&quot;http://eduzine.edujini-labs.com/uploads/technology/mstech/1_mma_2005_01.jpg&quot; /&gt;

&lt;p&gt;
You may need to restart the server.
&lt;/p&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;
For Microsoft SQL Server 2000 and 2005, having initial wrong choice for authentication is, now, not a burden.
Also, for Microsoft SQL Server 2005 Express Edition, it is easy to configure it for the mixed mode
authentication and create new IDs.
&lt;/p&gt;
    </description>
        <dc:publisher>Eduzine©</dc:publisher>
    <dc:creator>eduzine@edujinionline.com (Eduzine)</dc:creator>
    <dc:subject>SQL Server</dc:subject>
    <dc:date>2007-04-01T00:59:42Z</dc:date>
    <wfw:comment>http://eduzine.edujini-labs.com/wfwcomment.php?cid=24</wfw:comment>
    <slash:comments>9</slash:comments>
    <wfw:commentRss>http://eduzine.edujini-labs.com/rss.php?version=1.0&amp;type=comments&amp;cid=24</wfw:commentRss>
</item>
</rdf:RDF>