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

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 27, 2007 at 10:54 PM 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 29, 2007 at 11:21 PM 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 12: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 17, 2007 at 08:44 PM PDT #

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

Posted by Arun Gupta on October 19, 2007 at 09:30 AM 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 07:44 AM 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 01: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 01: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 22, 2008 at 07:43 PM 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 04: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 05:49 AM 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 12, 2008 at 10:35 PM PDT #

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

Posted by roy on September 09, 2008 at 09:27 AM PDT #

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

Posted by Arun Gupta on September 09, 2008 at 10:01 AM PDT #

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è

Posted by Andrè on November 02, 2008 at 05:21 AM PST #

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.

Posted by Andrè on November 02, 2008 at 08:55 AM PST #

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

Posted by Arun Gupta on November 02, 2008 at 12:00 PM PST #

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?

Posted by LAPTOP BATTERY on November 26, 2008 at 01:01 PM PST #

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.

Posted by Dom on June 03, 2009 at 02:26 AM PDT #

Post a Comment:
Comments are closed for this entry.
About

profile image
Arun Gupta is a technology enthusiast, a passionate runner, author, and a community guy who works for Oracle Corp.


Java EE 7 Samples

Stay Connected

Search

Archives
« July 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
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
31
  
       
Today