JavaFX Script in a GlassFish app client - featuring persistence this time

This example implements a very simple address book.  And as with my earlier JavaFX script examples, I am sure the U/I itself could be done much better and my JavaFX script style probably could be better.  Even so, the sample shows what I wanted it to: that we can use a local persistence unit in an app client to retrieve and store information for display and modification using JavaFX script.

The application allows the user to manage contacts, each of which can have multiple addresses of the same or different types (e-mail, home phone, office phone, mobile). The app client uses the default GlassFish database.

Download the NetBeans project JAR and expand it into a directory and open it from NetBeans.  You will need to resolve the server reference to the GlassFish server you have defined to NetBeans.

Some interesting things to notice (interesting to me, anyway):

  1. There are three entity classes which use the persistence annotations to define the relationships among them.

  2. As with the earlier example, the main Java class in the app client provides some convenience methods that the JavaFX script uses.  This lets the app client container handle the persistence annotations automatically.

  3. This JavaFX script U/I relies heavily on binding between the U/I
    elements and data objects.  Bindings do not work well with Java objects
    (there are some
    mailing list postings about why).  So I've created JavaFX objects that
    shadow the persistence-annotated Java objects.  As part of retrieving the persistent Java objects using the main class convenience methods, the JavaFX script builds shadow objects each of which refers to
    its Java object counterpart.  As part of saving the user's changes to the data, the JavaFX script copies the current attribute values from the a JavaFX shadow object to its corresponding Java persistent object before asking the main Java class to persist the Java objects. 

    The JavaFX script U/I declarations bind to the attributes on the JavaFX shadow classes - which works fine. I did have to add the extra scripting to copy the values back and forth between the shadow JavaFX classes and the Java objects, but it wasn't too bad.  Ideally this would not be necessary or would be handled by a developer or graphic designer tool.

    Even in the absence of tool support for this, there might be a better way to deal with this, but this worked fairly quickly for my purposes so I went with it.

  4. Even though there is no real server component to this example, I build an EAR and put the app client inside it.  This allows me to package the JavaFX JARs in the EAR, which GlassFish makes available to the app client.  Otherwise I would have to put copies of the JavaFX JARs into the extension directory for the JRE on the client system (or make them available to the client in some other way).  This way, GlassFish takes care of everything at the cost of a bit larger EAR and app client JAR. 

If you want to try this example, download the NetBeans project above and the JavaFX JARs.  Unjar the NetBeans project on your system, then add your downloaded JavaFX JARs to the JavaFXJars directory in the unjarred NetBeans project.

Make sure you have started the Derby database using the asadmin start-database command.  Then deploy the EAR.  To run the client, you can either:

  1. Run the EAR (not the app client subproject) from NetBeans.
  2. Retrieve the app client JAR using the --retrieve option on the deploy
    command.  Then use the appclient command to launch the client.
  3. Launch the app client using Java Web Start.

You may see warnings about tables or rows already existing in the database if you redeploy the app.  This should not harm the functioning of the app.


hello, could you attach some screenshots or could you say that end effect is jfx integrated with web browser or just is separated window eg like some java web start app?

Posted by emstol on November 25, 2007 at 03:25 PM CST #

This does not depend on a web browser.

Using any of the three techniques for starting the client app, it is actually the script engine for JFX that opens a new window containing the U/I. So from the user's perspective a Java FX script behaves like a Swing application.

Posted by Tim Quinn on November 26, 2007 at 02:51 AM CST #

hi, i am trying to start this application but could not succeed can you please help me, when i use url on local host it says access denied and give me so many errors?? is any other way to run???? it is very intersting but only if i will be able to run

Posted by Arun Kumar on November 26, 2007 at 03:36 PM CST #

Hi, Arun.

It is hard to know what the problem is without more information. Fee free to send the error messages you are getting to tim DOT quinn AT sun DOT com and I will see if I can help.

Posted by Tim Quinn on November 27, 2007 at 05:53 AM CST #

Hi Tim,
I'm trying out your jfx example and I'm having a problem. I followed all steps but when the application starts, I get this: access denied ( /tmp/acc-20c880f1-14f3524652062/AddressBk-app-client_jar read)
I use a fresh install of NB6, jdk1.6.0_04, GF packaged with NB6. I'm not an expert in security and jws, I must be missing something.

Posted by Nicholas on February 10, 2008 at 09:36 PM CST #

Hi, NIcholas.

As the app client container (ACC) starts up, it must expand one of the downloaded JARs into the temp directory (as you on doubt noticed) and then read its contents.

Could it be that the protection settings on /tmp cause the created directory be guarded against reads?

- Tim

Posted by Tim Quinn on February 11, 2008 at 12:47 AM CST #

Hi Tim,

thanks for your answer. I checked the rights and everything looks good. I tried also on windows Vista on a fresh install and got the same result.

- Nicholas

Posted by Nicholas on February 11, 2008 at 01:47 AM CST #

This is strange. It seems to work just fine for me.

Tomorrow I will check a few other things, but it's not clear to me why it is not working for you.

- Tim

Posted by Tim Quinn on February 13, 2008 at 02:12 PM CST #

Nicholas via e-mail gave me a list of steps he was following to trigger the error - and of course they worked fine for me.

He and I are continuing this via e-mail.

Posted by Tim Quinn on February 14, 2008 at 08:14 AM CST #

Post a Comment:
  • HTML Syntax: NOT allowed

News and musings on the technology I work on at Oracle.

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


« July 2016