Arun Gupta, Miles to go ...

Arun Gupta is a technology enthusiast, a passionate runner, and a community guy who works for Sun Microsystems.
« Previous month (Sep 2008) | Main | Next page of month (Oct 2008) »

http://blogs.sun.com/arungupta/date/20081028 Tuesday October 28, 2008

GlassFish @ Silicon Valley Code Camp 2008


CodeCamp at FootHill College. Click Here for Details and Registration Sun Microsystems is a sponsor of Silicon Valley Code Camp, Nov 8-9, 2008.

More than 800 attendees have already registered and numbers are expected to bump up.

There are three sessions by the GlassFish team:

The code camp follows six principles:
  • by and for the developer community
  • always free
  • community developed material
  • no fluff – only code
  • community ownership
  • never occur during working hours
And then there is wireless, lunch on both days, excellent networking, and Saturday night barbecue - everything free. Check out the complete session schedule and more details here.

If you are local to bayarea, why would you not come ? :)

Register now!

A mashup on the main page shows speakers and attendees geographical distribution. This is created using JSON feeds for Attendees ZIP.  A snapshot is shown below:



A similar feed for sessions for is also available for and includes presentation date/time, associated tags and similar information. Would you like to create a fancy session viewer ? If chosen, it'll be highlighted at the conference.

Technorati: conf siliconvalleycodecamp glassfish

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20081027 Monday October 27, 2008

Silicon Valley Half Marathon 2008 Completed - best time so far


I completed Silicon Valley Half Marathon yesterday. Although I missed my target of 8 min/mile by 4 seconds but still improved my personal best by 3 min and 8 secs. Here are my official results:
 


A summary of half-marathoners:



And the top 5 finishers:



And then the complete results.

Even though the number of 1/2 marathoners were much smaller (957 instead of 6679) than my previous marathon but I still enjoyed the run. Going through familiar streets and neighborhood was the best part :)

Here is a short video at the start:




And another one at the finish line in Los Gatos High School:




No marathon can ever be completed without family support. All the practice takes a significant amount of time away from family. And it's certainly exciting when they accompany you, early in the morning, for the actual race. Many thanks to my family for helping in my marathons all through out these years :) Here are couple of pictures:


The massage at the end of the race by National Holistic Institute was certainly relaxing!

And of course a small photo album:



Here are my timings so far:

Marathon / Half Marathon Total Time Pace
Silicon Valley 1/2 2008 1:45:42 8:04
San Francisco 1/2 2008 1:52:44 8:25
San Francisco Full 2007 4:04:33 9:20
Silicon Valley Full 2006 4:06:57 9:25
San Francisco 1/2 2005 1:48:50 8:18

As you can see, they have improved over past years :) It only becomes interesting going forward because of the higher bar.

Any suggestions on good San Francisco Bay Area marathons ?

Technorati: running marathon svmarathon results

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20081024 Friday October 24, 2008

TOTD #51: Embedding Google Maps in Java Server Faces using GMaps4JSF


GMaps4JSF allows Google Maps to be easily integrated with any JSF application. This blog shows how to use this library with Mojarra - JSF implementation delivered from the GlassFish community.

