Miles to go ...

Arun Gupta is a Technology Evangelist for Web Services and Web 2.0 Apps at Sun. He was the spec lead for APIs in the Java platform, committer in multiple Open Source projects, participated in standard bodies and contributed to Java EE and SE releases.
« ActiveRecord-JDBC... | Main | Excel using WSIT -... »

http://blogs.sun.com/arungupta/date/20070828 Tuesday August 28, 2007

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:

  1. 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("] }");
    %>
  2. 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

del.icio.us | furl | simpy | slashdot | technorati | digg
Comments:

[Trackback] 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, that contained a jMaki-wrapped Yahoo Data Table widget pulling data from JavaDB...

Posted by Arun Gupta's Blog on August 28, 2007 at 05:54 AM PDT #

[Trackback] The jMaki tutorial from SWDP explained the different approaches to load your own data into a jMaki widget. The jMaki widget models have formalized since then and so the code there no longer works. This TOTD explains how a combo...

Posted by Arun Gupta's Blog on August 30, 2007 at 06:21 AM PDT #

[Trackback] The first ever The Rich Web Experience 2007 just got over and I enjoyed participating in the conference. This conference is part of No Fluff Just Stuff Symposium series and truly lived up to it's name and these are...

Posted by Arun Gupta's Blog on September 08, 2007 at 07:08 PM PDT #

Hi arun,
I get an error when i run the jsp that contains <a:widget name="yahoo.dataTable"
service="data.jsp" />.

.it says Data format error loading data from http://localhost:8084/PMS/data.jsp

iam using tomcat apache 5.5
please help....
thanks in advance

Posted by akash mohan on October 18, 2007 at 03:44 AM PDT #

Akash, is there any error in the server-side logs ?

Posted by Arun Gupta on October 19, 2007 at 04:30 PM PDT #

[Trackback] A Previous Entry explained how a Data Table widget can be populated from a database using Java Persistence API (JPA). This TOTD extends that entry and explains how a selected row from the Data Table can be deleted from the...

Posted by Arun Gupta's Blog on November 04, 2007 at 03:44 PM PST #

Broken link. I'm trying to access the original article but get an error from the "earlier post" link whose shortcut value is:
http://blogs.sun.com/arungupta/entry/dynamic_data_in_jmaki_widgets

A dialog box is displayed saying, "There was a problem retrieving xml data: Not Found."

Regards,
Bill

Posted by Bill on December 12, 2007 at 09:16 AM PST #

Bill, I can click on the link you mentioned and view the page. Which exact page are you not able to view ?

Posted by Arun Gupta on December 12, 2007 at 09:25 AM PST #

Hi Arun, I have exactly the same problem of akash mohan (Data format error loading data from ...) and like him, I am also using Tomcat 5.5.
The data.jsp output is the following (yes, not exactly your example, but even simpler):

{columns : [ { label : 'Title', id : 'title'}, { label :'Author', id : 'author'}, { label : 'ISBN', id : 'isbn'}, { label : 'Description', id : 'description'} ], rows: [ {title :'La biologia delle Credenze',author:'B. Lipton',isbn:'1999-0952',description:'Genesi e sviluppo della nuova Epigenetica'} ] }

that seems correct. Tomcat logs have any entry relating this error
Have you any idea?
Thanks in advance
Marco Azzalini

Posted by Marco Azzalini on January 23, 2008 at 03:43 AM PST #

hi, how i add the link for rows , when user click by rows , goto link to id from database
for ex:in row one when user click goto
href= "result.jsp?id=1 "
row 2 click:"result.jsp?id=2 " and .....
thanks;

Posted by yadi on March 26, 2008 at 11:21 AM PDT #

help

with the registration in the google maps

so that I look at you in the
google mpas

Posted by leodany007 on April 17, 2008 at 12:49 PM PDT #

Hello, thank you very much for this tutorial, it was very helpful. I used an editable table. I'd like the changes I make to the table cells to be automatically made on the database. Any ideas on how? Thanks again.

Posted by Ioana Iacob on May 13, 2008 at 05:35 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
« ActiveRecord-JDBC... | Main | Excel using WSIT -... »

Valid HTML! Valid CSS!

This is a personal weblog, I do not speak for my employer.

--> ajax ajaxworld conf eclipse fitness gem glassfish glassfishday hyderabad india indigo interoperability javaone javaone2008 jax-ws jmaki jpa jruby mac marathon metro microsoft mysql netbeans phobos photography presos railsconf ruby rubyonrails running runninglog runsfm screencast siliconvalleymarathon sun suntechdays swdp tango theserverside totd training traveltips v3 vista wcf web2.0 webservices webtier windows wsaddressing wsit youtube
Locations of visitors to this page

calendar

« September 2008
SunMonTueWedThuFriSat
 
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    
       
Today
www.flickr.com
This is a Flickr badge showing public photos from ArunGupta. Make your own badge here.
Add to Technorati Favorites

Last 50