Tuesday September 11, 2007
Sun Microsystems kicks off 2007-2008 Tech Days and marks the 10th anniversary of the developer event. This blog celebrates the decade by announcing "Sun Tech Days Event Map" - a real-life RIA created using jMaki. It allows you to choose the date on a web page using a rich calendar widget, shows the city where Sun Tech Days event is happening during that month and then shows that city location in a map. Play the video below to see how the application looks like:
This application shows several concepts of jMaki:
This application is built using NetBeans IDE 5.5.1, jMaki 0.9.7.3 and deployed on GlassFish RC4. Let's get started.
Web" in "Categories"
and "Web application" in "Projects". Click on
"Next >".SunTechDays" and choose
GlassFish as the "Server" and take all other values
default. Click on "Next >".jMaki Ajax Framework" and choose "Two
Fixed Right Sidebars" layout.Finish".index.jsp"Top Right Column" by dragging-and-dropping "Dojo
Combobox".Right Column" with "Yahoo Calendar".Left Column" with a "Google Map".Runtime" tab, expand "Databases",
right-select the node with the value "jdbc:derby://localhost:1527/sample"
and select "Connect".app".Execute Command...".
Create the table using the following SQLcreate table TECHDAYS_SCHEDULE (startDate date,
endDate date,
location varchar(255),
PRIMARY KEY (startDate, endDate))INSERT INTO TECHDAYS_SCHEDULE VALUES ('9/11/2007', '9/12/2007',
'Boston, United States');
INSERT INTO TECHDAYS_SCHEDULE VALUES ('9/24/2007', '9/25/2007', 'Rome,
Italy');
INSERT INTO TECHDAYS_SCHEDULE VALUES ('9/26/2007', '9/28/2007', 'Milan,
Italy');
INSERT INTO TECHDAYS_SCHEDULE VALUES ('10/19/2007', '10/19/2007',
'Taipei, Taiwan');
INSERT INTO TECHDAYS_SCHEDULE VALUES ('10/23/2007', '10/25/2007',
'Shanghai, China');
INSERT INTO TECHDAYS_SCHEDULE VALUES ('11/1/2007', '11/3/2007',
'Beijing, China');
INSERT INTO TECHDAYS_SCHEDULE VALUES ('11/6/2007', '11/8/2007', 'Tokyo,
Japan');
INSERT INTO TECHDAYS_SCHEDULE VALUES ('12/3/2007', '12/5/2007',
'Frankfurt, Germany');
INSERT INTO TECHDAYS_SCHEDULE VALUES ('1/9/2008', '1/10/2008', 'Atlanta,
United States');
INSERT INTO TECHDAYS_SCHEDULE VALUES ('2/27/2008', '2/29/2008',
'Bangalore, India');
INSERT INTO TECHDAYS_SCHEDULE VALUES ('3/4/2008', '3/6/2008', 'Sydney,
Australia');
INSERT INTO TECHDAYS_SCHEDULE VALUES ('3/11/2008', '3/13/2008',
'Johannesburg, South Africa');
INSERT INTO TECHDAYS_SCHEDULE VALUES ('4/1/2008', '4/1/2008', 'St
Petersburg, Russia');
INSERT INTO TECHDAYS_SCHEDULE VALUES ('4/1/2008', '5/1/2008', 'Manila,
Philippines');
INSERT INTO TECHDAYS_SCHEDULE VALUES ('5/21/2008', '5/23/2008', 'Mexico
City, Mexico');New",
"Entity Classes from Database...".New Entity Classes from Database" dialog
window, choose "Data Source" and select "jdbc/sample"
value.Available Tables".
Select "TECHDAYS_SCHEDULE" and click on "Add >".Next >".suntech".Create Persistence Unit...".Create Persistence Unit..." dialog window take all
the default values and click on "Create".Finish".Configuration Files", open "persistence.xml",
click on "Add Class", click "Cancel", click on
"Add Class" again and now select "suntech.TechdaysSchedule"
and click on "OK".Source Packages", "suntech" node
and open "TechdaysSchedule.java".@NamedQuery(name = "TechdaysSchedule.findByMonth", query = "SELECT
t FROM TechdaysSchedule t WHERE t.techdaysSchedulePK.startdate >= :firstdate
and t.techdaysSchedulePK.enddate <= :lastdate"),Web Pages", open "glue.js" and add
the following code at the end of the file:jmaki.subscribe("/yahoo/calendar/onSelect",
function(args) {
var newDate;
if (typeof args.value == "undefined") {
var tempDate = new Date();
newDate = (tempDate.getMonth()+1) + "/" + tempDate.getDate()
+ "/" + tempDate.getFullYear();
} else {
var str = "" + args.value;
newDate = str.split(" ")[1] + "/" + str.split(" ")[2] + "/" +
str.split(" ")[3];
}
jmaki.doAjax({method: "POST",
url: "data.jsp?date=" +
encodeURIComponent(newDate),
callback: function(_req) {
var tmp = _req.responseText;
var obj = eval("(" + tmp + ")");
jmaki.log("tmp "+ obj);
jmaki.publish('/dojo/combobox/setValues',
obj);
// handle any errors
}
});
});
jmaki.subscribe("/dojo/combobox/onSelect", function(item) {
var location = item.value.split(',')[0] + ", " + item.value.split(',')[1];
var start = item.value.indexOf('(');
var stop = item.value.lastIndexOf(')');
var encodedLocation = encodeURIComponent("location=" + location);
// jmaki.xhp is provided as part of jmaki and maps to the XMLHttpProxy
var url = jmaki.xhp + "?id=yahoogeocoder&urlparams=" + encodedLocation;
jmaki.doAjax({url: url, callback : function(req) {
if (req.responseText.length > 0) {
// convert the response to an object
var response = eval("(" + req.responseText +
")");
var coordinates = response.coordinates;
v = {results:coordinates};
jmaki.publish("/jmaki/plotmap", coordinates);
} else {
jmaki.log("Failed to get coordinates for " +
location );
}
}
});
});<a:widget name="dojo.combobox" service="data.jsp"/>New" and then "JSP..."
using the name "data". Notice, the IDE automatically picks
up the file extension.<%@ page import="java.util.*" %>
<%@ page import="suntech.*" %>
<%@ page import="javax.persistence.*" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%
String dateParam = request.getParameter("date");
Date date = null;
if (dateParam == null || "".equals(dateParam))
date = Calendar.getInstance().getTime();
else {
SimpleDateFormat sdf = new SimpleDateFormat("MMM/dd/yyyy");
date = sdf.parse(dateParam);
}
EntityManagerFactory emf =
Persistence.createEntityManagerFactory("SunTechDaysPU");
EntityManager em = emf.createEntityManager();
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.set(Calendar.DATE, 1);
Date firstDateOfMonth = cal.getTime();
cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
Date lastDateOfMonth = cal.getTime();
List<TechdaysSchedule> list =
em.createNamedQuery("TechdaysSchedule.findByMonth").
setParameter("firstdate",
firstDateOfMonth).
setParameter("lastdate",
lastDateOfMonth).
getResultList();
out.println("[");
boolean first = true;
int count = 0;
SimpleDateFormat sdf = new SimpleDateFormat("MMM d, yyyy");
for (TechdaysSchedule t : list) {
StringBuffer buf = new StringBuffer();
buf.append(sdf.format(t.getTechdaysSchedulePK().getStartdate()));
buf.append(" - ");
buf.append(sdf.format(t.getTechdaysSchedulePK().getEnddate()));
String city = t.getLocation() + ", (" + buf.toString() + ")";
out.println("{");
out.println("name: \"" + t.getLocation() + "\", ");
out.println("label: \"" + city + "\", ");
out.println("value: \"" + city + "\"");
if (first) {
out.println(", selected: " + true);
first = false;
}
out.println("}");
if (count++ < list.size()-1)
out.println(",");
}
out.println("]");
%>And that's it!
Carla and I conceived this application together and Greg and helped with gluing the widgets.
Here are some potential fun improvements:
Technorati: jmaki netbeans glassfish suntechdays jpa screencast web2.0
Posted by Arun Gupta in web2.0 | Comments[14]
|
|
|
|
|
Today's Page Hits: 830
Total # blog entries: 1025
Posted by Arun Gupta's Blog on September 24, 2007 at 02:16 PM PDT #
Posted by Arun Gupta's Blog on September 26, 2007 at 01:26 AM PDT #
Posted by Arun Gupta's Blog on October 01, 2007 at 05:53 AM PDT #
Posted by Arun Gupta's Blog on October 16, 2007 at 11:20 PM PDT #
Posted by Arun Gupta's Blog on October 19, 2007 at 06:20 AM PDT #
Posted by Arun Gupta's Blog on October 30, 2007 at 08:20 AM PDT #
Hi Arun,
I use a MySQL Database. If I select in the calendar a month with 2 digits so oktober to december, it doesn't works no longer: exceptions: ParseException: Unparseable date: "Dec/11/2007" and in the jMaki logger: jMaki.doAjax Error: doAjax error communicating with dates.jsp?date=Dec%2F11%2F2007. Server returned status code 500. But it works for the months january to September.
best regards and thank you so much for your screencasts.
Posted by Anja on November 06, 2007 at 03:57 PM PST #
There might be some difference in the returned date format.
Did you try with JavaDB ?
Posted by Arun Gupta on November 06, 2007 at 05:38 PM PST #
Hi Arun
I think it's a language problem in the lib for the widget calendar
the DOM inspector has the value for month :
["Jan.", "Feb.", "Mär.", 9 more...]
the calender gives jan feb mar ....
in german
(mär)März=(mar)march
(okt) Oktober=(oct) october
(dez)Dezember= (dec)december
all other months are working.
I use NetBeans 6.0 beta2 in english
best regards and thanks for your help
Posted by Anja on November 08, 2007 at 09:10 AM PST #
Interesting, this app was certainly not localized :) Can you try changing the string array and see if the application continue to work ?
Posted by Arun Gupta on November 08, 2007 at 11:15 AM PST #
Posted by Arun Gupta's Blog on February 28, 2008 at 02:18 AM PST #
HI, this tutorial is excelent! Good work! But...
I'm tryng do my comboBox, refresh where I insert one new information(one new register) on the table.
But the combobox, only show the registers previous. No Show recents registers... However I give refresh (F5) in browser.... or any...
do you help me?
Posted by Carlos Mazzi on March 07, 2008 at 02:04 PM PST #
Posted by Arun Gupta's Blog on March 18, 2008 at 07:05 PM PDT #
Restaurant recommendations may be pulled from another service and shown for the event attendees.
Posted by LAPTOP BATTERY on November 26, 2008 at 08:57 PM PST #