Meaningful HTML/Java DukeScript Framework Applications (Part 1)

In an effort to make a meaningful application on the DukeScript Framework, here's the start of a JPA-based CRUD app (right now, only R is supported):

There are three parts to this.

  1. Model. I generated JPA entity classes from my database. I ended up with the "Customer" class, which has relationships with "DiscountCode" and "MicroMarket". Then I added a new annotation, on top of all the JPA annotations, to the "Customer" class:
    @Model(className = "CustomerData", properties = {})

    Then, in the same class, i.e., in "Customer", I exposed the data as follows:

    @ComputedProperty
    static java.util.List customers() {
        EntityManager entityManager
                = Persistence.createEntityManagerFactory("myPU").
                createEntityManager();
        Query query = entityManager.createNamedQuery("Customer.findAll");
        return query.getResultList();
    }
  2. Controler. In the Main class, I changed "onPageLoad" to this:
    public static void onPageLoad(String... args) throws Exception {
        new CustomerData().applyBindings();
    }
  3. View. Finally, the "index.html" that is bound to the model is as follows:
    <html>
        <body>
            <h1>Sample Database</h1>
            <table border="1">
                <thead>
                    <tr>
                        <th>Name</th>
                        <th>City</th>
                        <th>State</th>
                        <th>Mail</th>
                    </tr>
                </thead>
                <tbody data-bind="foreach: customers">
                    <tr>
                        <td data-bind="text: $data.getName()"></td>
                        <td data-bind="text: $data.getCity()"></td>
                        <td data-bind="text: $data.getState()"></td>
                        <td data-bind="text: $data.getEmail()"></td>
                    </tr>
                </tbody>
            </table>
            <p>
        </body>
    </html>

Notice that the method "customers()" in the model is bound in the "foreach" in the view.

Probably I'm doing all kinds of things wrong. Probably I should be using properties in the model. Happy to be corrected. 

Comments:

Nice try, but needs few homey touches. I've sent you an improved version.

Posted by guest on April 23, 2014 at 12:52 AM PDT #

Hello, just wanted to ask. If this is converted to javascript? How does it connect to the Database? Does dukescript use NodeJS?

Posted by Jade on October 20, 2014 at 04:59 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« May 2015
SunMonTueWedThuFriSat
     
2
3
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