The Source for Java Technology Collaboration

Home » java.net Forums » OpenJFX » JavaFX Script Language Discussion

Thread: need to pass a POJO (not a class) to existing javafx object, UPDATED2

Welcome, Guest Help
Login Login
Guest Settings Guest Settings
Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 0 Threads: [ Previous | Next ]
asdf_asdf

Posts: 15
need to pass a POJO (not a class) to existing javafx object, UPDATED2
Posted: Jul 5, 2008 4:03 AM
  Click to reply to this thread Reply

His,

in the main class i have instantiated a javafx object that prints out a table. that works, thanks to http://jfx.wikia.com/wiki/Programmatically_invoking_a_JavaFX_Script.

the task now is to pass to this table object that i have created and populated a POJO-model with the items to be displayed in the table.

hence the questions
1. how can from a java class a POJO be passed to javafx object?
2. how should this POJO be bound to the javafx table in order to reflect the changes that occur to the POJO (happens in the main method of the java class). I looked at http://jfx.wikia.com/wiki/Binding_to_a_POJO, but are there more examples?

many thanks

---------------
UPDATE 1
---------------


ok, i have progressed a little since the posting (thanks to http://jfx.wikia.com/wiki/Programmatically_invoking_a_JavaFX_Script and http://www.oreillynet.com/onjava/blog/2007/05/javafx_first_steps_hello_onjav_1.html). So far I have java class with method main that initializes a POJO model object. I than put this object in the script context the following way:

ClassLoader loader = Thread.currentThread().getContextClassLoader();
ScriptEngineManager manager = new ScriptEngineManager(loader);
JavaFXScriptEngine fxEngine = (JavaFXScriptEngine) manager.getEngineByExtension("fx");

Bindings bindings = fxEngine.createBindings();
bindings.put("JAVA_STOCK_MODELL:mystock.client.JavaStockModell",javaStockModell);

ScriptContext context = new SimpleScriptContext();
context.setBindings(bindings, ScriptContext.GLOBAL_SCOPE);
context.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
fxEngine.setContext(context);

and I can sysout it then from my script.fx as follows:

System.out.println("JAVA_STOCK_MODELL: {JAVA_STOCK_MODELL:<<mystock.client.JavaStockModell>>}");

Prints out the content of the object as expected.

!!! I found that ONLY calling JAVA_STOCK_MODELL:<<mystock.client.JavaStockModell>> this way, ie with <<>> and full "name:classname", would work.!!!

---------------
UPDATE 2
---------------

The trick with binding to POJO object's values from a JavaFX table did not work out. The problem is that when the values of the POJO are updated by an external java class, the updates are not being bound to the GUI element accordingly.

How we went around this could be interesting for some.
JavaFX creates a JavaFX-based Model that the values of a GUI are bound to. Then same script instantiates a POJO and passes the JavaFX model object to POJO. POJO does the job of updating the values of the JavaFX model (it does not care that it is a JavaFX object since that has implemented a java interface) and these new values successfully propagate to the GUI of the JavaFX script. The relationships are kind of sophisticated, but everything works as smoothly as it can =)

--------

My other question remains. Does anyone know how can JavaFX iterate through a HashMap of objects?

thanks

Message was edited by: asdf_asdf




 XML java.net RSS