Wednesday September 17, 2008
TOTD #45: Ajaxifying Java Server Faces using JSF Extensions
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!
| ~/tools >gunzip -c ~/Downloads/jsf-extensions-0.1.tar.gz | tar xvf - |

| <%@taglib prefix="jsfExt" uri="http://java.sun.com/jsf/extensions/dynafaces" %> |

| <jsfExt:scripts /> |


| onkeyup="DynaFaces.fireAjaxTransaction(this, { execute: 'cityName', render: 'city_choices', immediate: true});" |

| <h:outputText id="city_choices" value="#{dbUtil.cityChoices}"></h:outputText> |

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


| @NamedQuery(name = "Cities.findSimilarName",
query = "SELECT c FROM Cities c WHERE LOWER(c.cityName) LIKE
:searchString"), |

| 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; } |






Posted by Arun Gupta in web2.0 | Comments[3]
|
|
|
|
|
Sunday March 16, 2008
Travel Schedule - Next 5 weeks
Here is my travel schedule for next 5 weeks:
| Mar 17-21 | Ajax World, New York | Web Application Development using jMaki |
| Mar 25-26 | The Server Side Java Symposium, Las Vegas | Rails powered by GlassFish & jMaki |
| Mar 27 | Developer Update, St Louis Westport DoubleTree, FREE event | Open Source Web Services stack in GlassFish |
| Mar 28 | Developer Update, Kansas City, FREE event | Rich Internet Applications and GlassFish |
| Apr 16-19 | FISL, Brazil | Web 2.0 Application Development
using jMaki and Asynchronous Ajax for Revolutionary Web Applications |
Posted by Arun Gupta in General | Comments[2]
|
|
|
|
|
Wednesday December 12, 2007
TOTD #20: How to create a new jMaki widget ?
This TOTD explains how to create a new jMaki widget and make it available in the NetBeans palette.
In order to create a jMaki widget, it's important to understand the jMaki Widget Model.
![]() |
Basically, "component.htm", "component.js" and an optional "component.css" together make a jMaki widget. |
Here are the files for a Hello World widget that takes an argument, concatenates it with the string "Hello" and displays the result on the page.
component.htm
<div id="${uuid}" class="hello"></div> |
component.js
jmaki.namespace("jmaki.widgets.hello"); |
component.css
.hello { |
The following files are required if you like to package your component as a reusable widget library in the NetBeans IDE:
hello.jsp
<a:widget name="hello" args="{name: 'Duke'}"
/> |
Bundle.properties (top-level)
jMaki.Library.Name=jMaki Hello Widget |
Bundle.properties (templates)
NAME_templates.hello=Hello |
widget.json
{ |
Package these files together in the following directory structure (choose any zip file name):
Bundle.properties |
And then you zip up these files together, that's it! Now this zip file can be added to the jMaki palette in the NetBeans IDE as shown here. Really simple!
After the widget is added to NetBeans palette, it looks like as shown below:

Now, just like any other jMaki widget, you can drag-and-drop "Hello"
from the jMaki palette in your JSP page and the following code fragment is
generated:
<a:widget name="hello" args="{name: 'Duke'}" />
After the application is deployed, the page is rendered in the browser as shown below:

Couple of points ...
templates directory. This enables drag-and-drop of your widget
in those languages as well.Bundle.properties otherwise they will not be recognized.Please leave suggestions on other TOTD that you'd like to see. A complete archive is available here.
Technorati: totd jmaki web2.0 widgets ajax netbeans
Posted by Arun Gupta in web2.0 | Comments[12]
|
|
|
|
|
Monday June 04, 2007
Follow up from my previous entry, here is a list of slides for the next generation Web application, a.k.a "Web 2.0", sessions from Sun.
Technorati: Javaone Web2.0 Ajax jmaki REST
Posted by Arun Gupta in web2.0 | Comments[0]
|
|
|
|
|
Friday April 20, 2007
Ajax is a popular term for past few months but is still being written incorrectly as "AJAX" (all capitals) instead of "Ajax" (camel case). I started using AJAX but then corrected myself and have been using Ajax since then. So the correct term is Ajax, not AJAX.
Here is a list of several reasons (some mine and others from my colleague Rick's list):
The name is shorthand for
Asynchronous JavaScript + XML". It is intended to be a shorthand,
not an acronym. And notice it is "+", not an "and" indicating a
collection of technologies.I needed something shorter than
“Asynchronous JavaScript+CSS+DOM+XMLHttpRequest” to use when discussing
this approach with clients.". Ajax is not just Asynchronous
JavaScript and XML, it's CSS and DOM as well. Moreover JSON is becoming
a more
popular format for data interchange. Should "AJAX" then instead be
coined as "AJAJ" ? Or if an application happen to use Text instead, will
they call it as "AJAT" ?I think the above three bullets should be sufficient to convince anybody to use "Ajax" instead of "AJAX". But if not, here are some more reasons to switch to the correct usage of term:
Ajax beats AJAX in all but bad newspapers."Now there should be no reason to use "AJAX". However if you still feel like using this term, please leave a comment on this blog and let's talk. There are some incorrect usages in sun.com and I'll follow up to get them fixed.
Posted by Arun Gupta in web2.0 | Comments[4]
|
|
|
|
|
Friday March 23, 2007
Day 1 @ The Server Side Java Symposium
I've been in Las Vegas for past 2 days attending The Server Side Java Symposium. Sun is the only platinum sponsor.
|
|
The conference is at The Venetian, one of the nicest hotels on the strip, but found two irritating issues for working people:
TheServerSide sponsored the travel and lodging and check out the pictures of the suite, it's pretty cool!
I missed the opening keynote by Karen Tegan Padir but heard it went well. Later that day, I attended a session by Ben Galbraith and Dion Alamer (co-founders of Ajaxian) on "State of Ajax".
The session started by asking "Does anyone here not know how to do Ajax ?". There were few hands raised and so the session started by creating a simple HTML form that takes a zip code and returns the corresponding city using XMLHttpRequest without any page refresh. Then the talk explained three main Ajaxian architectures:
The talk identified Google Maps, Google Suggest, Housingmaps, TaDaList as Ajax innovators. In my opinion, Google Suggest was really the first effort that showed Ajax-like interactions.
Ben and Dion divided JavaScript in two camps: "JavaScript is Good" and "JavaScript is Bad". jMaki was classified in the first camp, Google Web Toolkit in the second camp and Direct Web Remoting in partly both the camps. Project Phobos was also classified in "JavaScript is Good" camp as it enables server-side scripting. Ben will be uploading a new video on jMaki showing Craig's list mashup so stay tuned for that.
Prototype, Scriptaculous and Dojo were rated as the most popular toolkits in a survey conducted last year on Ajaxian. The speakers classified Dojo as "Huge Elephant of JavaScript" with support for offline storage, presentation, remoting, charts and many other features.
IntelliJ IDEA 6.0 and NetBeans 5.5 for development and FireBug for debugging were the recommended tools. Then there were few slides on offline storage, especially the upcoming capabilities in Firefox 3 (off-line cache, off-line events, persistent cache), dojo.storage package and Adobe Apollo with offline flash. There was a brief mention of Project Tamarin that will provide approx 10 times faster JavaScript runtime and this will be integrated in a later version of Firefox. And the talk concluded by giving a future slide including topics such as off-line Ajax, fast JavaScript interpreters, HTML 5 and others.
A complete Day 1 report is available here. Ed Ort also posted notes.
Technorati: theserverside Ajax venetian
Posted by Arun Gupta in webservices | Comments[2]
|
|
|
|
|
Monday March 19, 2007
More on Sun Web Developer Pack
More buzz on Sun Web Developer Pack ...
Technorati: swdp web2.0 ajax scripting glassfish jmaki phobos
Posted by Arun Gupta in web2.0 | Comments[0]
|
|
|
|
|
Friday March 16, 2007
Sun Web Developer Pack in Blogs
Here is the SWDP buzz so far:
Download it, Get started, and give us feedback. And if you are wondering, it's a FREE download.
Technorati: swdp web2.0 ajax scripting glassfish jmaki phobos
Posted by Arun Gupta in web2.0 | Comments[1]
|
|
|
|
|
Wednesday March 14, 2007
Follow up from my previous entry, here is a complete list of all the next generation Web application, a.k.a "Web 2.0", sessions from Sun.
| Session # | Title |
| BOF 6012 | JavaScript Programming Language Best Practices for Developers on the Java Platform |
| TS 6029 | Beyond Blogging: Feeds in Action |
| TS 6375 | jMaki: Web 2.0 App Building Made Easy |
| TS 6381 | The Future of the Java Technology Web Tier |
| TS 6411 | JSR 311: The Java API for RESTful Web Services |
| BOF 6412 | Describing RESTful Applications: WADLing with Java |
| BOF 6424 | Accessibility for Ajax and Web 2.0 Applications, from Emerging Concepts to Practical Coding |
| BOF 6425 | Testing Web 2.0 Features, Using Real-World Applications |
| BOF 6807 | Real-World Comet-Based Applications |
| BOF 6876 | Ajax and Web 2.0 Performance Roundtable |
| TS 6957 | Project Phobos: Server-Side Scripting for the Java Platform |
| TS 8840 | Services Interoperability with Java Technology and .NET: Technologies and Tools for Web 2.0 |
| TS 9516 | Using jMaki in a Visual Development Environment |
There is more content that has not been publicly announced yet. And while we are working on making presentations for this year richer, fuller and more hands-on, get your self familiar with JavaOne 2006 archives on this topic.
| Session # | Title |
| TS 1161 | Evolving JavaServer Faces Technology: AJAX Done Right |
| TS 1222 | RESTful Web Services With JAX-WS |
| TS 1615 | Java EE 5 BluePrints for AJAX-Enabled Web 2.0 Applications |
| TS 1756 | Java Technology and REST: Implementing the Atom Protocol |
| TS 3577 | Using the Dojo Toolkit to Develop AJAX-Enabled Java EE Web Applications |
| TS 4372 | Java Technology, AJAX, Web 2.0 and SOA |
| TS 8614 | AJAX & Persistence: Emerging Patterns & Pain Points |
Technorati: Javaone Web2.0 Ajax jmaki REST JavaScript
Posted by Arun Gupta in web2.0 | Comments[1]
|
|
|
|
|
Tuesday March 13, 2007
Sun @ The Server Side Java Symposium
Here is the list of Sun Microsystems sessions at The Server Side, Java Symposium, Las Vegas next week:
Stop by and say hello to the folks who bring you this great technology!
Technorati: TheServerSide LasVegas Venetian Web services NetBeans Ajax JRuby Ruby GlassFish Sun presos
Posted by Arun Gupta in web2.0 | Comments[0]
|
|
|
|
|
Monday March 12, 2007
Introducing Sun Web Developer Pack
|
Sun Web
Developer Pack (SWDP) is a new integrated toolkit from Sun
Microsystems that consists of a collection of Web 2.0 technologies
that enable next generation Web application development. The toolkit
consists of binaries, tutorial, documentation, samples (including source) to
build your Web 2.0 applications and deploy them on industry-grade containers. It includes
support for building rich user interface using Ajax technologies with Project
jMaki & Project
Dynamic Faces, light-weight Web services with Atom
/ REST
APIs / WADL and server side
scripting with Project Phobos.
Check the system requirements to see the list of supported platforms, JDK versions, browsers, web containers and Ant. These applications can be hosted on Sun Java System Application Server 9.x, Sun Java System Web Server 7.0 U1, GlassFish v1 UR1, GlassFish v2 and Apache Tomcat 6. SWDP comes with NetBeans plug-ins that simplifies the design and development of Rich Internet Applications. These modules can be downloaded from NetBeans Update Center Beta with the name "Sun Web Developer Pack R1". Check out how to build jMaki and Phobos applications in a screencast. |
Get the Sun Web Developer Pack
Simplify development of your Web 2.0 applications
with this all-in-one download.
|
You can download SWDP as a stand-alone bundle and install on a supported Web container. Alternatively, you can download SWDP bundled with Java Application Platform SDK Update 3 Preview. The SDK bundle can be downloaded in three different flavors:
After installing SWDP, it's recommended to view the latest online Release Notes. The binaries are accompanied by a comprehensive tutorial and an SWDP forum to post your questions. You can also view the list of SWDP bloggers or subscribe to the aggregated pipe.
You can view and download demos, samples, widgets and much more using these technologies here. Blueprints provide you guidelines and code for building these applications.
Technorati: swdp web2.0 ajax scripting javaee javaeesdk glassfish jmaki phobos netbeans
Posted by Arun Gupta in web2.0 | Comments[12]
|
|
|
|
|
Friday March 02, 2007
Following up on my JSON blog, here is great table summarizing the strengths and weaknesses of JSON as compared to XML.
Technorati: XML JSON Web2.0 Ajax
Posted by Arun Gupta in web2.0 | Comments[0]
|
|
|
|
| Sun Microsystems is a silver sponsor of AJAX World Conference and Expo East 2007, Mar 19-21, New York City. Ajax Architect Greg Murray, Struts creator Craig McClanahan, and Jean Francois Arcand of Grizzly fame, all from Sun, will be speaking. Here are the topics:
It seems the conference
planners really like Greg a lot since they've not only featured him on their main
page but given his brief bio
thrice
And his last name is "Murray", not "Murry".
All of them are great speakers. So if you are planning to attend Ajax World, I highly recommend their talk. You'll see/feel the passion.
Technorati: Ajax Web2.0 Sun AjaxWorld presos
Posted by Arun Gupta in web2.0 | Comments[2]
|
|
|
|
|
Thursday March 01, 2007
Language-neutral data format: XML and JSON
XML and JSON are the two prevalent choices for language-neutral data format. That means a format used to exchange data between client and server, independent of the language used on each end. We are familiar with XML pointy bracket syntax which has served us well so far. With Rich Internet Applications becoming more common, there is a need to have a light-weight data interchange format. And so JSON is catching up (11% for data transfer in 2006).
Basically, JSON is built on two structures:
See message samples formatted in JSON and equivalent XML. Tim Bray summarizes when to use which format.
Here is a collection of interesting articles in case you want to dig deeper:
The key advantages of JSON I derived from my reading of the above articles are:
There are some disadvantages as well:
}}]} at the end of data snippet is frightening
and debugging pain.In jMaki, we use JSON in Java. Here is a sample code to create a JSON object using these APIs:
import org.json.*;
import java.io.*;
public class JSONSample {
public static void main(String[] args) throws Exception {
// basic object creation
JSONObject person = new JSONObject();
person.put("name", "duke");
person.put("age", "10");
System.out.println(person.toString());
// how to create array and write to a "writer"
JSONObject address = new JSONObject();
JSONArray array = new JSONArray();
array.put("4140, Network Circle"
;
array.put("Santa Clara"
;
array.put("CA - 95054"
;
address.append("address", array);
OutputStreamWriter osw = new OutputStreamWriter(System.out);
address.write(osw);
osw.flush();
// XML->JSON conversion
JSONObject likes = XML.toJSONObject("<likes><running/><skiing/></likes>");
System.out.println(likes.toString());
}
}
And here is the corresponding output:
{"age":"10","name":"duke"}
{"address":[["4140, network circle","Santa Clara","CA - 95054"]]}
{"likes":{"skiing":{},"running":{}}}
This API also allows conversion from comma-delimited text, HTTP, Cookie, and CookieList to JSON conversions. The source code for JSON in Java is freely available but here are two suggestions for ease-of-use:
In summary, XML is document-oriented and JSON is data-oriented. So if you want to deal with highly structured documents that requires a complex structure, binary data, exact ordering of elements and be able to render itself then use XML. OTOH, if you are focused on light-weight data exchange then JSON is the way to go.
Follow the JSON blog and enjoy!
Technorati: XML JSON DataFormat JavaScript Web2.0 Ajax jMaki
Posted by Arun Gupta in web2.0 | Comments[5]
|
|
|
|
|
Monday February 26, 2007
Last Friday jMaki team, at Sun Microsystems, arranged a jMaki Day for Sun-internal audience. The day was planned to introduce the technology and explains it's nuts and bolts with hands-on experience. Even though nobody outside Sun could attend it, but all the presos and lab material is available here.
The morning sessions gave an overview of jMaki and included:
The afternoon was BYOL (Bring Your Own Laptop) hands-on-labs and discussion with the team. It included:
The slides for the morning session and hands-on-labs are available. Here are some pictures:
Greg Murray |
Attendees |
Attendees |
Carla Mott |
Roberto Chinnici |
Doris helping with mic |
Ludovic Champenois |
Greg Murray |
Lunch |
Lunch |
Hands-on-labs |
Hands-on-labs |
You can get a flavor of these sessions and labs at Sun Tech Days.
You can also view a collection of samples (run or download them) put together by Sun's Web 2.0 team. You can also look for a collection of jMaki samples here. All of these samples can be run on GlassFish.
Here are some important jMaki links:
Please send any feedback on slides and hands-on-labs to dev-AT-ajax.dev.java.net.
Technorati: jmaki ajax netbeans glassfish presos
Posted by Arun Gupta in web2.0 | Comments[2]
|
|
|
|
|
Today's Page Hits: 4441
Total # blog entries: 994
| « November 2009 | ||||||
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
|---|---|---|---|---|---|---|
1 | 2 | 4 | 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 | ||||||