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.*" %>
<%@ page import="server.Company" %>
<%@ page import="javax.persistence.*" %>
<%
EntityManagerFactory emf = Persistence.createEntityManagerFactory("jmaki-jpaPU");
EntityManager em = emf.createEntityManager();
List<Company> list = em.createQuery("select c from Company c").getResultList();
out.println("{columns : [" +
"{ label : 'Company Name', id : 'companyName'}," +
"{ label :'Price', id : 'price'}," +
"{ label :'Change', id : 'change'}," +
"{ label :'% Change', id : 'pctChange'}," +
"{ label :'Last Updated', id : 'lastUpdated'}" +
"],");
out.println("rows: [");
for (int i=0; i<list.size(); i++) {
Company c = list.get(i);
out.print("{ companyName: '" + c.getCompanyname() + "'," +
"price: '" + c.getPrice() + "'," +
"change: '" + c.getChange() + "'," +
"pctChange: '" + c.getPercentchange() + "'," +
"lastUpdated: '" + c.getLastupdated() + "'}");
if (i < list.size()-1)
out.println(",");
else
out.println();
}
out.println("] }");
%> - The new generated code fragment in bullet 7.2 is now:
<a:widget name="yahoo.dataTable"
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
- 916 reads





