Thursday Aug 09, 2007
Thursday Aug 09, 2007

The jMaki team keeps making great changes to the technology, but sometimes it is hard to keep up with all the changes. I have finally gotten a working version of the latest jMaki-wrapped Spry Accordion. I think that this API will be stable for awhile, so now is a good time to post some instructions on how to use the Spry Accordion in a NetBeans 5.5.1 Visual Web project using the latest NetBeans jMaki plug-in (1.6.9.9.9.5), which bundles jMaki 0.9.7.
One of the recent changes has been the data model. The jMaki team is now publishing the data model information on the ajax.dev.java.net portal at http://wiki.java.net/bin/view/Projects/jMakiDataModels. The data model for the Spry Accordion widget is as follows:
items::= "{" {<label> } "}"
label ::= "{" "label:" <string>, [<content> | <include> |<action> ]
[<lazyload>] [<rowid>] <selected>"},"
selected ::= "selected:" "true" | "false" (default is false)
include ::= "include:" <string> ,
lazyload ::= "lazyload:" "true" | "false",
rowid ::= "rowid:" <string> ,
content ::= "content:" <string>,
action ::= "action:" "{" [<topic>] <message> "},"
topic ::= "topic:" <string>,
message ::= "message:" <obj>
obj ::= <string> | <JavaScript object literal>
|
Note: This model is the same as the data model for the tabbed view. This means that you can swap out the accordion with a tabbed view and not have to change the data.
To follow this mini-tutorial, you need to get the NetBeans jMaki Plugin. If you have already installed the plugin, use the NetBeans Update Center from the Tools menu to make sure you have the latest version (1.6.9.9.9.5). If you have an earlier version, See Carla's blog entry about how to update the jMaki framework resources in a jMaki project.
I noted in an earlier blog entry that you also need to download the JSF Compounds library (jsfcompounds-0.0.2.jar). This is no longer true. The 1.6.9.9.9.5 plug-in includes this library.
BaseJSFjMaki/Web Pages/glue.js to Your-VWP-Project/Web Pages.
BaseJSFjMaki/Web Pages/resources to Your-VWP-Project/Web Pages/resources:
config.jsonjmaki.js
system-glue.js
BaseJSFjMaki/Web Pages/resources/spry folder to Your-VWP-Project/Web Pages/resources.
xmlns:a="http://jmaki/v1.0/jsf" to the <jsp:root> tag.
<webuijsf:panelGroup binding="#{Page1.groupPanel1}" id="groupPanel1"
style="position: absolute; left: 72px; top: 48px;">
<a:widget name="spry.accordion" value="#{SessionBean1.tripContent}"/>
</webuijsf:panelGroup> |
Now we can setup the web application to return data from the Travel database in the data model format for the accordion.
SELECT ALL TRAVEL.PERSON.PERSONID,
TRAVEL.PERSON.NAME,
TRAVEL.TRIP.TRIPID,
TRAVEL.TRIP.DEPDATE
FROM TRAVEL.PERSON
INNER JOIN TRAVEL.TRIP ON TRAVEL.TRIP.PERSONID =
TRAVEL.PERSON.PERSONID
ORDER BY TRAVEL.PERSON.PERSONID ASC,
TRAVEL.TRIP.DEPDATE ASC
|
public String getTripContent() {
// Data Model Format
// { items : [
// {label: "label", content : "content"},
// ...
// ]}
String retVal = "";
try {
retVal = buildTripTreeData().toString();
} catch (JSONException ex) {
log("Exception building tree data" +
ex.getMessage());
}
return retVal;
}
public JSONObject buildTripTreeData()
throws JSONException {
JSONObject rootObject = new JSONObject();
JSONArray items = new JSONArray();
JSONObject itemObject = new JSONObject();
boolean hasNext = tripDataProvider.cursorFirst();
Integer currentPersonId =
(Integer) tripDataProvider.getValue(
"PERSON.PERSONID");
String currentName =
tripDataProvider.getValue(
"PERSON.NAME").toString();
StringBuffer currentContent = new StringBuffer();
while (hasNext) {
Integer newPersonId =
(Integer) tripDataProvider.getValue(
"PERSON.PERSONID");
if (!newPersonId.equals(currentPersonId)) {
// write out data for previous person
itemObject.put("label", currentName);
itemObject.put("content",
currentContent.toString());
items.put(itemObject);
// start gathering data for a new item
currentPersonId = newPersonId;
currentName =
tripDataProvider.getValue(
"PERSON.NAME").toString();
itemObject = new JSONObject();
currentContent = new StringBuffer();
}
// Add trip's date to the content
currentContent.append(tripDataProvider.getValue(
"TRIP.DEPDATE").toString() +
"<br>");
hasNext = tripDataProvider.cursorNext();
}
// write out data for last person
itemObject.put("label", currentName);
itemObject.put("content", currentContent.toString());
items.put(itemObject);
rootObject.put("items", items);
return rootObject;
}
|
Greg and Carla say that they have added some cool features to the accordion widget. I am hoping that as I learn about them, I can add to this mini-tutorial.