Tuesday Mar 11, 2008

jMaki on Rails - Reloaded for NetBeans 6.1 beta & Rails 2.0


NetBeans 6.1 Beta was released last week. Amongst the many improvements, one of them is the bundled JRuby 1.1 RC2 and Rails 2.0.2. The jMaki plugin used to work fine with Rails 1.2.3 but need to be updated because of changed file name extensions for the default generated views (".rhtml.erb" instead of ".rhtml"). With this release of NetBeans, jMaki plugin has been updated to work in this configuration as well.

This blog provide detailed steps to install jMaki plugin, create a simple Rails 2.0 application using NetBeans IDE and update the generated scaffold to use a Yahoo Data Table widget for displaying the data. It is an update to screencast #web8, lets get started!

  1. Install the jMaki plugin - In NetBeans IDE, go to "Tools", "Plugins". Select "jMaki Ajax support" and click on "Install" button as shown in the following figure:



    Follow the instructions to install the plugin. The IDE is restarted after a successful install.
  2. Create a new Rails project
    1. Create a new Rails project by selecting "File", "New Project..." and selecting "Ruby" and "Ruby on Rails Application". Take all the defaults as shown below:


      and click on "Next >".
    2. Choose "Specify Database Information Directly" and specify the database configuration information as shown below:


      and click on "Finish". You need to make sure MySQL server is running.
  3. Generate Scaffold and Database structures
    1. Right-click on the newly created project, select "Generate..." and enter the values as shown below:


      and click on "OK". This creates a scaffold and model that would allow us to perform CRUD operations on Title, Author, ISBN and Description for a Book.
    2. Create the datbase by invoking db:create target. This is done by right-selecting the project, select "Run Rake Task", "db" and then "create" as shown below:


    3. Create the database tables by running "db:migrate" using the similar steps described above - "Run Rake Task", "db", "migrate".
  4. Add and Configure jMaki widget
    1. In the project, expand "Views", "books" and double-click on "index.rtml.erb" to edit it. This page is used to display all the books from the database table in an HTML table. It also shows links to perform CRUD operations on each book item. From the jMaki Yahoo palette, drag-and-drop a "Yahoo Data Table" right after "</table>" tag. The generated fragment looks like:



    2. The default generated code fragment shows 4 columns in the table. Lets add a new column to display the CRUD operations link. Add the following fragment:

      { :actions => 'Action', :id => 'actions' }

      right after

      { :label => 'Description', :id => 'description'}

      You also need to add a comma "," after the Descrption column fragment. The updated code looks like:

    3. Add the following Ruby fragment right before "<%= jmaki_widget" generated code:

      <%
      @rows_data = []
      for book in @books
        @rows_data << { :id => book.id,
          :title => book.title,
          :author => book.author,
          :isbn => book.isbn,
          :description => book.description,
          :actions => link_to('Show', book) + ' ' + link_to('Edit', edit_book_path(book)) + ' ' + link_to('Destroy', book, :confirm => 'Are you sure?', :method => :delete)
        }
      end
      %>


      This fragment creates a JSON array, @row_data, in the format expected by Yahoo Data Table widget, after retrieving the values from the database. 
    4. Finally, instead of reading the static values for columns, use the newly created "@row_data" to populate the values. The code with all the changes looks like as shown below:

  5. Run the project
    1. The scaffold is now accessible at http://localhost:3000/books. This page in the browser looks like:


    2. After adding couple of entries, the page looks like:

Previous entries that shows how jMaki can be used with Ruby-on-Rails in NetBeans IDE can seen here.

Technorati: netbeans jmaki jruby ruby rubyonrails mysql

Wednesday Mar 05, 2008

Speaking @ SD West, Santa Clara - Mar 6, 2008

SD West 2008 Speaker I'm talking on "jMaki: Web 2.0 Application Building Made Easy" at SD West 2008 on Mar 6. This talk will cover how jMaki provides a light-weight framework that allows to create "Web 2.0" applications intuitively using NetBeans IDE. These application can be deployed on any Servlet container (such as GlassFish), Rails, PHP or Phobos. The talk will explain the jMaki concepts and shows several real-life demos that can be used for your applications.

Venue: Santa Clara Convention Center
Location: Room H
Time: 1:30 - 3:00pm

Register now!

Read more details here.

Technorati: conf sdwest jmaki netbeans glassfish

Sunday Jan 27, 2008

GlassFish at WebGuild Web 2.0 Conference & Expo 2008 - Jan 29

Sun Microsystems is a sponsor of WebGuild's Web 2.0 Conference & Expo and you can meet me at Sun booth in the exhibitor hall. Register for a FREE exhibitor pass here.

Ask me about:

  • How GlassFish provides an easy-to-use and production-quality development and deployment environment for your "Web 2.0" applications ?
  • How NetBeans IDE provides a rich extensible platform to create such applications ?
  • What is jMaki and how it allows you to use best tools & libraries to create Rich Internet Applications ?
  • How GlassFish is a "green" alternative for deploying JRuby-on-Rails applications ?
  • How RESTful Web services can be easily generated using Jersey from a database table ?
  • Or anything else you want to know :)

