Dynamic Data in jMaki Widgets Using JPA - Updated for formal data models
Doris pointed out that one of my
earlier post is not working any more. That entry explained the steps to
create a Web application, deployed on
GlassFish V2, and contained a jMaki-wrapped
Yahoo Data Table widget pulling data from
JavaDB using the
JPA.
The main reason for this is because
jMaki data
models have evolved since I wrote the original entry and are now
formalized. Here is the delta from the
previous entry to make it working:
- Use the following code in bullet 6 instead:
<%@ page import="java.util.*" %><br>
<%@ page import="server.Company" %><br>
<%@ page import="javax.persistence.*" %><br>
<br>
<%<br>
EntityManagerFactory emf =
Persistence.createEntityManagerFactory("jmaki-jpaPU");<br>
EntityManager em = emf.createEntityManager();<br>
<br>
List<Company> list = em.createQuery("select c from Company
c").getResultList();<br>
<br>
out.println("{columns : [" +<br>
"{ label : 'Company Name', id : 'companyName'}," +<br>
"{ label :'Price', id : 'price'}," +<br>
"{ label :'Change', id : 'change'}," +<br>
"{ label :'% Change', id : 'pctChange'}," +<br>
"{ label :'Last Updated', id : 'lastUpdated'}" +<br>
"],");<br>
<br>
out.println("rows: [");<br>
for (int i=0; i<list.size(); i++) {<br>
Company c = list.get(i);<br>
out.print("{ companyName: '" + c.getCompanyname() + "'," +<br>
"price: '" + c.getPrice() + "'," + <br>
"change: '" + c.getChange() + "'," +<br>
"pctChange: '" + c.getPercentchange() + "'," +
<br>
"lastUpdated: '" + c.getLastupdated() + "'}");<br>
if (i < list.size()-1)<br>
out.println(",");<br>
else<br>
out.println();<br>
}<br>
out.println("] }");<br>
%> - The new generated code fragment in bullet 7.2 is now:
<a:widget name="yahoo.dataTable"<br>
service="data.jsp" />
With jMaki 0.9.7.1, here is a snapshot of the updated web page:

And the updated NetBeans project is available
here.
Technorati: jmaki
glassfish
jpa
netbeans
- Login or register to post comments
- Printer-friendly version
- arungupta's blog
- 991 reads