TOTD #50 explains how to create a simple JSF 2.0 application and deploy on GlassFish v3 prelude using Mojarra 2.0 EDR2. The application allows to create a database of cities/country that you like. It uses integrated Facelets and the newly introduced JavaScript APIs to expose Ajax functionality. This blog shows how to extend that application to display a Google Map and Street View of the entered city using this library.
  1. Configure GMapsJSF library in the NetBeans project (created as described in TOTD #50)
    1. Download gmaps4jsf-core-1.1.jar.
    2. In the existing NetBeans project, right-click on the project, select Properties, Libraries, click on "Add JAR/Folder" and point to the recently download JAR.
    3. Configure Facelets support for this library. This is an important step since Facelets are the default viewing technology in JSF 2.0.
  2. In the NetBeans project, create a new Java class "server.CityCoordinates" that will use Google Geocoding APIs to retrieve latitude and longitude of the entered city. It also create a "details" entry by concatenating city and country name. Use the code listed below:

        private float latitude;
        private float longitude;
        private String details;
        @ManagedProperty(value="#{cities}")
        private Cities cities;

        private final String BASE_GEOCODER_URL = "http://maps.google.com/maps/geo?";
        private final String ENCODING = "UTF-8";
        private final String GOOGLE_MAPS_KEY = "GOOGLE_MAPS_API_KEY";
        private final String OUTPUT_FORMAT = "CSV";

        public String getLatLong() throws IOException {
            details = cities.getCityName() + ", " + cities.getCountryName();

            String GEOCODER_REQUEST =
                    BASE_GEOCODER_URL +
                    "q=" + URLEncoder.encode(details, ENCODING) +
                    "&key=" + GOOGLE_MAPS_KEY +
                    "&output=" + OUTPUT_FORMAT;
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(
                        new URL(GEOCODER_REQUEST).openStream()));
            String line = null;
            int statusCode = -1;
            while ((line = reader.readLine()) != null) {
                // 200,4,37.320052,-121.877636
                // status code,accuracy,latitude,longitude
                statusCode = Integer.parseInt(line.substring(0, 3));
                if (statusCode == 200) {
                    int secondComma = line.indexOf(",", 5);
                    int lastComma = line.lastIndexOf(",");
                    latitude = Float.valueOf(line.substring(secondComma+1, lastComma));
                    longitude = Float.valueOf(line.substring(lastComma+1));
                    System.out.println("Latitude: " + latitude);
                    System.out.println("Longitude: " + longitude);
                }
            }

            return "map";
        }

        // getters and setters

    "getLatLong()" method retrieves geocoding information using HTTP by passing the city and country name, Google Maps API key and CSV output format. The result is then processed to retrieve status code, latitude and longitude. Add the following annotation to this class:

    @ManagedBean(name="coords", scope="request")

    This ensures that "server.CityCoordinates" is injected as a managed bean in the runtime.
  3. Add a new button in "welcome.xhtml" right after "submit" button as:

    <h:commandButton action="#{coords.getLatLong}" value="map"/>
  4. Add a new page "map.xhtml" as:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:m="http://code.google.com/p/gmaps4jsf/">
        <head>
            <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAF9QYjrVEsD9al2QCyg8e-hTwM0brOpm-All5BF6PoaKBxRWWERRHQdtsJnNsqELmKZCKghs54I-0Uw" type="text/javascript"> </script>
        </head>
        <body>
            <m:map
                latitude="#{coords.latitude}"
                longitude="#{coords.longitude}"
                width="500px"
                height="300px"
                zoom="14"
                addStretOverlay="true">
                <m:marker draggable="true">
                    <m:eventListener eventName="dragend" jsFunction="showStreet"/>
                </m:marker>
                <m:htmlInformationWindow htmlText="#{coords.details}"/>
                <m:mapControl name="GLargeMapControl" position="G_ANCHOR_BOTTOM_RIGHT"/>
                <m:mapControl name="GMapTypeControl"/>
            </m:map>
            <br/> <br/>
            <m:streetViewPanorama width="500px" height="200px"
                                  latitude="#{coords.latitude}" longitude="#{coords.longitude}"
                                  jsVariable="pano1" />

            <script type="text/javascript">
                function showStreet(latlng) {
                    pano1.setLocationAndPOV(latlng);
                }

            </script>
            <form jsfc="h:form">
                <input jsfc="h:commandButton" action="back" value="Back"/>
            </form>
        </body>
    </html>

    The code is borrowed and explained in An Introduction to GMaps4JSF. Basically the code displays a Google Map and Street View where the latitude and longitude are bound by "server.CityCoordinates" managed bean. And these attributes are populated using the geocoding information earlier. The Street View corresponds to marker in the Map which is draggable. So if the marker is dropped to a different location in the map then the Street View changes accordingly.
  5. Add new navigation rules to "faces-config.xml" as:

        <navigation-rule>
            <from-view-id>/welcome.xhtml</from-view-id>
            <navigation-case>
                <from-outcome>map</from-outcome>
                <to-view-id>/map.xhtml</to-view-id>
            </navigation-case>
        </navigation-rule>
        <navigation-rule>
            <from-view-id>/map.xhtml</from-view-id>
            <navigation-case>
                <from-outcome>back</from-outcome>
                <to-view-id>/welcome.xhtml</to-view-id>
            </navigation-case>
        </navigation-rule>
