Wednesday Sep 06, 2006
Wednesday Sep 06, 2006
Note: See Using jMaki 9.3 With the NetBeans Visual Web Pack or the Sun Java Studio Creator IDE for updated instructions on how to add jMaki to a project.
Jennifer Ball just published two new jMaki tutorials, which you can read about in her blog. One of the tutorials shows how to use jMaki in JavaServer Faces projects, and it completes the information that I needed to figure out how to integrate a jMaki widget in a page built using the Java Studio Creator IDE. In particular, how to bind to a bean property, how to save off the widget's values, and how to make managed bean methods available for the AJAX requests.
So, here is a mini-tutorial on how to use jMaki to add a dojo AJAX combo box to a JavaServer Faces web page.
jar xvf jMaki.war
command, or you can rename the file to have a .zip extension and unzip it.jmaki/resources/jmaki.js to creator-project-dir/web/resources.
jmaki/resources/dojo/combobox to creator-project-dir/web/resources/dojo/combobox.
/resources/libs/dojo directory
(not the whole dojo directory) to creator-project-dir/web/resources/libs/dojo/version.3.1.
jmaki/WEB-INF/lib/ajax-wrapper-comp.jar to creator-project-dir/web/WEB-INF/lib.
ajax-wraper-comp.jar
to the IDE's library manager. Then, you can easily add the jMaki library to
a project by right-clicking the Libraries node in the Projects window and
choosing Add Library. xmlns:a="http://java.sun.com/jmaki-jsf" to the top-level
<div> tag. a:ajax tag inside an f:verbatim
tag, as shown below. Note that the service attribute is referring to
ApplicationBean1. Later, you add the completeCountry() method
to the application bean to return the list of choices.value="#{ApplicationBean1.completeCountry}".
Once I get it figured out, I will post a new entry.
<?xml version="1.0" encoding="UTF-8"?>
<jsp:root version="1.2" xmlns:a="http://java.sun.com/jmaki-jsf"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:ui="http://www.sun.com/web/ui">
<jsp:directive.page contentType="text/html;charset=UTF-8"
pageEncoding="UTF-8"/>
<f:view>
<ui:page binding="#{Page1.page1}" id="page1">
<ui:html binding="#{Page1.html1}" id="html1">
<ui:head binding="#{Page1.head1}" id="head1">
<ui:link binding="#{Page1.link1}" id="link1"
url="/resources/stylesheet.css"/>
</ui:head>
<ui:body binding="#{Page1.body1}" id="body1"
style="-rave-layout: grid">
<ui:form binding="#{Page1.form1}" id="form1">
<ui:panelGroup binding="#{Page1.groupPanel1}"
id="groupPanel1"
style="position: absolute; left: 24px; top: 48px">
<f:verbatim>
<a:ajax id="cb1" name="dojo.combobox"
service="ApplicationBean1-completeCountry.ajax" />
</f:verbatim>
</ui:panelGroup>
</ui:form>
</ui:body>
</ui:html>
</ui:page>
</f:view>
</jsp:root>
|
AbstractApplicationBean and use
the Managed Beans node in the Projects window to make the class' properties
available in application scope.
private String[] countries =new String[] {
"Canada", "France", "Uganda", "Ukraine", "United States of America",
"United Kingdom", "Japan", "Korea", "Jamacia", "Thailand"
};
private String[] countryCodes =
new String[] {"CA", "FR", "UG", "UR", "USA", "UK", "JP",
"KR", "JA", "TH"
};
public void completeCountry(FacesContext context,
String[] args,AjaxResult result) {
result.setResponseType(AjaxResult.JSON);
result.append("[");
for (int loop=0; loop < countries.length; loop++){
result.append("[\"" + countries[loop] + "\",\""
+ countryCodes[loop] + "\" ]");
if (loop < countries.length -1) result.append(",");}
result.append("]");
}
|
private String country = "";
public String getCountry() {
return country;
}
public void setCountry(String country){
this.country = country;
}
|
value="#{SessionBean1.country}"
attribute to the ajax tag, as shown below.
<a:ajax id="cb1" name="dojo.combobox"
service="ApplicationBean1-completeCountry.ajax"
value="#{SessionBean1.country}"/>
|
onSubmit property
to jmaki.attributes.get('form1:cb1').saveState();.Go.Back.
Click the ... button for the component's url property, choose
Page1, and click OK.value attribute is bound
to the session bean's country property, the previously selected value is displayed.
To understand how the jMaki tags work, I highly recommend that you read both of Jennifer's tutorials.
Posted by Prasanth on September 13, 2006 at 02:40 AM PDT #
Posted by Diva#2 on September 13, 2006 at 07:14 AM PDT #
hi Divas ! I can't update table in SQL server 2k using CommitChanges(). Error found :
Number of conflicts while synchronizing: 1 SyncResolver.UPDATE_ROW_CONFLICT row 1 [sunm][SQLServer JDBC Driver][SQLServer]The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.
Can you help me in solving this problem?
p/s : with Bundled database server, update is no problem
Thanks in advance
Posted by nghialt on October 17, 2007 at 07:00 PM PDT #
Hi,
For questions not related to the blog entries, I suggest searching the Sun Java Studio Creator forum at http://forum.java.sun.com/forum.jspa?forumID=881 for sql server entries. As this is a problem stemming from the driver, you might want to also look at forums about your particular JDBC driver. The installation guide says JSC supports use with MySQL database server 4.1 and 5.0 with JDBC driver.
Posted by 192.18.43.225 on October 18, 2007 at 09:30 AM PDT #