I will be at the WebGuild's Web 2.0 Conference & Expo

Technorati: conf jmaki jruby netbeans glassfish rubyonrails jruby jersey

Saturday Jan 26, 2008

"Rails powered by GlassFish & jMaki" @ South Bay Ruby Meetup - Jan 29, 7pm

I'll be speaking on "Rails powered by GlassFish & jMaki" at South Bay Ruby Meetup on Jan 29 (Tuesday) @ 7pm. Read more details here.

You'll learn:

  • How GlassFish provides an easy-to-use and production-quality development and deployment environment for your JRuby-on-Rails applications ?
  • How GlassFish is a "green" alternative for deploying JRuby-on-Rails applications ?
  • What is GlassFish v3 Gem ?
  • How jMaki allows you to create visually appealing views for Rails applications ?
  • How NetBeans provide first-class support for creating Rails applications ?

Thanks to Bala for providing an opportunity to talk about our efforts! Let's keep an interactive dialog and learn from each other :)

Technorati: conf jruby rubyonrails glassfish netbeans meetup

Thursday Jan 24, 2008

jMaki and Asynchronous Ajax @ Ajax World, New York 2008

The jMaki session at the upcoming Ajax World East 2008 is featured on Web2Journal.

Enjoy several jMaki screencasts before the talk :)

Jean-Francois is also speaking on Asynchronous Ajax for Revolutionary Web Applications - He is a great speaker and interesting topic too!

If you want to speak, the Call For Paper for Ajax World closes tomorrow (Jan 25, 2008).

Technorati: conf jmaki ajaxworld web2journal

Wednesday Jan 23, 2008

RESTful representation of "sakila" using GlassFish and NetBeans IDE

"sakila" is the sample database shipped with MySQL (pronounced as my ess-kew-ell). In the context of Sun Microsystems announcing the agreement to acquire MySQL, I'd like to dedicate this entry to show how this sample database can be exposed as a RESTful Web service endpoint and deployed on GlassFish using Jersey Tooling Plugin (0.4.1 with Jersey 0.4) in NetBeans IDE.

Lets get started!

  1. Install MySQL & the sample database "sakila".
    1. Download and Install MySQL Community Server.
    2. Download sakila sample database.
    3. Install the database as described here.
    4. Start MySQL database by giving the command 'mysqld-nt --user root --console' in bin directory on Windows or './bin/mysqld_safe' from MySQL directory on Unix flavors.
  2. Create the Project & Database Connection
    1. In NetBeans IDE, create a new Web project and name it as "sakila". Choose "GlassFish v2" as the "Server:".
    2. In the "Services" tab of NetBeans IDE, expand "Drivers" and add MySQL Connector/J driver if it does not exist already.
    3. Create a new new database connection by right-clicking on "Drivers" and specifying the parameters as shown below:

  3. Create the Persistence Unit
    1. Right-click on the project and select "New", "Entity Classes from Database...". In "Data Source", select "New Data Source..." and specify the values as shown below:

    2. Click on "film" in "Available Tables" and click on "Add >" as shown below:



      Click on "Next >".
    3. Click on "Create Persistence Unit..." and take all the defaults as shown below:



      Click on "Create".
    4. Enter the package name as "sakila" as shown below:



      and click on "Finish".
    5. In the NetBeans project explorer, expand "Configuration Files" and open "persistence.xml". Specify the username and password by replacing <properties/> with the following fragment:

      <properties>
        <property name="toplink.jdbc.user" value="root"/>
        <property name="toplink.jdbc.password" value=""/>
      </properties>


      Make sure to match the username and password to your MySQL installation.
  4. Create RESTful Web service endpoint
    1. In NetBeans IDE, click on "Tools", "Plugins", "Available Plugins", "RESTful Web Services" and then click on "Install". This installs the Jersey Tooling Plugin in the IDE.
    2. Right-click on the project, select "New", "RESTful Web Services from Entity Classes...".
    3. Click on "Add >>", take all other defaults as shown below:



      click on "Next >", take all defaults and then "Finish".
  5. Test RESTful Web Services
    1. Right-click on the project and select "Test RESTful Web Services". The following web page is presented in the browser:

    2. Click on "films" and then on "Test" as shown below:



      Clicking on "Test" button or the URL "http://localhost:8080/sakila/resources/films/" shows the RESTful representation of the "Film" table. The default representation shows 10 records from the table where each entry returns the "id" of the film and a reference to the detailed entry.

      You can view more entries (say 40) by giving the URL "http://localhost:8080/sakila/resources/films/?max=40". Additional fields from the table can be displayed by adding getter methods to "converter.FilmRefConverter" class such as:

      @XmlElement
      public String getTitle() {
        return entity.getTitle();
      }


      to return the film title in addition to the fields already returned. The different columns in the table can be viewed by going to the "Services" tab, expanding the sakila database connection created earlier as shown below:



      The modified output (with film title included) looks as shown below:

Here are few more ideas for you to explore:

  • Create RESTful representations of other tables using the steps described above.
  • Display the data from different tables in a jMaki-wrapped Yahoo or Dojo data table as explained in TOTD #10.
  • Display the data retrieved from the database in a JSP page as described in Hello JPA World.
  • Create a CRUD application using jMaki Data Table as described in TOTD #15 or Screencast #Web10.

A JRuby-on-Rails application using MySQL is explained here. TOTD #9 explains how JDBC connection pooling in GlassFish can be used for a JRuby-on-Rails application using MySQL.

The key message here is MySQL can be very easily used with GlassFish and NetBeans IDE makes it possible! Once MySQL becomes part of Sun, this integration is going to be much more seamless for the betterment of community.

All the entries on this blog using MySQL can be found here. And last but not the least, Welcome aboard MySQL!

A NetBeans project with all the source code can be downloaded from here. You will still need to setup the database connection and need to make sure the correct version of Jersey plug-in as well :)

Technorati: glassfish netbeans jersey mysql sakila jpa jmaki rubyonrails

Thursday Jan 17, 2008

Travel Plans for Q1 2008 - Fairfax, Little Rock, Orlando, Hyderabad, New York, Las Vegas

Here are my tentative travel plans for the next 3 months:
Event Dates Location
Partner Preso Jan 23 Fairfax, Virginia
Partner Preso Jan 24 Little Rock, Arkansas
Rails for All Feb 8-9 Orlando, Florida
Sun Tech Days Feb 27-29 Hyderabad, India
Ajax World Mar 18-20 New York
The Server Side Java Symposium Mar 26-28 Las Vegas

Stop by and say hello if you are at any of the locations! Also, drop a comment or shoot me an email if you'd like me to talk to your local Java User Group about GlassFish provides an open-source, production-quality and Java EE 5 compatible Application Server. We can also drill down on Metro or jMaki with numerous working samples. If you host or attend a Ruby Meetup then we can also talk about JRuby on GlassFish.

Let me know if you'll be interested in running a few miles together :)

Technorati: glassfish metro jruby ruby jmaki meetup jug webservices web2.0

Wednesday Jan 09, 2008

jMaki @ Ajax World, New York 2008

Ajax World 2008 - New York City

Sun Microsystems is a Gold sponsor of Ajax World 2008, New York City. I'll be speaking on Web Application Development using jMaki.

jMaki
is a light-weight framework to create Rich Internet Applications using the best tools/libraries and standard practices. I plan to deliver the talk with lots of demos and hope you'll be able to correlate them with real-life scenarios easily. Of course, GlassFish provides a robust development environment for deploying these applications.

I liked the fact that they put my name/photo on the front page as shown below (kinda cool):

Ajax World 2008 Front Page

This is the first time it happened to me :)

If you have not registered yet, Register Today (before Jan 18) and save $200.

Find out more about the Products, Solutions, Free Developer Tools, Try and Buy and Other Cool Stuff for your next generation Web application (aka "Web 2.0") at developers.sun.com/web.

Technorati: conf jmaki glassfish ajaxworld

Monday Dec 31, 2007

Screencast #Web11: Travel Map - Another Real-life app using jMaki & Jersey

In my role of Technology Evangelist, I get the opportunity to meet a lot of community (folks like you :) all around the world. In the year 2007, I represented GlassFish (and related technologies - Metro, jMaki and Jersey) at multiple conferences. This blog introduces a  new real-life application that plots all the places I visited this year on a jMaki-wrapped Google Map widget. Clicking on the marker shows more information about the event such as dates and the blog entry covering the event.

Play the video below to see how the application looks like.

Here is the architecture of this application:

travel map architecture

It consists of a server-side and a client-side applications - developed as NetBeans projects.

  1. Server-side project - A RESTful Web service endpoint that provides resource represenations for all the events attended and associated meta information such as date and blog URLs. This endpoint is created using Jersey.
  2. Client-side project - A jMaki-enabled Web application that consumes the representations generated by the RESTful Web service and plots the information on a jMaki-wrapped Google Map widget.

Both the server-side and client-side are deployed on GlassFish.

This is only a sample application so optimizations are certainly possible and corner cases (such as no blog entry for a particular visit) are not accounted for. But the application still demonstrates the concept. The fully built application looks like as shown below:

Arun's Travel Map 2007

My first presentation in this role was Sun Tech Days Atlanta (highlighted in the image). This application generates an interactive Google Map so feel free to zoom in/out and click 