That's it, now your application is ready!

Now when a city and country name are entered on "welcome.xhtml" and "map" button is clicked then the corresponding Google Map along with the street view are shown in next page.

If "San Jose" is entered on "http://localhost:8080/Cities/faces/welcome.xhtml" then the following page is shown:



Clicking on "map" button shows the following page:



If the marker is drag/dropped to 280 and 87 junction, then the page looks like:



Some other useful pointers:
Have you tried your JSF 1.2 app on Mojarra 2.0 ? Drop a comment on this blog if you have.

File JSF related bugs here using "2.0.0 EDR2" version and ask your questions on webtier@glassfish.dev.java.net.

Please leave suggestions on other TOTD (Tip Of The Day) that you'd like to see. An archive of all the tips is available here.

Technorati: totd javaserverfaces mojarra glassfish v3 netbeans gmaps4jsf googlemaps

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20081023 Thursday October 23, 2008

TOTD #50: Mojarra 2.0 EDR2 is now available - Try them with GlassFish v3 and NetBeans 6.5


Yaaay, 50th tip!! The previous 49 tips are available here.

Mojarra EDR2 is now available - download binary and/or source bundle!

GlassFish v2 UR2 ships with Mojarra 1.2.0_04 and v3 prelude comes with 1.2.0_10. The Mojarra binaries in both v2 and v3 can be easily replaced by the new ones as described in Release Notes. Additionally, TOTD# 47 explains how to get started with Mojarra 2.0 on GlassFish v2. This blog will guide you through the steps of installing these bits on GlassFish v3 Prelude and show how to use them with NetBeans IDE.

  1. Download latest GlassFish v3 prelude and unzip.
  2. Start Updatetool from "bin" directory. The first run of the tool downloads and installs the tool. Start the tool by typing the command again to see the screen shown below:


  3. Click on "Update", "Accept" the license and the component is then installed in GlassFish directory. Optionally, you can click on "Installed Components" and then verify that bits are installed correctly.
  4. An EDR2 compliant application can now be directly deployed in these GlassFish v3 bits. There is some work required in order to use code completion, auto-fixing of Imports  and similar features in NetBeans 6.5 RC. The steps below describe that.
    1. In "Tools", "Libraries", click on "New Library ...", enter the name "JSF2.0" as shown:

    2. Click on "OK", "Add JAR/Folder..." and pick "glassfishv3-prelude/glassfish/modules/jsf-api.jar", click on "OK".
    3. Right-click on the NetBeans project, select "Properties", "Libraries" and remove "JSTL1.1" and "JSF1.2" libraries.
    4. Click on "Add Library ...", select the newly created "JSF2.0" library, click "Add Library" and then "OK".
  5. In order to run "Cities" application on these GlassFish bits copy MySQL Connector/J jar in "glassfishv3-prelude/glassfish/lib" directory and then deploy the application.

Here are some pointers to get started:

Have you tried your JSF 1.2 app on Mojarra 2.0 ? Drop a comment on this blog if you have.

File JSF related bugs here using "2.0.0 EDR2" version and ask your questions on webtier@glassfish.dev.java.net.

Please leave suggestions on other TOTD (Tip Of The Day) that you'd like to see. An archive of all the tips is available here.

Technorati: totd javaserverfaces mojarra glassfish v3 netbeans

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

Tempo, Interval, Aerobic, Easy, Long runs etc ...


Still confused by the difference between tempo and interval running ?

How easy is an easy run ?

How long a long run should be ?

