Skip to main content

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

Posted by arungupta on August 27, 2007 at 8:49 PM PDT

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:



    &lt;%@ page import=&quot;java.util.*&quot; %&gt;<br>
    &lt;%@ page import=&quot;server.Company&quot; %&gt;<br>
    &lt;%@ page import=&quot;javax.persistence.*&quot; %&gt;<br>
    <br>
    &lt;%<br>
    &nbsp; EntityManagerFactory emf =
    Persistence.createEntityManagerFactory(&quot;jmaki-jpaPU&quot;);<br>
    &nbsp; EntityManager em = emf.createEntityManager();<br>
    <br>
    &nbsp; List&lt;Company&gt; list = em.createQuery(&quot;select c from Company
    c&quot;).getResultList();<br>
    <br>
    &nbsp; out.println(&quot;{columns : [&quot; +<br>
    &nbsp;&nbsp;&nbsp; &quot;{ label : 'Company Name', id : 'companyName'},&quot; +<br>
    &nbsp;&nbsp;&nbsp; &quot;{ label :'Price', id : 'price'},&quot; +<br>
    &nbsp;&nbsp;&nbsp; &quot;{ label :'Change', id : 'change'},&quot; +<br>
    &nbsp;&nbsp;&nbsp; &quot;{ label :'% Change', id : 'pctChange'},&quot; +<br>
    &nbsp;&nbsp;&nbsp; &quot;{ label :'Last Updated', id : 'lastUpdated'}&quot; +<br>
    &nbsp;&nbsp;&nbsp; &quot;],&quot;);<br>
    <br>
    &nbsp; out.println(&quot;rows: [&quot;);<br>
    &nbsp; for (int i=0; i&lt;list.size(); i++) {<br>
    &nbsp;&nbsp;&nbsp; Company c = list.get(i);<br>
    &nbsp;&nbsp;&nbsp; out.print(&quot;{ companyName: '&quot; + c.getCompanyname() + &quot;',&quot; +<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;price: '&quot; + c.getPrice() + &quot;',&quot; + <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;change: '&quot; + c.getChange() + &quot;',&quot; +<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;pctChange: '&quot; + c.getPercentchange() + &quot;',&quot; +
    <br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;lastUpdated: '&quot; + c.getLastupdated() + &quot;'}&quot;);<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (i &lt; list.size()-1)<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; out.println(&quot;,&quot;);<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else<br>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; out.println();<br>
    &nbsp; }<br>
    &nbsp; out.println(&quot;] }&quot;);<br>
    %&gt;
  2. The new generated code fragment in bullet 7.2 is now:



    &nbsp;&lt;a:widget name=&quot;yahoo.dataTable&quot;<br>
    &nbsp; service=&quot;data.jsp&quot; /&gt;

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

Related Topics >>