And one last thing before we build the application. Here is the list of technologies and associated concepts used to build this application:

  1. Jersey
    1. Shows an example of how RESTful Web services can be easily generated from JPA Entity Classes.
    2. Shows how all the resource representations (instead of reference to individual resources) can be returned by a Jersey endpoint.
  2. jMaki
    1. Shows how to consume XML data from an external service (RESTful Web service endpoint) in this case.
    2. Shows how the underlying data model of a widget (Google Map in this case) can be accessed and manipulated.
  3. GlassFish
    1. All the applications are deployed on GlassFish - implicit in the development/deplyment process through seamless integration with NetBeans.
  4. NetBeans 6
    1. Used for generation of RESTful Web services from JPA Entity Classes.
    2. Used for generating/deploying jMaki projects and drag-and-drop of jMaki-wrapped widgets.
  5. JavaScript Closures - to persist the state for asynchronous callback functions
  6. JavaScript DOM processing - to process the XML data received from Jersey endpoint.
  7. Google Maps API
    1. Generate meaningful markers on each location
    2. Populate Google Map from a RESTful Web service endpoint
  8. Java Persistence API - to retrieve data from the database.

And finally, lets build this application. Lets build the RESTful Web service endpoint project first.

  1. Create and Populate the Database
    1. In the NetBeans IDE, go to Services tab, and connect to the database with URL "jdbc:derby://localhost:1527/sample [app on APP]" (right-click and select "Connect...").
    2. Right-click on this database and select "Execute Command..." and create a table by giving the following command:

      create table EVENTS (id int GENERATED ALWAYS AS IDENTITY,
                          event_name varchar(255),
                          dates varchar(20),
                          venue varchar(255),
                          blogs varchar(2056),
                          PRIMARY KEY (id))


      Notice, the "id" column is marked as IDENTITY that instructs the database to auto generate the values for this column and increment by 1 (default) for each row. This column is also marked as the primary key.
    3. Again right-click on the database and select "Execute Command..." to add data to the table by giving the following command:

      INSERT INTO EVENTS (event_name, dates, venue, blogs) VALUES('SunTech Days - Atlanta', 'Jan 16 - Jan 17', 'Cobb Galleria Center, Two Galleria Parkway, Atlanta, Georgia, 30339', 'http://blogs.sun.com/arungupta/entry/wsit_and_web_2_0');
      INSERT INTO EVENTS (event_name, dates, venue, blogs) VALUES('jMaki Day', ' Feb 23', '4150 Network Circle Santa Clara, CA 95054', 'http://blogs.sun.com/arungupta/entry/sun_internal_jmaki_day_review');
      INSERT INTO EVENTS (event_name, dates, venue, blogs) VALUES('Ajax World - New York', 'Mar 19 - Mar 21', 'The Roosevelt Hotel, 45 E 45th St, New York, NY 10017', 'http://blogs.sun.com/arungupta/entry/sun_ajax_world');
      INSERT INTO EVENTS (event_name, dates, venue, blogs) VALUES('The Server Side Java Symposium - Las Vegas', 'Mar 22', '3355 Las Vegas Blvd. South Las Vegas, NV 89109', 'http://blogs.sun.com/arungupta/entry/sun_the_server_side_java, http://blogs.sun.com/arungupta/entry/tango_at_venetian_las_vegas');
      INSERT INTO EVENTS (event_name, dates, venue, blogs) VALUES('JavaOne - San Francisco', 'May 7 - May 11', 'Moscone Center, 747 Howard Street, San Francisco, CA 94103', 'http://blogs.sun.com/arungupta/entry/slides_for_ts_4865, http://blogs.sun.com/arungupta/entry/javaone_2007_day_1_finished, http://blogs.sun.com/arungupta/entry/javaone_2007_day_1, http://blogs.sun.com/arungupta/entry/javascript_everywhere_javaone_2007_demo, http://blogs.sun.com/arungupta/entry/excel_using_wsit_javaone_2007, http://blogs.sun.com/arungupta/entry/ts_4865_takes_two_to, http://blogs.sun.com/arungupta/entry/communityone_glassfish_day_report, http://blogs.sun.com/arungupta/entry/javaone_2007_backstage, http://blogs.sun.com/arungupta/entry/javaone_2007_is_almost_here, http://blogs.sun.com/arungupta/entry/my_javaone_2007_picks');
      INSERT INTO EVENTS (event_name, dates, venue, blogs) VALUES('Rails Conf - Portland', 'May 17 - May 20', '777 NE MLK, Jr. Blvd. Portland, OR 97232', 'http://blogs.sun.com/arungupta/entry/tim_bray_s_keynote_session, http://blogs.sun.com/arungupta/entry/sun_rails_conf_2007_keep, http://blogs.sun.com/arungupta/entry/getting_started_with_jruby_tutorial, http://blogs.sun.com/arungupta/entry/jmaki_netbeans_and_glassfish_in');
      INSERT INTO EVENTS (event_name, dates, venue, blogs) VALUES('Google Developer Day - San Jose', 'May 31', '150 W San Carlos St San Jose, CA 95113', 'http://blogs.sun.com/arungupta/entry/google_developer_day_report');
      INSERT INTO EVENTS (event_name, dates, venue, blogs) VALUES('Mashup Camp - Mountain View', 'Jul 18 - Jul 19', 'Computer History Museum, 1401 N Shoreline Blvd., Mountain View, CA 94043', 'http://blogs.sun.com/arungupta/entry/jmaki_at_mashup_camp_report, http://blogs.sun.com/arungupta/entry/jmaki_mashup_camp');
      INSERT INTO EVENTS (event_name, dates, venue, blogs) VALUES('OSCON - Portland', 'Jul 23 - Jul 27', '777 NE MLK, Jr. Blvd. Portland, OR 97232', 'http://blogs.sun.com/arungupta/entry/jmaki_oscon');
      INSERT INTO EVENTS (event_name, dates, venue, blogs) VALUES('JRuby Hack Day - San Francisco', 'Aug 8', '1201 8th St, San Francisco, CA 94107', 'http://blogs.sun.com/arungupta/entry/jruby_on_rails_hackday_report, http://blogs.sun.com/arungupta/entry/learn_jruby_on_rails_free');
      INSERT INTO EVENTS (event_name, dates, venue, blogs) VALUES('Rich Web Experience - San Jose', 'Sep 6 - Sep 8', '170 S Market St, San Jose, CA 95113', 'http://blogs.sun.com/arungupta/entry/the_rich_web_experience_2007, http://blogs.sun.com/arungupta/entry/jmaki_javafx_the_rich_web');
      INSERT INTO EVENTS (event_name, dates, venue, blogs) VALUES('Rails Conf Europe - Berlin', 'Sep 17 - Sep 19', 'Maritim Pro Arte, Friedrichstrasse 151, 10117 Berlin', 'http://blogs.sun.com/arungupta/entry/rails_conf_europe_2007_day2, http://blogs.sun.com/arungupta/entry/rails_conf_europe_2007_day1, http://blogs.sun.com/arungupta/entry/rails_conf_europe_2007_day, http://blogs.sun.com/arungupta/entry/jmaki_netbeans_and_glassfish_in1');
      INSERT INTO EVENTS (event_name, dates, venue, blogs) VALUES('Sun Tech Days - Rome', 'Sep 24 - Sep 25', 'Meliá Roma Aurelia Antica, Vía Aldobrandeschi, 223  Rome ITALY  00163', 'http://blogs.sun.com/arungupta/entry/netbeans_day_rome_2007, http://blogs.sun.com/arungupta/entry/travel_tips_to_rome, http://blogs.sun.com/arungupta/entry/glassfish_metro_jersey_and_jmaki');
      INSERT INTO EVENTS (event_name, dates, venue, blogs) VALUES('Sun Tech Days - Milan', 'Sep 26 - Sep 28', 'ATA Hotel Quark - Via Lampedusa 11/a 20141 Milano, Italia', 'http://blogs.sun.com/arungupta/entry/glassfish_day_milan_2007');
      INSERT INTO EVENTS (event_name, dates, venue, blogs) VALUES('Mid West Java Tech Days - Minneapolis', 'Oct 16', 'University of St Thomas, MPL 201, 1000 LaSalle Avenue, Minneapolis, MN 55403-2005', 'http://blogs.sun.com/arungupta/entry/mid_west_java_tech_days, http://blogs.sun.com/arungupta/entry/metro_and_jmaki_in_minneapolis');
      INSERT INTO EVENTS (event_name, dates, venue, blogs) VALUES('Mid West Java Tech Days - Chicago', 'Oct 18', 'Donald E Stephens Convention Center, 9301, W Bryn Mawr Ave, Rosemont IL 60018', 'http://blogs.sun.com/arungupta/entry/mid_west_java_tech_days1, http://blogs.sun.com/arungupta/entry/crowne_plaza_chicago_o_hare, http://blogs.sun.com/arungupta/entry/metro_and_jmaki_in_minneapolis');
      INSERT INTO EVENTS (event_name, dates, venue, blogs) VALUES('Silicon Valley Code Camp - Los Altos', 'Oct 27', 'Foothill College, Los Altos, CA', 'http://blogs.sun.com/arungupta/entry/silicon_valley_code_camp_trip, http://blogs.sun.com/arungupta/entry/metro_jmaki_silicon_valley_code');
      INSERT INTO EVENTS (event_name, dates, venue, blogs) VALUES('Sun Tech Days - Beijing', 'Nov 1 - Nov 3', 'Beijing International Convention Center, No.8 Beichendong Road Chaoyang District, Beijing', 'http://blogs.sun.com/arungupta/entry/glassfish_day_beijing_2007_by, http://blogs.sun.com/arungupta/entry/wangfujing_street_authentic_china_in, http://blogs.sun.com/arungupta/entry/sun_tech_days_beijing_talent, http://blogs.sun.com/arungupta/entry/sun_tech_days_beijing_day, http://blogs.sun.com/arungupta/entry/travel_tips_to_beijing, http://blogs.sun.com/arungupta/entry/glassfish_day_beijing');
      INSERT INTO EVENTS (event_name, dates, venue, blogs) VALUES('Partner Preso - Toronto', 'Nov 21', 'Toronto City Center', 'http://blogs.sun.com/arungupta/entry/metro_jmaki_jruby_glassfish_q');
      INSERT INTO EVENTS (event_name, dates, venue, blogs) VALUES('Partner Preso - Montreal', 'Nov 21', 'Montreal City Center', 'http://blogs.sun.com/arungupta/entry/metro_jmaki_jruby_glassfish_q');
      INSERT INTO EVENTS (event_name, dates, venue, blogs) VALUES('GlassFish - Delhi University', 'Dec 3', 'New Delhi', 'http://blogs.sun.com/arungupta/entry/glassfish_delhi_university');
      INSERT INTO EVENTS (event_name, dates, venue, blogs) VALUES('FOSS.IN - Bangalore', 'Dec 4', 'India Institute of Science, Bangalore', 'http://blogs.sun.com/arungupta/entry/packaging_java_apps_for_ubuntu, http://blogs.sun.com/arungupta/entry/foss_in_schedules_now_available, http://blogs.sun.com/arungupta/entry/glassfish_foss_in_2007');
      INSERT INTO EVENTS (event_name, dates, venue, blogs) VALUES('Partner Preso - Bangalore', 'Dec 4', 'Bangalore', 'http://blogs.sun.com/arungupta/entry/glassfish_bangalore_chennai_and_pune');
      INSERT INTO EVENTS (event_name, dates, venue, blogs) VALUES('Partner Preso - Chennai', 'Dec 5', 'Chennai', 'http://blogs.sun.com/arungupta/entry/glassfish_bangalore_chennai_and_pune');
      INSERT INTO EVENTS (event_name, dates, venue, blogs) VALUES('Partner Preso - Pune', 'Dec 6', 'Pune', 'http://blogs.sun.com/arungupta/entry/glassfish_bangalore_chennai_and_pune');
      INSERT INTO EVENTS (event_name, dates, venue, blogs) VALUES('Partner Preso - San Francisco', 'Dec 17', 'San Francisco', 'http://blogs.sun.com/arungupta/');

      These SQL statements populate the database with details about my visits in 2007. If you'd like to develop a similar application highlighting your visits then you'll need to modify the VALUES clause to match accordingly.
  2. Create and Configure RESTful Web service endpoint
    1. Create a Persistence Unit as described in "Generating Entity Classes from Database" section in Getting Started with RESTful Web Services. Lets say the project name is "WebApplication3", package name is "events" and the table name to generate Entity classes is EVENTS. Take everything else as the defaults.
    2. Generate a RESTful Web service as described in "Generating RESTful Web Services from Entity Classes" section in Getting Started with RESTful Web Services.
      1. Add a new class EventsList in the events package as:

        @javax.xml.bind.annotation.XmlRootElement
        public class EventsList {
          @javax.xml.bind.annotation.XmlElement
          protected java.util.List<Events> events;

          public EventsList() {
            if (events == null)
              events = new java.util.ArrayList<Events>();
          }

          public void add(Events name) {
            events.add(name);
          }

          public java.util.List<Events> getValue() {
            return events;
          }
        }
      2. In service.EventsResource, change the method associated with GET to:

        public EventsList get() {
                EventsList eventsList = new EventsList();
                List<Events> list  = PersistenceService.getInstance().createQuery("SELECT e FROM Events e").getResultList();
                for (Events e : list) {
                    eventsList.add(e);
                }
                return eventsList;
        }

        This will ensure that all the resource representations are returned instead of a reference to the resource. Make sure to fix the imports.