Here is a great article defining different types of runs/pace, advantages and how to do them properly.

Technorati: running tempo interval

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20081022 Wednesday October 22, 2008

42k195.com - An exhaustive marathon directory



42k195.com provides an exhaustive directory of marathons across continents.

The marathons can be selected by countries, month or by a keyword. The search feature is especially nice because it shows all the details about the race - marathon route, registration page, nearest marathons, community rating, and even hotel booking amongst many other features.

Did you know 167 marathons will be run in Oct 2008 alone ? And you think marathons are run only in New York, London, Boston and Chicago :)

This is a great resource if you are traveling on business and would like to satisfy your running desires!

The map above shows Metro Silicon Valley Marathon coming up over the weekend and I'll be running the 1/2 marathon.



My goal is to finish comfortably in under 2 hours (a conservative target). This is in addition to:
Drop a note if you are running Silicon Valley! Sun Microsystems has a corporate discount and you can save some money during this financial crisis :)

Technorati: running marathon svmarathon directory

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20081021 Tuesday October 21, 2008

NetBeans is turning 10 next week!


NetBeans is turning 10 next week!

Wow, it's been 10 years and the IDE has certainly evolved tremendously over these years. My first usage of NetBeans goes back to version 3.6 (Mar 2004). The What's New list shows Code Folding, Native L&F for Windows and MacOS and Arrange Windows using drag-and-drop amongst many other features. And today, it leverages the mauturity of Java platform and incorporates comprehensive tooling for languages and frameworks other than Java such as PHP, Ruby-on-Rails, Groovy-on-Grails, C/C++, JavaScript, and many others.

Read complete history of how Xelfi evolved into NetBeans IDE as you know today!

Don't forget to enter NetBeans Decathlon to receive a limited edition NetBeans 10th Anniversary Shirt. GlassFish is one of the featured projects and some suggestions to particpate are:
  • Try the latest GlassFish v3 prelude build with v3 plugin
  • Share your experience with NetBeans and GlassFish integration on forum thread
  • Demo NetBeans/GlassFish to a friend and post a blog entry. Several demos are available here.
This blog has published 174 entries (including 25 screencasts) dedicated to NetBeans as shown by the tag cloud:



I wonder if that count towards getting the limited edition shirt ;-)

Anyway, participate in all the action on NetBeans Birthday. Enjoy birthday wishes from the NetBeans team who make it all happen seamlessly.




Happy Birthday NetBeans!

And miles to go ...

Technorati: netbeans birthday glassfish

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

Comet @ Ajax World 2008 West


Jim and I presented on "Using Comet to create a Two-Player Web Game" at Ajax World 2008 West yesterday. The talk explained the basic concepts of Comet, showed how a Tic Tac Toe game can be easily created using code walkthrough and then talked about future directions. The slides are available here and the code can be downloaded here.

A similar sample that can be deployed on Rails and Grails is described here. It uses GlassFish's support for multiple dynamic languages and associated web frameworks.

One of the benefits of delivering first talk in the morning is the ability to attend different sessions during the day. Of the different sessions I particularly enjoyed listening Bill Scott on Crafting Rich Web Interfaces.The talk explained six principles of rich web interaction with set of design patterns and real world examples. The slides are available here. All other sessions were mostly product pitches with very little value for developers.

Here are some pictures from the show:


And a complete album is available at:




Technorati: conf ajaxworld comet glassfish

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20081020 Monday October 20, 2008

Relevance of Open Source during Financial Crisis - GlassFish, MySQL, OpenSolaris, VirtualBox, NetBeans, ...


CIO published an article highlighting 5 cheap (or free) software that can be afforded during financial crisis. Their recommendations are:

  • Open Office ($0) instead of Microsoft Office ($110 for basic version)
  • Mozilla Thunderbird ($0) instead of Microsoft Outlook (lots of security issues)
  • GnuCash ($0) instead of Quicken ($30 for starter edition)
  • Alfresco ($0) instead of Sharepoint ($5K for five licenses)
  • Linux instead of Windows (non-zero cost, always virus-prone ;)
