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]
|
|
|
|
|
Today's Page Hits: 265
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 | ||||||
Here are some other useful resources you should refer people to:
Old, but good overview article:
http://java.sun.com/developer/technicalArticles/J2EE/webapp_3/
Great tutorial that actually explains how DF works and comes with a downloadable code example:
https://jsf-extensions.dev.java.net/mvn/tutorial.html
Posted by Jennifer on September 17, 2008 at 08:51 AM PDT #
Posted by Arun Gupta's Blog on September 22, 2008 at 06:05 AM PDT #
Posted by Arun Gupta's Blog on October 14, 2008 at 05:55 AM PDT #