That's it, our server-side project is now ready. "http://localhost:8080/WebApplication3/resources/events" now return a complete RESTful representation of all the rows from the database table EVENTS.

Lets build the client-side application next. Make sure jMaki plug-in in NetBeans IDE is already installed.
  1. In the NetBeans IDE, create a new Web project, enable "Ajax Framework" and choose the "Standard" layout for "index.jsp".  Lets say the project name is "WebApplication4".
  2. Drag-and-drop a jMaki-wrapped Google Map widget in the 'Main Content Area' and jMaki-wrapped Yahoo Button in the 'Sidebar Content Here'.
  3. Customise the widgets
    1. Add id="mymap" attribute to the Google Map widget. The updated widget looks like as shown below:

      <a:widget  name="google.map" id="mymap"
               args="{ centerLat : 37.4041960114344,
                       centerLon : -122.008194923401 }" />

      id="mymap"
      will allow the Map widget to be accessed by name later.
    2. Add args="{label:'Plot Events'}" attribute to thes Yahoo button widget. The updated widget looks like as shown below:

      <a:widget name="yahoo.button" args="{label:'Plot Events'}"/>
  4. In glue,js, add the following code to \*onClick subscribe method:

    var url = jmaki.xhp + "?id=events";
    var _map = jmaki.getWidget("mymap").map;
    _map.setZoom(2);
    _map.clearOverlays();
    _map.enableInfoWindow();
       
    jmaki.doAjax({method: "GET",
        url: url,
        callback: function(_req) {          
            var xmlobject = (new DOMParser()).parseFromString(_req.responseText, "text/xml");
            var root = xmlobject.getElementsByTagName('eventsList')[0];
            var events = root.getElementsByTagName('events');
            for (var i = 0 ; i < events.length ; i++) {
                var event = events[i];
                var eventName = event.getElementsByTagName('eventName')[0].firstChild.nodeValue;
                var venue = event.getElementsByTagName('venue')[0].firstChild.nodeValue;
                var blogs = event.getElementsByTagName('blogs')[0].firstChild.nodeValue;
                var dates = event.getElementsByTagName('dates')[0].firstChild.nodeValue;
               
    var id = event.getElementsByTagName('id')[0].firstChild.nodeValue;
                   
                var encodedLocation = encodeURIComponent("location=" + venue);
                var url = jmaki.xhp + "?id=yahoogeocoder&urlparams=" + encodedLocation;
                jmaki.myHandler(url, eventName, blogs, dates, id, _map);
            }
        }
    });
  5. Add the following functions above the \*onClick subscribe method:

    // "Function closure" used from http://econym.googlepages.com/basic1.htm
    // Creates local copy of "marker" and "html" variables to be preserved for later use
    function createMarker(point,html) {
        var marker = new GMarker(point);
        GEvent.addListener(marker, "click", function() {
            marker.openInfoWindowHtml(html);
        });
        return marker;
    };

    // Function closure that preserves "eventName", "blogs", "dates and "id"
    // Gets the latitude/longitude from Yahoo Geocoding service and plots them on the map
    // Also creates meaningful markers
    jmaki.myHandler = function(_url, eventName, blogs, dates, id, _map) {
        jmaki.doAjax({url: _url,
            callback : function(req) {
                if (req.responseText.length > 0) {
                    jmaki.log("name: " + eventName);
                    var response = eval("(" + req.responseText + ")");
                    var coordinates = response.coordinates;
                    jmaki.publish("/jmaki/plotmap", coordinates);
                    jmaki.log("plotting " + eventName);
                    var latlng = new GLatLng(coordinates[0].latitude, coordinates[0].longitude);
                   
                    var blogHtml = "";
                    b = blogs.split(', ');
                    for (i=0; i<b.length; i++) {
                        blogHtml += '<a href="' + b[i] + '">' + (i+1) + '</a>';
                        if (i<b.length-1)
                            blogHtml += ", ";
                    }
                   
                    var txt = '<table>' +
                    '<tr><td>#' + id + ": " + eventName + '</td></tr>' +
                    '<tr>Dates: ' + dates + ', 2007</td></tr>' +
                    '<tr><td>Blogs: ' + blogHtml + '</td></tr>' +
                    '</table>';
                   
                    var marker = createMarker(latlng, txt);
                    _map.addOverlay(marker);
                    marker.openInfoWindowHtml(txt);
                } else {
                    jmaki.log("Failed to get coordinates for " + location );
                }
            }
        });   
    };
  6. Add the following entry in Web Pages, resources, xhp.json:

    ,
    {"id": "events",
     "url":"http://localhost:8080/WebApplication3/resources/events/"
    }


    assuming WebApplication3 is the project where RESTful Web service endpoint is hosted.