All the recommendations are open source and can be downloaded and used without any hidden clauses. In all cases the open source version is at par and sometimes better than the commercial version. And of course there is always the agility factor. You enounter a bug, somebody in the community fixes it (on priority if you have support subscription), patch available in the nightly and you are back in business.

Here are some more recommendations ...
  • GlassFish instead of Oracle Weblogic or IBM Websphere
  • MySQL instead of Oracle Enterprise or IBM DB2
  • OpenSolaris instead of Windows
  • NetBeans instead of IntelliJ
  • VirtualBox instead of VM Ware or any other virtualization software
  • and many more here
All these options are completely open source with a full enterprise support available from Sun Microsystems.

Now some actual price comparisons using GlassFish and MySQL Unlimited ...



That's $3 million savings over a period of 3 years!!!

And if the number of sockets/cores go up, that's just additional money you are wasting during this financial crisis. With GlassFish Enterprise Unlimited starting at $25,000 - no counting cores, sockets, support incidents, servers or auditing - you can deploy unlimited GlassFish instances for the same price charged for one WebLogic Enterprise Edition. GlassFish for Business explains the value of buying subscription for your deployments.

Here is another comparison for Total Cost of Ownership for MySQL compared with other databases:



Can your apps scale more than Google, Facebook, Yahoo or Wikipedia ? All these sites are powered by MySQL. Do they need to be more reliable than telco vendors such as Vodafone ? Again powered by MySQL.

In an open source world, why have a "30-day" evaluation period ?

In the times of financial crisis, why spend extra money when there are other better options available with HUGE savings ?

Open Source software is indeed a great way to cut costs. And Sun Microsystems offer a wide varitey of open source offerings (GlassFish, MySQL, OpenSolaris, VirutalBox, Linux, NetBeans and many others) that can help you during this financial crisis!

Technorati: opensource glassfish mysql netbeans opensolaris sun

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20081017 Friday October 17, 2008

SOAP and REST - both equally important to Sun


"Sun moving away from SOAP to embrace REST" is the misleading title of an article recently published in SD Times. The article provides a good introduction to JAX-RS and Jersey. But I really wonder what motivated the author of this article to use this title. This blog, hopefully, provides a better context.

Jersey is the Reference Implementation of Java API for RESTful Web Services (JAX-RS, JSR 311) and was released earlier this week. The headline indicates that Sun is leaving SOAP and will support REST. The debate between REST and SOAP is not new and there are religious camps on both sides (even within Sun). And that's completely understandable because each technology has its own merits and demerits. But just because a new JSR aimed to make RESTful Web services easy in the Java platform is released, it does not mean Sun Microsystems is leaving existing technology in trenches.

The addition of Jersey to Sun's software portfolio makes the Web services stack from GlassFish community a more compelling and comprehensive offering. This is in contrast  to "moving away" from SOAP as indicated by the title. As a matter of fact, Jersey will be included as part of Metro soon, the Web Services stack of GlassFish. And then you can use JAX-WS (or Metro) if you like to use SOAP or JAX-RS (or Jersey) if you prefer RESTful Web services. It's all about a offering choice to the community instead of showing a direction.

Here are some data points for JAX-WS:

  • The JAX-WS 2.0 specification was released on May 11, 2006. There have been couple of maintenance releases since then and another one brewing.
  • Parts of Metro, the implementation of JAX-WS, are currently baked into GlassFish, embeddable in JBoss WS Stack, and also part of Oracle Weblogic and IBM Websphere.
  • The implementation stack is mature and used in several key customer deployments. 
  • JAX-WS is already included in Java SE 6 and hence available to a much wider audience.
  • As opposed to "moving away", JAX-WS 2.2 (currently being worked upon) will be included in Java EE 6 platform, as will Jersey be.
So I believe both SOAP and REST are here to stay, at least in the near future. And Sun Microsystems is committed to support them!

You still think Sun is moving away from SOAP ?

