Arun Gupta's Blog
Arun Gupta is a Technology Evangelist for Web Services and Web 2.0 Apps at Sun. He was the spec lead for APIs in the Java platform, committer in multiple Open Source projects, participated in standard bodies and contributed to Java EE and SE releases.
TOTD #48: Converting a JSF 1.2 application to JSF 2.0 - Facelets and Ajax
Posted by arungupta on October 15, 2008 at 05:40 AM | Permalink
| Comments (7)
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 (T ip O f T he D ay) that
you'd like to see.
An archive of all the tips is available here .
Technorati: totd
javaserverfaces
glassfish
mojarra
netbeans
TOTD #47: Getting Started with Mojarra 2.0 nightly on GlassFish v2
Posted by arungupta on October 14, 2008 at 05:54 AM | Permalink
| Comments (2)
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 :)
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.
Download Mojarra 2.0 latest
nightly .
Follow Release
Notes to install the binary, the steps are summarized here
for convenience (GlassFish installed in GF_HOME):
Backup "GF_HOME/lib/jsf-impl.jar".
Copy the new "jsf-api" and "jsf-impl" JARs from the
unzipped Mojarra distribution to "GF_HOME/lib".
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.
Restart your server.
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 (T ip O f T he D ay) that
you'd like to see.
A complete archive of all tips is available here .
Technorati: totd
javaserverfaces
glassfish
mojarra
netbeans
FREE Sun Student Technology Camp - Oct 24, 2008
Posted by arungupta on October 13, 2008 at 09:48 AM | Permalink
| Comments (0)
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
LOTD #10: Running GlassFish on Joyent Accelerator
Posted by arungupta on October 10, 2008 at 10:53 AM | Permalink
| Comments (0)
Joyent
provides a
cloud computing environment for all your needs.
Beyond their typical reasons (scale on demand, pay for what you use,
PHP/Rails/Python/Java pre-installed and ready to go, billions of page
views and others), now there is another reason to use their cloud.
The instructions
to configure GlassFish on Joyent cloud are really clean and simple.
Check them out here !
Do you know that Rails applications can be deployed (without any
packaging)
on GlassFish v3 ? Check out more details here .
All previous entries in this series are archived at LOTD .
Technorati: lotd
joyent
glassfish
Sun Tech Days 2008, Sao Paolo - Day 1
Posted by arungupta on September 30, 2008 at 06:20 AM | Permalink
| Comments (0)
Sun
Tech Days kick started yesterday in the beautiful city of Sao Paolo,
Brazil . Over 1000 attendees, completely charged, willing to
discuss their issues, amazing amount of energy and all there to learn
about different Sun
technologies - just a superb recipe to succeed and outpace everybody
else in the world!
The GlassFish
session was packed with 400 attendees and there were attendees all over
the floor :) The slides are available here .
The demos showed during the talk are listed as blog URLs in the slides.
Drop a comment if you attended the talk, are currently using GlassFish
for development or production or would like to know more about it.
The winners of Open
Source Community Awards (sponsored by Sun) were announced at
the keynote. And I'm very excited to announce the two GlassFish
Award
Program (GAP) winners were present to receive in person.
Congratulations to all the
winners, very well deserved!
Reginaldo
Russinholi won an award for "Translation of Hudson project to
Brazilian Portuguese". More details can be found in the submission .
And Claudio
Miranda won an award for "Provide CLI/GUI support to
add/modify/remove certificates to JKS". More details can be found at in
the submission
and bug
#4524 .
And then all the winners together:
And here are some pictures from the evening reception:
The evening concluded with a wonderful dinner at Praca Sao Lourenco
(Vila Olimpia) with Bruno, Claudio and Mauricio:
It is a great restaurant with wilderness ambience, and as always, great
hospitality. If you are in the city of Sao Paolo, this is another great
place to go!
And the evolving (2 more days remaining) album at:
Technorati: conf
suntechdays
brazil
glassfish
saopaolo
GlassFish @ ES JUG, Brazil
Posted by arungupta on September 28, 2008 at 07:06 PM | Permalink
| Comments (1)
SUCESU-ES
organized ES JUG
(Espirito Santo, Brazil) meeting yesterday and I presented on GlassFish . The
slides are available here .
There were approx 100 attendees and I was pleasantly surprised to see
almost half the audience had heard of GlassFish.
The complete agenda is published
here and there were other speakers from Sun as well.
I did not get much time to talk to the audience afterwards because
there were back-to-back sessions scheduled. But please feel free to
drop a comment on this blog if you attended the talk and have any
question/comment.
And they gave a great gift basked (loaded with Garoto
chocolates), check out the picture of gift basket:
Thanks a lot!!
Check out some pictures:
The complete album is available here:
Technorati: conf
jug esjug vitoria brazil
espiritosanto
glassfish
LOTD #9: Advantages of JRuby over MRI
Posted by arungupta on September 27, 2008 at 02:18 PM | Permalink
| Comments (0)
Andreas blogged about why he likes
JRuby even though he dislikes Java.
JRuby is "It's just
Ruby" with more than 50,000 tests to ensure MRI compliance. The blog
highlights that there is no need to know Java, at all, to run JRuby.
Here are
some advantages that are described in the blog:
JVM runtime optimization
Efficient memory usage
Native threads to spread work on multiple cores
Great garbage collection to make memory usage more efficient
JIT and AOT compilation
Inegration with Java libraries
Running Rails applications on existing Java application
servers
Documentation and specs
Read more details here .
Do you know Rails applications can be deployed (without any packaging)
on GlassFish v3 ? Check out more details here .
Technorati: lotd
jruby ruby rubyonrails
glassfish
GlassFish @ DF JUG in Taguatinga
Posted by arungupta on September 25, 2008 at 05:11 AM | Permalink
| Comments (1)
Mauricio , Doris , Simon
and I visited DFJUG @ Taguatinga
yesterday (make sure to pronounce it
correctly, otherwise you'll be corrected again & again, as I
was :). 200 attendees, mostly students, stayed all along the 4
hourof
presentations. The projector stopped recognizing any laptop after first
two presos. Fortunately Simon had a backup projector but we lost time
in debugging but at least all of us could speak!
On
the way to JUG venue, Daniel and I talked more about how he is
contributing towards social responsibility in the community. A
particular one that touched me deeply is where JUG attendees are
recommended to bring milk powder for needy children, such a noble
thought! There were 150 boxes already donated for this JUG and more
were expected at the actual venue. It's not difficult to find 100
volunteers (of the total 33,000 members) to coordinate this effort at
each DFJUG venue, truly amazing.
Another excellent step in that
direction is where
talented kids (between age 16-21) who cannot afford education are
trained in Java to succeed in life. You can find more details at
www.politecsolidaria.com.br
about his efforts. Check out the picture of "cloud" at Politec's office
;-)
Back
to the JUG, I presented on "GlassFish: The Best Open Source
Application Server" and the slides are available here .
Drop a comment on the blog if you attended the talk. The demos shown
during the talk can be easily reproduced as explained here
and here .
I also had a good interaction with faculty in Facitec (JUG venue)
and
they are already planning to use GlassFish/NetBeans for their upcoming
curriculum courses. spotlight.dev.java.net/start
provides a comprehensive list of resources (tutorials, course material,
hands-on-lab, videos, etc) if you are interested as well.
Look at the following pictures during Simon's talk on JavaFX:
Either JavaFX or Simon's British accent was having an amorous effect on
the audience, or it was too late on Wednesday night (around 10:30pm) or
may be it's just Brazilian culture ;-) Simon's demo on controlling Wii
Nintendo and JavaFX was very well appreciated (lots of whistles for a
long time). You can see the demo here:
Once again, freebies got the attendees excited. Thanks Koshuke
for the
tip and Aaron (JUG
Program Coordinator ) to provide the goodies. It was
definitely worth carrying
them all the way. A picture is worth a thousand words and here are a
few to prove that:
Check out some other pictures from the JUG meeting:
The evening ended with a late night BBQ dinner at a friend's house,
really great dinner and wonderful hospitality. The topic of discussions
ranged from Cricket, most pointeless/boring sports in Olympics,
Mah-jong, traffic in India :) My second dinner in Brazil and I'm still
sleeping/eating Pacific Time zone :)
Once again, a wonderful arrangement by Mauricio, Daniel &
Fernando. Obrigado!
Here is the complete album so far:
Technorati: conf glassfish
brazil
taguatinga
jug dfjug
GlassFish @ DF JUG in Brasilia
Posted by arungupta on September 24, 2008 at 04:09 AM | Permalink
| Comments (0)
Started San Francisco 2 days back, through Washington Dulles, with a
stop over @ Rio de Janeiro and finally arrived Brasilia yesterday.
The local airlines (TAM) from Rio to Brasilia offered a nice sandwich
where as any meal need to be bought during domestic travel in US (even
if it's across the continent). So that was a nice experience!
Daniel deOliveira , a Java
Champion and DF
JUG (oldest & biggest with 33,000 member
Java User Group) founder and leader picked me up at the airport. He
demonstrated
true welcoming spirit by taking me around the city and showing the key
places. And again he volunteered to take me to the venue of JUG. It was
pretty impressive to know that he teaches Java to deaf and blind as
part of social responsiblity program in his company. At the JUG venue,
I met Fernando
Anselmo - Architect of Solutions of Directory of Solutions @ Politec ,
a Java
Champion , DFJUG Moderator, and an avid NetBeans
user, mostly the
mobile part. And when in Brazil, you need to drink coffee and that's
what he offered! And finally met Mauricio Leal
(SDN Program
Manager for Latin America) who is coordinating my visits. I've
been talking to Mauricio for past few days and it was great to meet him
in person.
There were 130 attendees but strangely not even a single question.
That's not the kind of audience I expected ;) But I don't feel
completely
disappointed because there were no questions during Mauricio's preso
(who speaks local language) and other English-speaking presenters. The
translators did a tremendous job by matching pace of all the
presenters. Doris
presented on Grizzly Comet and Simon
on JavaFX.
A few more JUGs are scheduled so hopefully I'll see
some interaction going. The true spirit was quite evident when
tee-shirts and
other goodies were thrown to the audience, always a hit! I was also
truly impressed by the audience staying from 7-11pm, and that too
without any food or drink ;-)
Check out some pictures:
The evening ended with a late night dinner at Fogo
de Chao . I was quite surprised that the dinner was still open
at 11:15pm in the night, this is quite unlike San Francisco Bay Area
where typically last dinner entry is taken at 9:30pm! The food was good
and the highlight was luscious mango.
Drop a comment if you attended the talk and liked (or did not) it :)
Here is the complete album so far:
Technorati: conf
glassfish
brazil
jug dfjug
LOTD #9: Slides for Deploying and Monitoring Ruby on Rails Tutorial @ Rails Conf Europe 2008
Posted by arungupta on September 23, 2008 at 09:55 PM | Permalink
| Comments (3)
During Rails
Conf Europe 2008
Day 1 I attended an excellent tutorial on Deploying
and Monitoring Ruby on Rails . The session very clearly
explained the several deployment options with Rails. My notes from the
session are here
and the slides are now available .
Here are couple of snapshots from the slide:
The complete set of slides from Rails Conf Europe 2008 are available here .
Technorati: conf
railsconf
glassfish
deployment
rubyonrails
berlin
TOTD #46: Facelets with Java Server Faces 1.2
Posted by arungupta on September 22, 2008 at 06:05 AM | Permalink
| Comments (0)
This blog updates TOTD
#45 to use Facelets
as view technology.
Powerful templating system, re-use and ease-of-development,
designer-friendly are the key benefits of
Facelets. Facelets are already an integral part of Java Server Faces
2.0. But this blog shows how to use them with JSF 1.2.
Download Facelets from here
(or specifically 1.1.14 ). Facelets
Developer Documentation is a comprehensive source of
information.
Add "jsf-facelets.jar" from the expanded directory to
Project/Libraries as shown:
Change the JSF view documents to ".xhtml" by adding the a
new
context parameter in "web.xml" as:
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
The updated "web.xml" looks like:
Specify Facelets as the ViewHandler of
JSF application by adding the following fragment to "faces-config.xml":
<application>
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
</application>
The updated document looks like:
Create three new XHTML pages by right-clicking on the
project, selecting "New", "XHTML" and name them as "template",
"welcome" and "result". This creates "template.xhtml", "welcome.xhtml"
and "result.xhtml" in "Web Pages" folder.
Replace the generated code in "template.xtml" with the
code given here .
Change the <title> text "Facelets: What's your favorite
City ?".
Replace the generated code in "welcome.xhtml" with the
code given here . Refactor
"welcomeJSF.jsp" such that H1 tag and the associated text goes in
<ui:define name="title"> and rest of the content goes in
<ui:define name="body">. Also change the value of
"template" attribute of <ui:composition> by removing "/".
The updated page looks like:
Replace the generated code in "result.xhtml" with the
code given here . Refactor
"result.jsp" such that H1 tag and the associated text goes in
<ui:define name="title"> and rest of the content goes in
<ui:define name="body">. Also add a namespace declaration
for "http://java.sun.com/jsf/core".
Optionally change the
<h:form> associated with the command button to:
<form
jsfc="h:form">
<input jsfc="h:commandButton" action="back" value="Back"/>
</form>
The updated page looks like:
Add couple of more navigation rules to "faces-config.xml":
<navigation-rule>
<from-view-id>/welcome.xhtml</from-view-id>
<navigation-case>
<from-outcome>submit</from-outcome>
<to-view-id>/result.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>/result.xhtml</from-view-id>
<navigation-case>
<from-outcome>back</from-outcome>
<to-view-id>/welcome.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
And that's it, Facelets-based application is now available at
"http://localhost:8080/Cities/faces/welcome.xhtml". The interaction is
exactly similar to as shown in TOTD
#45 and some of the sample images (borrowed from TOTD
#45 ) are:
Now this application is using Facelets as the view technology instead
of the in-built view definition framework.
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
facelets
netbeans
glassfish
LOTD #8: sun.com/students launced: Everything about Sun and Students
Posted by arungupta on September 19, 2008 at 07:08 AM | Permalink
| Comments (0)
sun.com/students
is one-stop for all students interested in Sun Microsystems.
It has content related to all students:
and many other pointers. Visit sun.com/students
today!
Here are few GlassFish
specific pointers for students:
Technorati: lotd
students
sun glassfish
spotlight
LOTD #7: Happy User of FREE GlassFish Hosting @ OStatic/LayerTech
Posted by arungupta on September 19, 2008 at 07:06 AM | Permalink
| Comments (0)
Alex De Marco is a happy
user of FREE 12-months GlassFish Hosting @ OStatic. Here is
what he has to say:
Many thanks to OStatic
and LayeredTech for offering free hosting, and to Sun for providing a
powerful yet free application development stack: Glassfish, Java,
MySQL, and OpenSolaris. VERY MUCH appreciated!
You can avail this exclusive and limited-time offer here !
Technorati: glassfish
startup
hosting
ostatic
layeredtech
TOTD #45: Ajaxifying Java Server Faces using JSF Extensions
Posted by arungupta on September 17, 2008 at 05:47 AM | Permalink
| Comments (6)
TOTD
#42 explained how to create a simple Java Server Faces
application using NetBeans 6.1 and deploy on GlassFish. In the process
it explained some basic
JSF concepts as well. If you remember, it built an application that
allows you to create a database of cities/country of your choice. In
that application, any city/country combination can be entered twice and
no errors are reported.
This blog entry extends TOTD
#42 and show the list of cities, that have already been
entered,
starting with the letters entered in the text box. And instead of
refreshing the entire page, it uses JSF Extensions
to make an Ajax call to the endpoint and show the list of cities based
upon the text entered. This behavior is similar to Autocomplete
and shows the suggestions in a separate text box.
Let's get started!
Download latest JSF-Extensions
release .
Unzip the bundle as:
~/tools >gunzip
-c ~/Downloads/jsf-extensions-0.1.tar.gz | tar xvf -
In NetBeans IDE, add the following jars to Project/Libraries
Edit "welcomeJSF.jsp"
Add the following to the required tag libraries
<%@taglib prefix="jsfExt"
uri="http://java.sun.com/jsf/extensions/dynafaces" %>
The updated page looks like:
Add the following tag as the first tag inside
<f:view>
The updated page looks like:
Add prependId="false" to "<h:form>" tag.
The updated tag looks like:
Add the following fragment as an attribute to
<h:inputText> tag with "cityName" id:
onkeyup="DynaFaces.fireAjaxTransaction(this, {
execute: 'cityName', render: 'city_choices', immediate: true});"
This is the magic fragment that issues an Ajax call to the endpoint. It
ensures execute
portion of the request lifecycle is executed for "cityName" and
"city_choices" (defined later) is rendered.
The updated page looks like:
Add a new <h:outputText> tag after
<h:commandButton> tag (to hold the suggestions output):
<h:outputText id="city_choices"
value="#{dbUtil.cityChoices}"></h:outputText>
The updated page looks like:
Add the following fragment to web.xml
<init-param>
<param-name>javax.faces.LIFECYCLE_ID</param-name>
<param-value>com.sun.faces.lifecycle.PARTIAL</param-value>
</init-param>
The updated file looks like:
Edit "server.Cities" class
Add a new NamedQuery in Cities class (at the mark after
yellow-highlighted parentheses):
The query is:
@NamedQuery(name = "Cities.findSimilarName",
query = "SELECT c FROM Cities c WHERE LOWER(c.cityName) LIKE
:searchString"),
This NamedQuery queries the database and return a list of city names
that matches the pattern specified in "searchString" parameter.
Change the toString() method implementation to return
"cityName". The updated method looks like:
This allows the city name to be printed clearly.
Add a new method in "server.DatabaseUtil" as:
public
Collection<Cities> getCityChoices() {
Collection<Cities> allCities = new
ArrayList<Cities>();
if (cities.getCityName() != null &&
!cities.getCityName().equals("")) {
List list = entityManager.createNamedQuery("Cities.findSimilarName").
setParameter("searchString", cities.getCityName().toLowerCase() + "%").
getResultList();
for (int i = 0; i < list.size(); i++) {
allCities.add((Cities) list.get(i));
}
}
return allCities;
}
This method uses previously defined NamedQuery and adds a parameter for
pattern matching.
Now, play time!
The list of created cities is:
If "S" is entered in the text box (http://localhost:8080/Cities/), then
the following output is shown:
Entering "San", shows:
Entering "Sant" shows:
Entering "De" updates the page as:
And finally entering "Ber" shows the output as:
So you built a simple Ajaxified Java Server Faces application using JSF
Extensions.
Here are some more references to look at:
JSF
Extensions Getting Started Guide
Tech
Tip : Adding Ajax to Java Server
Faces Technology with Dynamic Faces
JSF
Extensions Ajax Reference
Java Server Faces 2.0 has Ajax functionality integrated into the spec
and this should be more seamless. I'll try that next!
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
mysql javaserverfaces
netbeans
glassfish ajax
GlassFish swimming to Brazil
Posted by arungupta on September 12, 2008 at 05:44 AM | Permalink
| Comments (1)
September is the month
of Java in Brazil. There are developer events and Java
conferences through out the country. And the month ends by kick
starting Sun
Tech Days in the city of Sao Paulo .
Kohsuke is already
in Brazil and here is my schedule:
Sep
23-26
Brasilia
Sep
27
Vitoria
Sep 28-Oct 1
Sau
Paulo
I'll be talking about GlassFish ,
it's ecosystem, Scripting Langauges & Web frameworks (for
example Ruby-on-Rails
and Groovy-on-Grails ),
Hudson , Web services and
anything else around GlassFish :)
This is my first trip to Brazil so I'm really excited and gathered some
facts. Here are some interesting tidbits:
Largest and mot populous country in South America
Fifth largest country by geographical area (5.7% of total
land, approx 88% of USA)
Fifth most populous country (2.81 % of world population,
approx 61% of USA)
Consists of 26 states and one Federal District, Brasilia
is the capital city, Sao
Paulo is the economic center
Equator line passes through the northern tip of Brazl in
the state of Amapa
(my first trip to Southern Hemisphere)
Has 60% of the biggest and the richest tropical rainforest
- Amazon
Rainforest (most diverse
population of birds )
Brazilian Football (known as Soccer in USA) has produced
some of finest players - Pele ,
Three R's (Ronaldo ,
Rivaldo
& Ronaldinho ).
And they have won FIFA
World Cup Football a record 5 times.
Samba
Dance and Rio
Carnival demonstrates the true dancing spirit
And of course To
Brazil by Venga
Boys as shown in the video below:
Lets hope I get my visa in time before the travel ;-)
More details to come ...
Technorati: conf
brazil
suntechdays
glassfish
Kenai - High Throughput and Scalable Rails on GlassFish
Posted by arungupta on September 11, 2008 at 06:09 AM | Permalink
| Comments (0)
Kenai
(pronounced 'keen-eye') is a fictional character
from Disney's Brother
Bear series. It's also a river ,
mountain
range , national
park , peninsula
and a city
in the southern coast of Alaska in the United States. But that's got
nothing to do (as much as I know) with either Rails or GlassFish.
But Project
Kenai was announced last week. It's a developer hub with SCM,
issue tracking, forums
and similar stuff you need for hosting your open source projects. And
it is
a Rails application deployed on GlassFish
v2.
Read all about it in an
interview
with the lead developer Nick
Sieger . Fernando gave a great overview (slides
here ), with excellent tuning tips for Rails on GlassFish, in
Rails Conf Europe last week.
Other Rails on GlassFish success stories are described here .
And if you want, enjoy this beautiful video of Kenai National Wildlife
Refuge.
Technorati:
rubyonrails
jruby ruby glassfish
stories
kenai
Rails Conf Europe 2008 - Day 3
Posted by arungupta on September 05, 2008 at 10:17 PM | Permalink
| Comments (0)
Last day of Rails Conf Europe 2008 (Day
1 & Day
2 ), and it's finally over!
David Black's opening session talked about Ruby
and Rails Symposium: Versions, Implementations, and the Future .
Here is a brief summary of MRI Ruby versions:
Ruby 1.8.6
Bread and butter for many of us
1.8.7
1.8 with lots of backported 1.9 features
Help with migration to 1.9
Not gaining traction, is it ?
1.9.0
First release of 1.9
Not particularly feature stable
Not in wide production use.
1.9.1
Feature freeze 9/25
Release Christmas 2008 (planned)
Expected to be more stable
The
talk showed some of the new features coming up in Ruby 1.9.x. An
informal survey of audience indicated the following numbers:
4 - How many are using 1.8.7 ?
98% - How many are using 1.8.6 ?
1 - How many are using 1.9.0 ?
4 - Tried 1.8.7 and not switching
3 - Tried 1.9 and not switching
85% - Never tried 1.9
JRuby
is an alternative implementation of Ruby that runs on Java VM.
And when prompted, I quoted all the JRuby numbers (75% memory
improvement with upcoming Rails 2.2, 33,000 assertions from Ruby Spec
and 22,000 tests for Ruby 1.8.6 compliance, Ongoing work on Ruby 1.9
compliance). JRuby "It's just Ruby" - knowing Java is not a
pre-requisite to run JRuby for your Ruby or Rails applications!
In Developing
Ruby and Rails applications with the NetBeans IDE
talk, Erno & Petr showed all the cool features of Ruby/Rails
editing, syntax highlighting, debugging, project creation, refactoring
and many more. You can find all about it here .
Rails
powered by GlassFish talk was well attended. The slides are
available here
and if you attended the session, please rate
it here . I value your feedback. Some of the excerpts from the
talk are:
Let us know by sending an email to webtier@glassfish.dev.java.net
if you are using JRuby or GlassFish or JRuby and GlassFish in
production. We'll be happy to feature you on blogs.sun.com/stories .
Rails
2.0.4 and 2.1.1 were released during the
conference. Now I need to start working on all the different blogs
promised earlier this week :)
Here are some pictures from Day 3:
And finally the complete photo album:
Next stop - Braaaazzzil!
Technorati: conf
railsconf
berlin
rubyonrails
Rails Conf Europe 2008 - Day 2
Posted by arungupta on September 05, 2008 at 10:16 PM | Permalink
| Comments (0)
Rails
Conf Europe 2008 Day 1 was mostly about tutorials .
On Day 2, David Black gave the opening session. After some logistics he
introduced the favorite
son of Chicago - David Heinemeier Hansson. The theme of
DHH's session was "Legacy Software". Now that Rails is 5 years old, the
discussions of legacy is indeed meaningful. He showed some code from BaseCamp
and showed how refactoring can deal with legacy. I love his statement
"What you write today will become legacy". That is indeed so true
especially given the fact that Rails community is now thinking about
legacy. There is Rails 1.2.x, 2.0.x, 2.1 and 2.2 coming up - it was
bound to happen. Overall a great session and love the honesty!
In JRuby:
The Other Red Meat by Tom Enebo, the highlights were:
JRuby is
"It's just Ruby". No prior knowledge of Java is
required, at all, to run JRuby.
22,000 tests and 33,000 assertions (from Ruby Spec ) all pass to
ensure 1.8.6 compliance.
75% memory improvement with upcoming Rails 2.2. The numbers
captured from the preso for 1000 requests and 10 concurrent users are:
10
Rails instances
Edge
Rails
Startup
Memory
200 Mb
50
Mb
Heap
(at end)
233
Mb
55
Mb
I'll explain in a detailed post later on how to generate these numbers
Several JRuby
success stories
FFI support in JRuby that will make converting a C-based
plugin to pure-Ruby a breeze
In Rails
Software Metrics Roderick talked about different tools to
generate metrics for Rails applications.
rake stats: Provides Code to Test Ratio (0.8 to 1.6 is a
good range)
flog: Tracking code complexity (available as gem, useful
for refactoring, elaborates on complexity)
rcov: Tracking test coverage (analyzes line coverage,
available as gem)
heckle:
Analyzes branch coverage (available as gem, dynamically mutates your
code - flipping a branch should cause test failire, takes very long,
not feasible for TDD)
saikuro: Cyclometic complexity (Decidedly
scientific graph theory, available as gem, highlights overly complex
methods, useful to spot refactoring methods)
metrics_fu: Set of Rake
tasks to use with CruiseControl, Runs all of the before mentioned on a
check-in. Anybody interested in integrating that with Hudson ?
The advise "A single metric is seldom useful, pair them to see what's
going on." is certainly very practical.
Fernando explained in details in his session, Achieving
High Throughput and Scalability with JRuby on Rails , on how
to tune GlassFish
for Rails applications. Look for his slides, they got real meat from a
Rails application running on production with multiple concurrent
requests.
At Five Runs
exhibit, I found about FiveRuns
monitoring on JRuby . That means you can generate all the performance
monitoring data on GlassFish. And then there is nagios and stickshift
for monitoring. That's a few blog posts for me later :)
Here are some of the sessions I plan to attend Day 2:
Here are some pictures from Day 2:
And you can see the gourmet lunch was not only beautifully decorated,
it was equally luscious:
And finally the complete photo album so far:
Stay tuned for Day 3 blog!
Technorati: conf
railsconf
berlin
rubyonrails
GlassFish and MySQL Student Contest - 3 steps to earn $500
Posted by arungupta on September 03, 2008 at 05:08 AM | Permalink
| Comments (0)
Are you a student and like to earn $500 ? Here are three steps:
That's all it takes for a chance to win $500. And there are 5 $250
second prizes as well. The prize money comes right
in time for winter holiday shopping :)
A pre-compiled list of several
projects is available for you to get started. And you can
certainly churn an innovative idea from your creative mind!
Make sure to read the contest
rules before applying, complete details here .
Make sure to submit a substantive
feedback since that is an important part of judging the submission.
Do you know:
NetBeans IDE
allows you to create several Java EE modules like JSP, Servlets, Java
Persistence Units, Enterprise Java Beans, Java Server Faces and Web
services seamlessly and deploy them directly on GlassFish.
Rails
and Grails
applications can be deployed on GlassFish v2 UR2 as WAR files.
Metro
is an extensible and highly performant Web services stack in GlassFish.
New functionality can be easily added by creating and configuring your pipes .
And there are many more
features that allow your developer instincts to contribute
something valuable to GlassFish ecosystem. Let those bright minds run
free and start working on it today! The contest ends October 22, 2008.
spotlight.dev.java.net
is a onestop that provides links to several demos, screencasts,
presentations, tutorials that can be leveraged for your curriculum.
Technorati: glassfish
mysql netbeans
students
spotlight
contest
Rails Conf Europe 2008 - End of Tutorial Day
Posted by arungupta on September 03, 2008 at 12:20 AM | Permalink
| Comments (1)
Sep
2, 2008 was the Tutorials Day @ Rails Conf Europe .
I attended Renegade's
Guide to Hacking Rails Internals (partly) and Deploying
and Monitoring Ruby on Rails . The first session did exactly
what it says - explained the complete internals, digging deep into the
code and how to hack them to
meet your needs. I thoroughly enjoyed the second tutorial as it covered
the deployment in detail and somewhat monitoring.
The first part covered the common Application Server and Web/Proxy
Servers used for Rails deployment. It explained the different
deployment scenarios and their pros/cons. The Application Servers
(along with their detailed notes) are:
FastCGI
Use mod_fcgi
Proxy local and remove FastCGI instances
Oldest way of deploying Rails
Deprecated & Unstable (security problems in impl
of Apache2, easy to get zombie processes, works for some)
Hard to debug
Dont' use in production
Mongrel
As an alternative to FastCGI
Complete HTTP-server that can load arbitrary Ruby-servlets
Built-in Rails support
Utility to manage several Mongrel clusters
(mongrel_cluster)
Very robust, strict HTTP parser, easy to debug
Defacto standard deployment with Apache 2.2 and
mod_proxy_balancer
Can be a bit difficult to setup
Not so easy on mass/virtual hosting
mod_rails (aka Phusion Passenger)
Similar to mod_php
Fairly new module of Apache 2.2
Allows Apache to control Rails instances
Apache starts/stop app instance depending on the app load
Very easy to setup
Able to run any RACK-compatible Ruby app
Pros
Touching a file "restart.txt" and Phusion automatically
restarts all the Rails instances
All Rails instances are local to a machine
HTTP balancer is required to spawn across multiple
machines
Fairly new but ready for production
Makes setup easier - on single machine
Multiple server still require load balancer
Suitable for mass hosting
JRuby, GlassFish & Co
Similar to mod_rails where multiple runtimes can run on a
single machine
WAR-based deployments
Suitable for Java shops
Database connection pooling
I'll be talking all about Rails and GlassFish in my session
tomorrow @ 1:40pm
Here are the requirements on Proxy servers:
Hide cluster backend from the user
Load-balancer backend instances
Recognize down hosts
Fair scheduler
And the different choices (along with their notes) are:
Apache2
Introduced mod_proxy_balancer
Can speak to multiple backends and balance requests
Can act as pure proxy or can also serve static files
Deliver static content
Pros
Very old, mature, stable
Many people know how to work with Apache
Integrates well with other modules (SVN, DAV, etc)
Cons
Can be complicated to configure
The stock Apache is quite resource-hungry (12-15 KB,
where nginx takes 3-5 KB and 20% faster serving of static files)
compared to pure proxy solutions
nginx
Popular Russian web server with good proxy support (40%
websites in Russia run nginx)
Can load-balance multiple backends and deliver static
content
Quite popular with Mongrel as Rails backend
Simple configuration file -
http://brainspl.at/nginx.conf.txt (nginx conf file)
Pros
Stable, Robust, Fast
Use fewer resources (CPU & RAM) than Apache
proxy-mode & static files
Simple configuration file
Can directly talk to memcached - SSI
Cons
More documentation would be nice
No equivalent for many Apache modules
LightTPD
Lightweight and Fast web server
Balancing proxy server
Good FastCGI support
Used to be popular - until Mongrel came around
Nobody is using these days in production
Pros
Fast & lightweight
User fewer resources
Simpler configuration file
Cons
Unstable for some people
Slow development cycle
More docs would be nice
HA-Proxy (also applies to Pen and Pound)
Reliable, High performance TCP/HTTP-level balancer (SNMP
or MySQL proxying too)
Proxying and content inspection
No content serving, just a proxy
Pros
Mature, stable & fast
TCP & HTTP Balancing
Cons
Few Rails examples
Usually not needed in Rails setup
After discussing all the options in detail, the recommendations were:
Small site - Apache 2.2 with mod_rails
Medium site - Apache 2.2 as front-end proxy + Mongrel or
mod_rails as backend, Deliver static files with Apache.Not nginx
because it does not depend on the extra power to deliver static files.
Large Rails site - Redundant load-balancer, redundant
proxy/web, Mongrel/mod_rails
Heavy static files - Dynamic requests to Apache+mod_rails,
static files nginx/lighttpd
Java Shop - WAR fles + integrate with existing Java
landscape and infrastructure
Then it explained Capistrano, Webistrano ,
Macistrano
and ran through a practical lab of using them.
The tutorial concluded by discussing monitoring. The two criteria for
monitoring are:
Is it still running ?
What are the trends ?
The two main recommendations are:
Monit
Process-level monitoring
Checks PID-files, ports and perms
Reacts by executing a script and/or alerting
Munin
Host level monitoring tool
Master periodically ask nodes for local data
Check system resources and records historical data
Allows to recognize trends and make predictions
Alerting support
And other tools that were mentioned as well such as Nagios, Big
Brother, New Relic RPM, FiveRuns and JMX. The slides will be published
on Rails Conf website so watch
this space .
The evening concluded with Q&A from Rails Core Members - DHH,
Koz & Jeremy.
Here are some of the sessions I plan to attend tomorrow:
And then there is exhibitor hall as well so will see how much I can
attend :) I have to miss the late afternoon and evening sessions/BoFs
because of Berlin/Brandenberger
JUG preso.
Here are some pictures from yesterday:
And finally the complete photo album so far:
The sessions/exhibit halls start today!
Technorati: conf
railsconf
berlin
rubyonrails
Mango* - King of FOSS Offerings
Posted by arungupta on September 02, 2008 at 05:55 AM | Permalink
| Comments (7)
If there is one thing that I terribly miss after moving to this
country, that would be the variety of Mangoe s
in India. I've been asked at the United States Customs if I'm importing
any mangoes. The fruit's flavor, fragrance and color is just great so I
don't blame them at all. There is even International
Mango Festival conducted every year since 1987 in Delhi. The
festival features more than 550 varieties for visitors to view and
taste.
I can talk at lengths about the fruit Mango but this entry is about
Mango*. So what is it ?
Project
mang o*
is an initiative to promote the use of Sun's (Free Open Source
Software) FOSS stack in the enterprise middleware market. Mango* is an
acronym which stands for
M y SQL A nd
N etbeans
G lassfish
O pen*...(OpenESB
or OpenSSO or OpenPortal or OpenSolaris...)
It's not a new prodcut or technology but a packaging of Sun's FOSS
offerings that brings reliable, scalable and open software to the
enterprise. The main purpose is to demonstrate and illustrate
how enterprises achieve their IT and business goals using Sun's FOSS
technologies.
You can taste/download mango* here ,
it contains the king of FOSS offerings.
And don't forget to taste the "king of fruits" on your next visit to
India :)
Technorati: mango
glassfish
netbeans
mysql foss sun
Rails Conf Europe 2008 and Bratwurst-on-Rails
Posted by arungupta on September 01, 2008 at 11:17 PM | Permalink
| Comments (0)
I arrived Berlin yesterday on a non-adventurous United flight from San
Francisco, just the way I like it! The flight from Frankfurt was
delayed 30 minutes but that's normal these days :)
The venue of RailsConf
Europe 2008 is same
as last year so street names/geography are somewhat familiar.
But the conference
hotel was sold out so am instead staying across the street.
Visited Brandenburger
Tor for a short duration after checking into the hotel. Also
stopped by the Peugeot showroom on Unter
den Linden and saw popular bear figurines in a side street.
The evening ended with a social gathering celebrating the popular
German
culture of Bratwurst -on-Rails .
It's always exciting to meet my blog readers, thank you! Let me know if
I'm missing any of your expectations.
The tutorial starts today and the conference starts tomorrow. If you
are in Berlin, don't forget to attend the joint JUG
and TU-Berlin talk . And my talk on "Rails
powered by GlassFish " is scheduled on Thursday, Sep 4 @
1:40pm.
The evening really eneded with a 40 minutes run and dinner in room
service. The Jolly
Hotel
is really nice, newer rooms, courteous staff, delicious and very neatly
prepared Club Chicken
sandwich and prompt room service, definitely a good recommendation.
However the fitness center is minimal with one ultra-loud
treadmill and 3 other basic machines. The hotel staff informed that
they are working on furnishing the fitness center (known as Wellness
Center here). And there is only one American
channel which is only talking about Storm
Gustav and Republican
National Convetion , Juno
of Juneau since my arrival :(
Anyway, enjoy the pictures so far!