Miles to go …

August 28, 2007

Dynamic Data in jMaki Widgets Using JPA – Updated for formal data models

Filed under: web2.0 — arungupta @ 12:02 am

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

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot
Related posts:
  1. Dynamic Data in jMaki Widgets Using JPA
  2. TOTD #5: Loading data from beans in jMaki widgets
  3. TOTD #15: Delete/Update Row from Database using jMaki Data Table
  4. Hello JPA World!
  5. jMaki on Rails – Updated for NetBeans 6 M10

18 Comments »

  1. [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…

    Comment by Arun Gupta's Blog — August 28, 2007 @ 5:54 am

  2. [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…

    Comment by Arun Gupta's Blog — August 30, 2007 @ 6:21 am

  3. 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

    Comment by akash mohan — October 18, 2007 @ 3:44 am

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

    Comment by Arun Gupta — October 19, 2007 @ 4:30 pm

  5. [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…

    Comment by Arun Gupta's Blog — November 4, 2007 @ 3:44 pm

  6. 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

    Comment by Bill — December 12, 2007 @ 9:16 am

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

    Comment by Arun Gupta — December 12, 2007 @ 9:25 am

  8. 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

    Comment by Marco Azzalini — January 23, 2008 @ 3:43 am

  9. 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;

    Comment by yadi — March 26, 2008 @ 11:21 am

  10. help

    with the registration in the google maps

    so that I look at you in the
    google mpas

    Comment by leodany007 — April 17, 2008 @ 12:49 pm

  11. 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.

    Comment by Ioana Iacob — May 13, 2008 @ 5:35 am

  12. Arun,
    I am using a yahoo datatable. How can I format cells to show say checkbox or drop down list please.
    Many thanks
    Roy

    Comment by roy — September 9, 2008 @ 4:27 pm

  13. Roy, please post your question users@ajax.dev.java.net for a timely response.

    Comment by Arun Gupta — September 9, 2008 @ 5:01 pm

  14. Hello and THANKS for this blog, it really helped me a lot.

    I’ve got one question which I’ve been googling a lot, but I didn’t find what I was looking for.

    in a nutshell: how to ask a table widget just to refresh its data source?

    I got a dojo table feeded by service (mydata.jsp), which, also, gather data from a webservice.

    Is there a way to put a button which forces the dojo table to refresh itself from the provided service (mydata.jsp) ? I’d like to do that without having to reload entire page, and keeping favourite sortings selected by user.. (that means without destroying and recreating the widjet).

    any ideas?

    Thank you!

    Andrè

    Comment by Andrè — November 2, 2008 @ 1:21 pm

  15. gotcha. I finally made it, some information at http://javajumper.blogspot.com/2008/01/struts-and-jmaki-yahoodatatabledojotabl.html

    along with some of your VERY NICE screencasts I’ve been able to reload a table.. whoa. still on schedule! :-)

    Great job, without some of your screencast I wouldn’t be able to complete this task.

    Comment by Andrè — November 2, 2008 @ 4:55 pm

  16. Andre, please ask your question on users@ajax.dev.java.net for a quicker response.

    Comment by Arun Gupta — November 2, 2008 @ 8:00 pm

  17. Hello and THANKS for this blog, it really helped me a lot.

    I’ve got one question which I’ve been googling a lot, but I didn’t find what I was looking for.

    in a nutshell: how to ask a table widget just to refresh its data source?

    Comment by LAPTOP BATTERY — November 26, 2008 @ 9:01 pm

  18. This only works for me if I use:

    <a:widget name="yahoo.dataTable"
    service="./data.jsp" />

    It doesn’t work for me without the "./" before the "data.jsp"

    I am using GlassFish V2.

    Comment by Dom — June 3, 2009 @ 9:26 am

RSS feed for comments on this post. TrackBack URL

Leave a comment

The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.
Powered by WordPress