It seems a personal preference is interpreted as Sun's disinvestment in SOAP. It's good to have increased readership but not at the cost of misleading headlines :)

Technorati: jax-ws rest webservices metro sdtimes glassfish

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

TOTD #49: Converting a JSF 1.2 application to JSF 2.0 - @ManagedBean


This is a follow up to TOTD #48 which showed how to convert a JSF 1.2 application to use new features of JSF 2.0. In this blog, we'll talk about a new annotation added to the JSF 2.0 specification - @ManagedBean.

@ManagedBean is a new annotation in the JSF 2.0 specification. The javadocs (bundled with the nightly) clearly defines the purpose of this annotation:

The presence of this annotation on a class automatically registers the class with the runtime as a managed bean class. Classes must be scanned for the presence of this annotation at application startup, before any requests have been serviced.

Essentially this is an alternative to <managed-bean> fragment in "faces-config.xml". This annotation injects a class in the runtime as a managed bean and then can be used accordingly.

Using this annotation, the following "faces-config.xml" fragment from our application:

<managed-bean>
        <managed-bean-name>cities</managed-bean-name>
        <managed-bean-class>server.Cities</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
    </managed-bean>
    <managed-bean>
        <managed-bean-name>dbUtil</managed-bean-name>
        <managed-bean-class>server.DatabaseUtil</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
        <managed-property>
            <property-name>cities</property-name>
            <value>#{cities}</value>
        </managed-property>
    </managed-bean>

is simplified to

@Entity
@Table(name = "cities")
@ManagedBean(name="cities", scope="request")
@NamedQueries({@NamedQuery(...)})
public class Cities implements Serializable {

and

@ManagedBean(name="dbUtil", scope="request")
public class DatabaseUtil {

    @ManagedProperty(value="#{cities}")
    private Cities cities;

The specification defines that managed bean declaration in "faces-config.xml" overrides the annotation.

A worthy addition to this annotation is "eager" attribute. Specifying this attribute on the annotation as @ManagedProperty(..., eager="true") allows the class to be instantiated when the application is started. In JSF 1.2 land, developers write their own ServletContextListeners to perform this kind of task. And this can of course be specified in "faces-config.xml" as <managed-bean eager="true">.

Section 11.5.1 of JSF 2.0 EDR2 specification defines several similar annotations that can be used to simplify "faces-config.xml".

Have you tried your JSF 1.2 app on Mojarra 2.0 ? Drop a comment on this blog if you have.

File JSF related bugs here using "2.0.0 EDR1" version and ask your questions on webtier@glassfish.dev.java.net.

Please leave suggestions on other TOTD (Tip Of The Day) that you'd like to see. An archive of all the tips is available here.

Technorati: totd javaserverfaces glassfish mojarra netbeans

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20081016 Thursday October 16, 2008

"Using Comet to Create a Two-Player Web Game" @ Ajax World




Jim and I are speaking at Ajax World next week on Using Comet to Create a Two-Player Web Game.

The session walks through the process of creating a Tic Tac Toe game that can be played over the Internet using Ajax and Comet. In the process, it explains the general Comet concepts using APIs specific to the GlassFish Application Server. It also highlights the multi-lingual capabilities of GlassFish v3 by deploying a similar application using Ruby-on-Rails.

Here is the list of other Sun sessions:

The complete schedule shows a list of all the sesssions.

Technorati: conf ajaxworld comet glassfish

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20081015 Wednesday October 15, 2008

TOTD #48: Converting a JSF 1.2 application to JSF 2.0 - Facelets and Ajax


TOTD #47 showed how to deploy a JSF 1.2 application (using Facelets and Ajax/JSF Extensions) on Mojarra 2.0-enabled GlassFish.  In this blog we'll use new features added in JSF 2.0 to simplify our application:

Let's get started!
  • Re-create the app as defined in TOTD #47. This app is built using JSF 1.2 core components and Facelets. It uses JSF Extensions for adding Ajax capabilities. Lets change this app to use newer features of JSF 2.0.
  • Edit "faces-config.xml" and change the value of faces-config/@version from "1.2" to "2.0".
  • Remove the following fragment from "faces-config.xml":