That completes our client-side web application as well. Now, either hit F6 (default key to Run the NetBeans project) and this will show http://localhost:8080/WebApplication4/index.jsp in the configured browser. Once you click on "Plot Events" button, all the markers on the Google Map are plotted.
Future Improvements
  1. If Jersey can return all the resource representations directly, then the workaround used above may not be required.
  2. Use e4x after <script type="text/javascript"> in index.jsp can be generated as <script type="text/javascript; e4x=1">.
  3. Build the client-side application using Rails once issue #309 & #310 are resolved.
    1. Once deployed as Rails application on WEBrick, create a WAR file and deploy on GlassFish.
    2. Try this application using GlassFish v3 gem.
  4. Embed Google Map in the blog entry.
An alternate title of this blog entry could've been "How I spent my winter break ?". But in order to keep the title inline with rest of other entries (keeping it simple and reflecting the content of the entry) I decided to use the existing title ;-)

Technorati: screencast conf jmaki jersey netbeans glassfish jpa javascript googlemaps restful web2.0 jmakimashups

Thursday Dec 13, 2007

GlassFish @ Delhi University

I presented on GlassFish and related technologies (Metro, JRuby-on-GlassFish and jMaki) at the Department of Computer Science, Delhi University last week. The slides are available here.

The talk was very well attended with approximately 120 students and 4 faculty members. The students were pretty excited and had great a interactive session.

 

