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:

    static java.util.List customers() {
        EntityManager entityManager
                = Persistence.createEntityManagerFactory("myPU").
        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:
            <h1>Sample Database</h1>
            <table border="1">
                <tbody data-bind="foreach: customers">
                        <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>

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. 


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

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.


« August 2015