        <application>
            <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
        </application>

    This fragment is no longer required because Facelets is the default view technology in JSF 2.0. But it's important to remember that JSF 2.0 Facelets is disabled by default if "WEB-INF/faces-config.xml" is versioned at 1.2 or older.
  • Remove the following code fragment from "web.xml":

            <init-param>
              <param-name>javax.faces.LIFECYCLE_ID</param-name>
              <param-value>com.sun.faces.lifecycle.PARTIAL</param-value>
            </init-param>

    This is only required if JSF Extensions APIs are used.
  • Edit "welcome.xhtml" and replace code with:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:h="http://java.sun.com/jsf/html">
        <ui:composition>
            <h:head>
                <h1><h:outputText value="What city do you like ?" /></h1>
            </h:head>
           
            <h:body>
                <h:form prependId="false">
                    <h:panelGrid columns="2">
                        <h:outputText value="CityName:"/>
                        <h:inputText value="#{cities.cityName}"
                                     title="CityName"
                                     id="cityName"
                                     required="true"
                                     onkeyup="javax.faces.Ajax.ajaxRequest(this, event, { execute: 'cityName', render: 'city_choices'});"/>
                        <h:outputText value="CountryName:"/>
                        <h:inputText value="#{cities.countryName}" title="CountryName" id="countryName" required="true"/>
                    </h:panelGrid>
                   
                    <h:commandButton action="#{dbUtil.saveCity}" value="submit"/>
                    <br/><br/>
                    <h:outputText id="city_choices" value="#{dbUtil.cityChoices}"></h:outputText>
                   
                    <br/><br/>
                    <h:message for="cityName" showSummary="true" showDetail="false" style="color: red"/><br/>
                    <h:message for="countryName" showSummary="true" showDetail="false" style="color: red"/>
                </h:form>
            </h:body>
            <h:outputScript name="ajax.js" library="javax.faces" target="header"/>
        </ui:composition>
       
    </html>

    The differences are highlighted in bold and explained below:
    • "template.xhtml" is no longer required because standard tags are used to identify "head" and "body".
    • <h:head> and <h:body> are new tags defined in JSF 2.0. These tags define where the nested resources need to be rendered.
    • <h:outputScript> is a new tag defined in JSF 2.0 and allows an external JavaScript file to be referenced. In this case, it is referencing "ajax.js" script and is rendered in "head". The script file itself is bundled in "jsf-api.jar" in "META-INF/resources/javax.faces" directory. It adds Ajax functionality to the application.
    • "javax.faces.Ajax.ajaxRequest" function is defined in the JavaScript file "ajax.js". This particular function invocation ensures that "city_choices" is rendered when execute portion of the request lifecycle is executed for "cityName" field. The complete documentation is available in "ajax.js". Read more details about what happens in the background here.

    Notice how the Facelet is so simplified.
  • Refactor "result.xhtml" such that the code looks like as shown below:



    The changes are explained in the previous step, basically a clean Facelet using standard <h:head> and <h:body> tags and everything else remains as is.
And that's it, just hit "Undeploy and Deploy" in NetBeans IDE and your application should now get deployed on Mojarra 2.0-enabled GlassFish. To reiterate, the main things highlighted in this blog are:
  • Facelets are integrated in Mojarra 2.0.
  • New tags for resource re-location allow a simpler and cleaner facelet embedded in a JSF application.
  • JavaScript APIs provide a clean way to expose Ajax functionality in JSF app.
And all of these features are defined in the JSF 2.0 specification. So if you are using Mojarra then be assured that you are developing a standards compliant user interface.

Have you tried your JSF 1.2 app on Mojarra 2.0 ? Drop a comment on this blog if you have.
File JSF related bugs here using "2.0.0 EDR1" version and ask your questions on webtier@glassfish.dev.java.net.

Please leave suggestions on other TOTD (Tip Of The Day) that you'd like to see. An archive of all the tips is available here.

Technorati: totd javaserverfaces glassfish mojarra netbeans

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20081014 Tuesday October 14, 2008

TOTD #47: Getting Started with Mojarra 2.0 nightly on GlassFish v2


Java Server Faces 2.0 specification (JSR 314, EDR2) and implementation (soon to be EDR2) are brewing. This blog shows how to get started with Mojarra - Sun's implementation of JSF.

GlassFish v2 comes bundled with Mojarra 1.2_04 which allows you to deploy a JSF 1.2 application. This blog explains how you can update GlassFish v2 to use Mojarra 2.0 nightly. And then it deploys a simple JSF 1.2-based application on this updated GlassFish instance, there by showing that your existing JSF 1.2 apps will continue to work with Mojarra 2.0-enabled GlassFish. This is an important step because it ensures no regression, unless it was a compatibility fix :)