Being an alumni of the school (many years ago ;), it was great seeing the new building of the department, meeting the faculty and interacting with the students. I reached there an hour earlier so that I can mingle with the staff and students and it was a lot of fun.

The department faculty proposed to use GlassFish instead of Tomcat for their next semester assignment. I believe this is a great move as it will allow the students to understand the simplicity and power of a great open-source and Java EE 5 compliant Application server.

I initiated the process of recruiting a Campus Ambassador from Delhi University and this will help establish a better relationship between this University and Sun Microsystems.

Here are the questions and answers that were asked during the session:

  1. Amongst the different Java training courses, how do I decide which one to pick ?

    Sun Learning defines several Learning Paths for different Java technologies (EE, SE, ME, Web Services and Web 2.0). Pick an appropriate learning path depending upon your interest. In addition, Sun Training Catalogue (click on your country) shows different events conducted by Sun Learning in the local geogrpahy.
  2. How does Sun make money with GlassFish being open sourced ?

    That's true, GlassFish is 100% open-source and totally free to use. The business model for Sun is that of selling support and services:
  3. What are the dis-advantages of GlassFish ?

    GlassFish provides an open source, production-quality and Java EE 5 compatible application server. It has world class performance ([1], [2]), .NET interoperable Web services stack, out-of-the-box clustering, load balancing and high availability support. However instead of identifying dis-advantages, here are some areas for improvement:
     
    • Feature-wise: The footprint for GlassFish v2 is higher than some non-full JavaEE containers (like Tomcat). This problem will disappear with GlassFish v3 which is small (< 100 kb), fast (starts up < 1 sec) and modular (load only required containers).
    • Ecosystem-wise
      • Community is not as well developed as Tomcat or JBoss because we have not been around as long. However the adoption is continuously increasing.
      • We are not yet as transparent as Tomcat, but we are more transparent than anybody else (including JBoss). Transparency will continue to improve in the future.
      • Our governance is still in transition.
  4. Any comparison between NetBeans and Eclipse ?

    Why NetBeans ? explains the top reasons to use the NetBeans IDE. Some specific points are:
    • Consistent UI across all platforms where as Eclipse runs best on Windows
    • A friendlier environment for people who are new with links to sample apps and docs accessible from within the IDE.
    • An easy to use website with tons of quality docs and screencasts.

    Here are couple of more links that provide a comparison between the IDEs:

  5. What are the main features of Ruby as compared to Java ?

    A comparison of Ruby and Java is explained in this blog.
  6. Why Ruby when there are many other languages ?
    • Ruby is getting popular due to Rails.
    • Ruby-on-Rails very popular among web developers.
    • JRuby is a pretty mature implementation of Ruby in Java, running on JVM and able to use existing Java libraries.
    • Complete deployment story on Solaris -- customer can chose native RoR or JRuby on Rails on GlassFish.
  7. What is the difference between Tomcat and GlassFish ?

    Tomcat is a Servlet container that can host JSP and Servlets. GlassFish is a Java EE 5 compliant application server that includes implementation for a Web services stack (Metro), EJBs, Java Persistence and many others incuded in the Java EE 5 specification. In addition to this, GlassFish also provides out-of-the-box clustering, high availability and load balancing capabilities that are required for enterprise applications. Read more about Why use GlassFish ?
  8. What does Sun offer to students ?

    The offerings are described in detail here.
  9. What is java.net ?

    java.net is a premier web-based, open community created to facilitate Java™ technology collaboration in applied areas of technology and industry solutions. java.net is a central gathering place for Java technology enthusiasts and existing communities across industries, platforms, and interest groups. Read more about java.net in the FAQ.
  10. How do I create a brand new jMaki widget ?

    This is explained in TOTD #20.
  11. What are the main differences between GPL and CDDL ?

    A detailed difference between EULA, GPL, CDDL and BSD in terms of copyright and patent rights is explained here.
  12. What are the different options of doing a collaborative research in association with Sun Microsystems ?

    The Collaborative Research program is explained here.
  13. What is the difference between GlassFish v2 and Sun Java System Application Server 9.1 ?

    There are three key differences:

    The detailed differences are highlighted here.

  14. What are the different ways GlassFish can be configured in NetBeans ?

    Two ways:
    • If you download a full version of NetBeans IDE then GlassFish comes pre-bundled and is installed for you.
    • You can configure an existing GlassFish installation on your machine in the Services tab. If the Services tab is not visible, then select "Windows" menu item and then "Services". Right-click on "Servers", select "Add Server...", select "GlassFish V2" in the "Choose Server" dialog box. Click on "Next" and follow the instructions.

The complete album is here:

Technorati: conf glassfish webservices metro ruby jruby jmaki web2.0 delhiuniversity delhi netbeans q&a

About

profile image
Arun Gupta is a technology enthusiast, a passionate runner, author, and a community guy who works for Oracle Corp.


Java EE 7 Samples

Stay Connected

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today