  1. Re-create a simple JSF 1.2 application as described in TOTD #42, TOTD #45 and TOTD #46. This application allows to create a list of cities and store them in a backend database. It uses JSF Extensions to show suggestions, using Ajax, based upon the cities already entered and also uses Facelets as the view technology. Alternatively you can use any pre-existing JSF 1.2 application.
  2. Download Mojarra 2.0 latest nightly.
  3. Follow Release Notes to install the binary, the steps are summarized here for convenience (GlassFish installed in GF_HOME):
    1. Backup "GF_HOME/lib/jsf-impl.jar".
    2. Copy the new "jsf-api" and "jsf-impl" JARs from the unzipped Mojarra distribution to "GF_HOME/lib".
    3. Edit "GF_HOME/domains/<domain-name>/config/domain.xml" and add (or update the existing "classpath-prefix") 'classpath-prefix="${com.sun.aas.installRoot}/lib/jsf-api.jar" in the java-config element.
    4. Restart your server.
  4. Deploy the application on Mojarra 2.0-enabled GlassFish, that's it!
The application is accessible at "http://localhost:8080/Cities/faces/welcome.xhtml". Some of the screen captures are shown below.

If only "S" is entered in the city name, then the following output is shown:



Now with "San" ...



And another one with "De" ...



With JSF 2.0, Ajax capabilities and Facelets are now part of the specification and have already been integrated in Mojarra. A follow up blog entry will show how to use that functionality.

The downloaded Mojarra bundle has some samples (in "samples" folder) to get you started, have a look at them as well!

File JSF related bugs here using "2.0.0 EDR1" version and ask your questions on webtier@glassfish.dev.java.net.

Please leave suggestions on other TOTD (Tip Of The Day) that you'd like to see. A complete archive of all tips is available here.

Technorati: totd javaserverfaces glassfish mojarra netbeans

del.icio.us | furl | simpy | slashdot | technorati | digg |
|

http://blogs.sun.com/arungupta/date/20081013 Monday October 13, 2008

FREE Sun Student Technology Camp - Oct 24, 2008


Sun Student Technology Camp is an effort to educate students about what is going on in the world of technology. If you are a student, from middle school on up through university-level, then this is for you! There are presentations, demos, hands-on activities on the latest and most innovative technology from resident technology geeks.

The topic for upcoming camp is Open Source. Find out how Open Source will expand your opportunity, increase flexibility, and foster innovation for their future. There will also be a sneak peek on cool technology that has been brewing in SunLabs.

Did I mention these events are FREE ? :)

Hurry- seating is limited! Register today!

Here are the key details:

Date Friday, October 24th
Location Menlo Park (room location given upon sign-up)
Time 4:00pm – 6:00pm PST (but please try to arrive at 3:30pm)
Topic Open Source Software (Zembly.com, OpenSolaris, and Wonderland)

Technorati: sun students technologycamp opensource

del.icio.us | furl | simpy | slashdot | technorati | digg |
|
« Previous month (Sep 2008) | Main | Next page of month (Oct 2008) »

Valid HTML! Valid CSS!

This is a personal weblog, I do not speak for my employer.