<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ObjectSource Blog - Because Expertise Matters &#187; JavaFX</title>
	<atom:link href="http://objectsource.com/blogs/category/javafx/feed/" rel="self" type="application/rss+xml" />
	<link>http://objectsource.com/blogs</link>
	<description>Objective Outsourcing Delivered</description>
	<lastBuildDate>Sun, 22 Aug 2010 07:43:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Understand FxContainer in 10 minutes</title>
		<link>http://objectsource.com/blogs/2010/08/understand-fxcontainer-in-10-minutes/</link>
		<comments>http://objectsource.com/blogs/2010/08/understand-fxcontainer-in-10-minutes/#comments</comments>
		<pubDate>Sun, 22 Aug 2010 07:27:44 +0000</pubDate>
		<dc:creator>Srikanth Shenoy</dc:creator>
				<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[FxContainer]]></category>
		<category><![CDATA[FxObjects]]></category>
		<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[JavaFX Dependency Injection]]></category>
		<category><![CDATA[JavaFX IoC Container]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://objectsource.com/blogs/?p=154</guid>
		<description><![CDATA[Its a fast lane world and I know it. That&#8217;s exactly why I have created a slidedeck with 20 slides to cover the FxContainer. You can read it in 10 minutes and start using FxContainer in your JavaFX applications. You can also download it here:  JavaFX Dependency Injection with FxContainer You can get additional (sometimes [...]]]></description>
			<content:encoded><![CDATA[<p>Its a fast lane world and I know it.</p>
<p>That&#8217;s exactly why I have created a slidedeck with 20 slides to cover the FxContainer. You can read it in 10 minutes and start using FxContainer in your JavaFX applications.</p>

<!-- GDE EMBED ERROR: retrieve error (:), use force="1" to bypass this check -->

<p>You can also download it here:  <a href="https://fxobjects.dev.java.net/files/documents/11182/152371/file_152371.dat/JavaFX%20Dependency%20Injection%20with%20FxContainer.pdf">JavaFX Dependency Injection with FxContainer</a></p>
<p>You can get additional (sometimes overlapping perspective from my earlier blog</p>
<p><a href="http://objectsource.com/blogs/2010/08/fxcontainer-the-ioc-container-built-using-javafx-and-for-javafx-applications/">http://objectsource.com/blogs/2010/08/fxcontainer-the-ioc-container-built-using-javafx-and-for-javafx-applications/</a> </p>
<p>or my &#8220;other blog&#8221; at java.net that has more details for the detail oriented folks</p>
<p><a href="http://weblogs.java.net/blog/srikanth/archive/2010/08/21/fxcontainer-ioc-container-written-javafx-javafx-applications">http://weblogs.java.net/blog/srikanth/archive/2010/08/21/fxcontainer-ioc-container-written-javafx-javafx-applications</a></p>
<p>Happy reading</p>
]]></content:encoded>
			<wfw:commentRss>http://objectsource.com/blogs/2010/08/understand-fxcontainer-in-10-minutes/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>FxContainer &#8211; The IoC Container built using JavaFX and for JavaFX Applications</title>
		<link>http://objectsource.com/blogs/2010/08/fxcontainer-the-ioc-container-built-using-javafx-and-for-javafx-applications/</link>
		<comments>http://objectsource.com/blogs/2010/08/fxcontainer-the-ioc-container-built-using-javafx-and-for-javafx-applications/#comments</comments>
		<pubDate>Sun, 22 Aug 2010 07:00:23 +0000</pubDate>
		<dc:creator>Srikanth Shenoy</dc:creator>
				<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[FxContainer]]></category>
		<category><![CDATA[FxObjects]]></category>
		<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[JavaFX Dependency Injection]]></category>
		<category><![CDATA[JavaFX IoC Container]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://objectsource.com/blogs/?p=148</guid>
		<description><![CDATA[I would like to announce the second gem from ObjectSource to the JavaFX Open Source Community &#8211; FxContainer (For those that you have been following, we contributed FxObjects Command-Event-Controller framework and are developing next version) Both projects can be accessed here: https://fxobjects.dev.java.net/ So what is FxContainer? FxContainer is the only IoC container that is built [...]]]></description>
			<content:encoded><![CDATA[<p>I would like to announce the second gem from ObjectSource to the JavaFX Open Source Community &#8211; FxContainer<br />
(For those that you have been following, we contributed FxObjects Command-Event-Controller framework and are developing next version)<br />
Both projects can be accessed here: <a href="https://fxobjects.dev.java.net/">https://fxobjects.dev.java.net/</a></p>
<h2>So what is FxContainer?</h2>
<p>FxContainer is the only IoC container that is built using JavaFX and specifically meant for JavaFX applications to provide Dependency Injection.<br />
But that is not its speciality really.</p>
<p>The world is already filled with dozens of IoC containers. Do we need another one? That is the question I pondered a lot before setting out to write a DI/IoC container in JavaFX</p>
<p>Writing a DI is fairly easy, but not completely trivial. So I looked at Spring, Guice and others as to how to apply them successfully for JavaFX</p>
<p>Spring supports XML and Annotation based Dependency Injection. Guice supports Annotation and binding &amp; provider API based DI. Both support Constructor and Setter Injection.</p>
<p>Unfortunately for us, JavaFX does not support Annotations. JavaFX also does not support constructor injection. So we are left with XML based setter injection.</p>
<p>However setter injection feels artificial for JavaFX programming style (where variables are initialized during allocation. Variables are generally declared public-init)</p>
<p>In addition, Setter Injection introduces atleast one known side effect that can cause certain type of JavaFX objects not to work correctly. (More details here: <a href="http://weblogs.java.net/blog/srikanth/archive/2010/06/12/wiring-javafx-objects-spring-tread-caution">http://weblogs.java.net/blog/srikanth/archive/2010/06/12/wiring-javafx-objects-spring-tread-caution</a>)</p>
<p>A minimal Spring DI requires 3-4 jars that can add up and exceed 1 MB. My aim is to have one DI solution for all platforms (dekstop, mobile etc. i.e if JavaFX becomes a reality in mobile. I know you have some doubts about that. Me too), lightweight, powerful, small footprint and easy to use.</p>
<p>FxContainer is exactly that.</p>
<h2>More details </h2>
<p>I will not repeat and bore you with details but you can read it up on my &#8220;other blog&#8221; at Java.net View it here and Vote for it if you like:</p>
<p><a href="http://www.dzone.com/links/fxcontainer_ioc_container_written_in_javafx_for_j.html">http://www.dzone.com/links/fxcontainer_ioc_container_written_in_javafx_for_j.html</a></p>
<p>And dont forget to provide feedback, ideas and contribute to the project on our discussion forum: <a href="https://fxobjects.dev.java.net/servlets/ProjectForumView">https://fxobjects.dev.java.net/servlets/ProjectForumView</a></p>
]]></content:encoded>
			<wfw:commentRss>http://objectsource.com/blogs/2010/08/fxcontainer-the-ioc-container-built-using-javafx-and-for-javafx-applications/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JavaFX Silver Partner</title>
		<link>http://objectsource.com/blogs/2010/08/javafx-silver-partner/</link>
		<comments>http://objectsource.com/blogs/2010/08/javafx-silver-partner/#comments</comments>
		<pubDate>Thu, 05 Aug 2010 13:59:50 +0000</pubDate>
		<dc:creator>Srikanth Shenoy</dc:creator>
				<category><![CDATA[FxObjects]]></category>
		<category><![CDATA[JavaFX]]></category>

		<guid isPermaLink="false">http://objectsource.com/blogs/?p=139</guid>
		<description><![CDATA[This is a short post and more of an announcement. I am extrmemely pleased to inform that ObjectSource has now achieved JavaFX Silver Partner status. JavaFX partner requirements are not very strict as it is still in infancy. However I feel that the silver partner status validates our commitment and contribution to JavaFX as a   [...]]]></description>
			<content:encoded><![CDATA[<p>This is a short post and more of an announcement.</p>
<p><strong>I am extrmemely pleased to inform that ObjectSource has now achieved JavaFX Silver Partner status.</strong></p>
<p>JavaFX partner requirements are not very strict as it is still in infancy.</p>
<p>However I feel that the silver partner status validates our commitment and contribution to JavaFX as a  </p>
<ol>
<li>JavaFX systems integrator</li>
<li>Application and Content developer</li>
<li>Significant contributor  to JavaFX open source projects and community</li>
</ol>
<p>This also reaffirms our commitment to JavaFX as a RIA platform.</p>
<p>We will continue to work towards eliminating FUD associated with JavaFX in the community. Needless to say we will continue to contribute to extend the horizons of JavaFX.</p>
<p><a href="http://objectsource.com/blogs/wp-content/uploads/2010/08/Javafx-logo.png"><img class="alignleft size-full wp-image-140" title="Javafx-logo" src="http://objectsource.com/blogs/wp-content/uploads/2010/08/Javafx-logo.png" alt="" width="148" height="78" /></a><a href="http://objectsource.com/blogs/wp-content/uploads/2010/08/b-409571-Silver_jewellery.jpg"><img class="alignleft size-medium wp-image-141" title="b-409571-Silver_jewellery" src="http://objectsource.com/blogs/wp-content/uploads/2010/08/b-409571-Silver_jewellery-300x287.jpg" alt="" width="158" height="78" /></a></p>
<p>This calls for a round of beer and then business as usual <img src='http://objectsource.com/blogs/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><a href="http://objectsource.com/blogs/wp-content/uploads/2010/08/ist2_5028735-glass-with-beer.jpg"><img class="alignleft size-medium wp-image-142" title="ist2_5028735-glass-with-beer" src="http://objectsource.com/blogs/wp-content/uploads/2010/08/ist2_5028735-glass-with-beer-300x249.jpg" alt="" width="150" height="61" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://objectsource.com/blogs/2010/08/javafx-silver-partner/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Understand FxObjects in 10 minutes</title>
		<link>http://objectsource.com/blogs/2010/07/understand-fxobjects-in-10-minutes/</link>
		<comments>http://objectsource.com/blogs/2010/07/understand-fxobjects-in-10-minutes/#comments</comments>
		<pubDate>Sat, 31 Jul 2010 17:47:03 +0000</pubDate>
		<dc:creator>Srikanth Shenoy</dc:creator>
				<category><![CDATA[FxObjects]]></category>
		<category><![CDATA[JavaFX]]></category>

		<guid isPermaLink="false">http://objectsource.com/blogs/?p=124</guid>
		<description><![CDATA[In a hurry ? No time to read the FxObjects user guide or go through the samples ? Not to worry. I have created a slidedeck with 25 slides to cover the FxObjects. You can read it in 10 minutes and get the overall picture pretty well. This approach works great if you are a [...]]]></description>
			<content:encoded><![CDATA[<p>In a hurry ? No time to read the FxObjects user guide or go through the samples ?</p>
<p>Not to worry. I have created a slidedeck with 25 slides to cover the FxObjects. You can read it in 10 minutes and get the overall picture pretty well.</p>
<p>This approach works great if you are a big picture guy and want to scratch the surface before delving in deeper.</p>
<p>Well, here it is:</p>

<!-- GDE EMBED ERROR: retrieve error (:), use force="1" to bypass this check -->

<p>You can also download it here:  <a title="Effective JavaFX Architecture with FxObjects in 10 minutes" href="https://fxobjects.dev.java.net/files/documents/11182/151936/file_151936.dat/Effective%20JavaFX%20Architecture%20with%20FxObjects.pdf">Effective JavaFX Architecture with FxObjects in 10 Minutes</a></p>
<p>Happy reading</p>
]]></content:encoded>
			<wfw:commentRss>http://objectsource.com/blogs/2010/07/understand-fxobjects-in-10-minutes/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>FxObjects 0.1 is released &#8211; Making JavaFX easy</title>
		<link>http://objectsource.com/blogs/2010/07/fxobjects-0-1-is-released/</link>
		<comments>http://objectsource.com/blogs/2010/07/fxobjects-0-1-is-released/#comments</comments>
		<pubDate>Fri, 30 Jul 2010 09:31:12 +0000</pubDate>
		<dc:creator>Srikanth Shenoy</dc:creator>
				<category><![CDATA[FxObjects]]></category>
		<category><![CDATA[JavaFX]]></category>

		<guid isPermaLink="false">http://objectsource.com/blogs/?p=116</guid>
		<description><![CDATA[I am extremely delighted to announce that FxObjects 0.1 is released on July 30. FxObjects is a open source Enterprise JavaFX Application Development framework. The whole intention of the framework is to make Enterprise JavaFX application development easy, elegant and fast. The 0.1 version provides powerful features JavaFX objects to XML round tripping a breeze [...]]]></description>
			<content:encoded><![CDATA[<p>I am extremely delighted to announce that FxObjects 0.1 is released on July 30.</p>
<p>FxObjects is a open source Enterprise JavaFX Application Development framework. The whole intention of the framework is to make Enterprise JavaFX application development easy, elegant and fast. The 0.1 version provides powerful features</p>
<ol>
<li>JavaFX objects to XML round tripping a breeze (zero code)</li>
<li>Makes asynchronous calls really easy</li>
<li>Consolidated commands for Http calls with option to plug in request and response builders, content processors and token based substitutable url templates and finally callbacks to update the UI.</li>
<li>Controller framework provides controller chain to organize your UI into pages and modules</li>
<li>Provides Model View Presenter implementation for the very first time in JavaFX to make your UI lean, mean and clean and easily testable with JUnit and jMock.</li>
</ol>
<p>0.1 release includes a 50 page user guide and 8 fully working samples demonstrating the usage of the framework.</p>
<p>There are big plans for 0.2 and hopefully more people would join and contribute.</p>
<p>Checkout the project: <a href="http://fxobjects.dev.java.net">http://fxobjects.dev.java.net</a></p>
<p>The framework is based on my series of blog posts on Enterprice and Effective JavaFX architecture at java.net -  <a href="http://weblogs.java.net/blog/srikanth">http://weblogs.java.net/blog/srikanth</a></p>
<p>In the last few weeks I have blogged about the rationale behind a few of these here. There is some overlap between the contents of the blog and the user guide, as the thoughts became blogs and crystallized into this framework and got refined into the user guide.</p>
<ul>
<li><a href="http://weblogs.java.net/blog/srikanth/archive/2010/07/01/effective-javafx-architecture-part-1">Effective JavaFX Architecture Part 1</a></li>
<li><a href="http://weblogs.java.net/blog/srikanth/archive/2010/07/07/effective-javafx-architecture-part-2-test-driven-development-tdd-ja">Effective JavaFX Architecture Part 2</a></li>
<li><a href="http://www.java.net/blog/srikanth/archive/2010/07/22/effective-javafx-architecture-part-3-asynchronous-calls-command-pat">Effective JavaFX Architecture Part 3</a></li>
</ul>
<p>When I did some large JavaFX project &#8211; about a year back, as I painfully recall, there were no patterns, principles or best practices for developing JavaFX applications. After serious introspection, analysis of our execution and a few more JavaFX projects it became clear to me that there was a gap to fill. FxObjects is now the end result of months of hard work from me and a dedicated team committed to making JavaFX application development easy, elegant and fast for all of us. </p>
<p>It seems to be part reality and part fashion to rule out JavaFX once in a while. Give JavaFX a try. Combine JavaFX with JFxtras UI controls library (<a href="http://jfxtras.org">http://jfxtras.org</a>)  and FxObjects application development framework (<a href="https://fxobjects.dev.java.net">https://fxobjects.dev.java.net</a>) to architect and develop applications that are beautiful inside-out</p>
<p>Enjoy and code elegantly in JavaFX!!</p>
]]></content:encoded>
			<wfw:commentRss>http://objectsource.com/blogs/2010/07/fxobjects-0-1-is-released/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>JavaFX bind syntax &#8211; Too much hype?</title>
		<link>http://objectsource.com/blogs/2010/06/javafx-bind-syntax-too-much-hyp/</link>
		<comments>http://objectsource.com/blogs/2010/06/javafx-bind-syntax-too-much-hyp/#comments</comments>
		<pubDate>Mon, 21 Jun 2010 16:20:48 +0000</pubDate>
		<dc:creator>Srikanth Shenoy</dc:creator>
				<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[FxObjects]]></category>

		<guid isPermaLink="false">http://objectsource.com/blogs/?p=105</guid>
		<description><![CDATA[The possibilities with JavaFX bind are over-hyped. Use bind only in limited scenarios. There are a whole lot of cases where bind seems like a good idea at first, but read this blog post for the devil in the details.]]></description>
			<content:encoded><![CDATA[<p>This is a reproduction of my java.net blog &#8211; <a href="http://weblogs.java.net/blog/srikanth/archive/2010/06/21/javafx-bind-%E2%80%93-too-much-hype">http://weblogs.java.net/blog/srikanth/archive/2010/06/21/javafx-bind-%E2%80%93-too-much-hype</a></p>
<p>One cannot cruise through JavaFX land these days without hearing about JavaFX keywords “bind”, “inverse” and “on replace”.</p>
<p>In short, one could think of JavaFX bind as an Observer pattern at the language syntax level. It is one of the biggest “zing thing” purported about JavaFX in common literature. It has even been claimed that the JavaFX bind can be applied for declarative automatic data binding.</p>
<p>[What is data binding – In a typical application the data comes from a server. A common mechanism used in Swing based UI development is to automatically tie the data from the Java based model object to UI widgets. This mechanism is called Data Binding. JGoodies data binding is used frequently with Swing. Similarly SWT and JFace data binding is popular in Eclipse RCP world]</p>
<p>Having successfully used SWT/JFace data binding in the past, I was ecstatic about JavaFX providing language level bind support and decided to try it out in a real JavaFX project and found it is not all that great as hyped. [One would of course say – “Yes it has its limitations”. But what are those limitations exactly? Instead of hand waving, this blog examines them thoroughly]</p>
<p>Let’s start with the first and obviously a big limitation.</p>
<h2>Limitation 1: A JavaFX attribute cannot be bound to a Java attribute.</h2>
<p>A JavaFX attribute cannot be bound to a Java attribute. I understand there are underlying platform reasons for that, but regardless that’s a big limitation as far as I am concerned. A lot of JavaFX applications that I build are large corporate applications and my data always comes from the server as Java objects. I&#8217;d have loved to bind these Java objects to the JavaFX UI widgets &#8211; ideally bidirectional bind or at least a unidirectional bind. Both options dont work.</p>
<p>What makes this even more confusing is that the JavaFX compiler happily allows the unidirectional binding syntax, but does not work. However JavaFX compiler throws an explicit error that inverse binding with Java objects is not possible.</p>
<p>This compiles, but does not work</p>
<pre>var firstNameTextBox:TextBox = TextBox { text: bind empJavaObj.firstName }</pre>
<p>and this does not compile</p>
<pre>var firstNameTextBox:TextBox = TextBox { text: bind empJavaObj.firstName with inverse }</pre>
<p>One might think, “Hey. No problem – I will copy the data from the Java POJO (or a JPA Entity) sent by the server as a response my service call into a JavaFX presentation object. Something like this:</p>
<pre>var firstNameTextBox:TextBox = TextBox { text: bind empFxObj.firstName with inverse }</pre>
<p>where empFxObj is a JavaFX object representing a Employee. Well, you might be surprised that this also has its share of gotchas. That brings to me to the next limitation.</p>
<h2>Limitation 2: A JavaFX object must be a def for bidirectional binding to work</h2>
<p>def is sort of equivalent to Java’s final. Wow! Take a deep breath for the repercussions of this limitation to sink in. This implies that the UI widget attribute can be bound only to a constant JavaFX presentation data object. The memory reference of this JavaFX presentation data object cannot vary (but its attributes can vary). Well, for me, the whole point of data binding is to get data from the server as Java POJOs, construct a fresh JavaFX object and set it in the UI so that the data binding magic takes place. If the Java FX object has to be a constant, then all of bind effort is wasted (Remember folks – To reach this point, we have gone through the effort of copying data from the Java POJO into a JavaFX object – and this can be error prone effort especially when the returned dataset or object graph is large and involves conditional copying of data.)</p>
<h2>Workarounds for Limitation 2</h2>
<p>Having said that, there are two workarounds for this limitation and I did not like either. But I will mention them anyway.</p>
<h3>Option 1: Dispose the UI every time</h3>
<p>Since JavaFX expects the bound object to be a def, we can do this – On every invocation (or the end of it), we can throw away the UI itself and construct a fresh one. When the UI is newly constructed every time, the def is also a fresh one and so, the def is no longer a show stopper. So, if you had a controller that is listening to the UI button actions, it could simply access the def JavaFX object from the UI and make appropriate calls to the server to save the data and then construct a new UI with the freshly returned/constructed JavaFX object.</p>
<h3>Why I don’t like Option 1</h3>
<p>This works, but it works for simple scenarios. The whole reason one chooses JavaFX is because the UI is far more richer/complex than what can be done by traditional Web 1.0 or Web 2.0 AJAX/DOM manipulation (Very Rich Internet Applications – VRIA). This approach works like a charm for the Hello World application, but does not cut it for decently sized applications. When the UI and hence the scene graph is complex, disposing it on every server call is not a wise thing to do. [Unless of course one likes to develop slow and non-responsive application with JVM constantly garbage collecting and CPU cycles wasted in constructing new scene graphs every time ? ]</p>
<h3>Option 2: Write some interesting code</h3>
<p>Here is the second work around. I will show you the code snippet for the UI first.</p>
<p>Listing 1</p>
<pre>public class VeryComplexUINode extends CustomNode {</pre>
<pre>var currentModel:FxEmployee on replace {</pre>
<pre>    boundModel.firstName = currentModel.firstName;</pre>
<pre>    boundModel.lastName = currentModel.lastName;</pre>
<pre>}</pre>
<pre>    def boundModel:FxEmployee = FxEmployee { lastName: ""; };</pre>
<pre>    def lastNameTxtBox:TextBox = TextBox { text: bind boundModel.lastName with inverse };</pre>
<pre>}</pre>
<p>The VeryComplexUINode is my simplification of indeed a very complex UI node. Only one textbox is shown to illustrate the work around. Notice that the node maintains two instances of model objects. One is the boundModel and the other one is currentModel. Whenever the controller gets new data from server and creates a new JavaFX presentation object, it will set the currentModel on this node. The currentModel has an onReplace block that faithfully copies data into the boundModel. When data makes it to the boundModel, voila the UI widgets also show the latest data.</p>
<h3>Why I don’t like Option 2</h3>
<p>To get the JavaFX bind working, we have coded the following</p>
<ol>
<li>We copied data from the Java model object into a JavaFX presentation model object</li>
<li>We then again copied data from the JavaFX presentation object into another</li>
</ol>
<p>I can already hear you say: “Wait a minute!! I am jumping through hoops here to get the bidirectional syntax work. Wasn’t the goal of data binding is to prevent this kind of coding anyway?” My point exactly.</p>
<p>If I am copying the data from one object to another and so on just to get JavaFX bind syntax working in my scenario, I would rather not do it. Instead I would directly set the UI data manually from the Java model objects into the UI widgets.</p>
<h2>Limitation 3: bind with inverse cannot work with expressions</h2>
<p>Consider a case when the data to be set is based on a condition as shown below</p>
<pre>var firstNameTextBox:TextBox = TextBox {</pre>
<pre>    text: bind if (empFxObj.lastName == null) "N/A" else empFxObj.lastName with inverse;</pre>
<pre>}</pre>
<p>But guess what? You are not allowed to do that. Bidirectional binding don’t allow expressions. Again, I understand why it is disllowed, but this is a minor irritation while building business applications, as objects from one tier to another don’t map plain-vanilla. A transformation of data between tiers is always in the cards. [You might be wondering – why in the world would anybody not have a last name. Certain cultures don’t have last names. Closer to home, “The Artist formerly known as Prince” does not have a last name!].</p>
<p><strong>NOTE: </strong></p>
<ol>
<li>Followers of “Presentation Model is redundant v/s necessary” discussion might say that – “Hey the presentation model needs to be dumb and the transformation code needs to reside in domain to presentation model mapping tier”. You are right, this code should reside in the mapping tier, but the above code is meant to illustrate the JavaFX limitation &#8211; not a showstopper, but a nice to know limitation</li>
<li>There is at least one case where a JavaFX presentation model is suitable. In JFxtras libraries, The XTableVIew component can only be bound to a JavaFX object. That bound JavaFX object has to extend a predefined XObject class.</li>
</ol>
<h2>Design choice: Using bind as alternative for loosely coupled Event Listeners</h2>
<p>Now, some of you might have thought about a lot of uses for the bind syntax and I am one of them. I even thought I don’t have to write event listeners, change listeners in my system and just use bind. Well a deeper thought proved how wrong I was – The primary fact about JavaFX bind is that you know whom you are binding to. That results in a tight coupling between the source and listener. This is not an issue if the listener and source are in a same UI. There is nothing wrong about it. (In fact this is the only case where using JavaFX bind saves additional coding and is an elegant way to do things).</p>
<p>If you are trying to mimic an event bus sort of thing (for instance enabling the copy icon when text is selected somewhere in the UI). It can be theoretically achieved, but the code will not be pretty.</p>
<h2>Summary</h2>
<p>The possibilities with JavaFX bind are over-hyped. However use bind only in limited scenarios (Not many as you saw above). There are a whole lot of cases where bind seems like a good idea at first, but read this blog post for the devils in the details. The whole point of this blog post is to convince you to bid good bye to data binding in your JavaFX UI architecture using the bind syntax (at least for now and foreseeable future). It is a slippery slope that will lead you pointless customizations of your UI objects, plugging in PropertyChangeListeners in JavaFX, forcing you to invent one hack after another to support your one-off cases and duct-taping your application to prevent it from falling apart.</p>
<p>I recommend that you do yourself a favor and forget data binding in your application using the JavaFX bind syntax.</p>
]]></content:encoded>
			<wfw:commentRss>http://objectsource.com/blogs/2010/06/javafx-bind-syntax-too-much-hyp/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>JavaFX and Spring &#8211; A very good match, but there is a little catch</title>
		<link>http://objectsource.com/blogs/2010/06/javafx-and-spring-a-good-match-but-there-is-a-little-catch/</link>
		<comments>http://objectsource.com/blogs/2010/06/javafx-and-spring-a-good-match-but-there-is-a-little-catch/#comments</comments>
		<pubDate>Tue, 15 Jun 2010 16:53:25 +0000</pubDate>
		<dc:creator>Srikanth Shenoy</dc:creator>
				<category><![CDATA[JavaFX]]></category>
		<category><![CDATA[FxObjects]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://objectsource.com/blogs/?p=93</guid>
		<description><![CDATA[This blog entry is a reproduction of my June 12, 2010 blog entry at java.net with slight modifications for readability. You can access the original post at:  http://weblogs.java.net/blog/srikanth/archive/2010/06/12/wiring-javafx-objects-spring-tread-caution I like Spring framework. Who doesn&#8217;t? (Well some don&#8217;t. But anyway, that’s not the point). I wanted to see if I could combine the both to see if [...]]]></description>
			<content:encoded><![CDATA[<p>This blog entry is a reproduction of my June 12, 2010 blog entry at java.net with slight modifications for readability. You can access the original post at:  <a href="http://weblogs.java.net/blog/srikanth/archive/2010/06/12/wiring-javafx-objects-spring-tread-caution">http://weblogs.java.net/blog/srikanth/archive/2010/06/12/wiring-javafx-objects-spring-tread-caution</a></p>
<p>I like Spring framework. Who doesn&#8217;t? (Well some don&#8217;t. But anyway, that’s not the point). I wanted to see if I could combine the both to see if it is a match made in heaven. In other words, I attempted to see if I could wire JavaFX components using Spring. After trying a couple of scenarios, I found at least one scenario, where this may not work as expected. Here are the details:</p>
<p>I started with bare basics of using JavaFX with Spring first. Look at the code in Listing 1 for wiring a simple JavaFX class using Spring.</p>
<p>Listing 1.</p>
<pre>&lt;bean id="myfxobj"&gt;
  &lt;property name="variable1" value="Initial Value1"&gt;
  &lt;property name="variable2" value="Initial Value2"&gt;
&lt;/bean&gt;</pre>
<p>Needless to say that I cannot do constructor injection since there is no concept of constructor in JavaFX. So, my next resort is setter injection. It worked and Listing 2 below shows my JavaFX class.</p>
<p>Listing 2</p>
<pre>public class SomeJavaFXClass {

    public var variable1:String on replace {
        println("variable1 repacement called");
    }

    public-init var variable2:String on replace {
        println("variable2 repacement called");
    }

    init {
        println("init called");
    }

    postinit {
        println("postinit called");
    }

    public function setVariable1(s:String):Void {
        println("setVariable1 called");
        variable1 = s;
    }

    public function setVariable2(s:String):Void {
        println("setVariable2 called");
        variable2 = s;
    }
}</pre>
<p> Nothing outstanding, but here are the concessions I made (or slightly violated JavaFX principle)</p>
<ol>
<li>Generally it is not a norm to write setters in JavaFX. But nonetheless I wrote the setters on the JavaFX class.</li>
<li>Notice that variable2 is declared as public-init. In JavaFX it means, the variable should be initialized only when the object is created. By providing a setter injection, I am essentially violating that principle in theory. But it did not break anything.</li>
</ol>
<p>Emboldened by the initial success, I went a step further to wire the JavaFX UI itself with Spring (Normally, when I create Swing UIs, I like to wire the UIs itself in Swing). Listing 3 shows the wiring that I could do (but I did not do)</p>
<p>Listing 3</p>
<pre>&lt;bean id="uiNode"&gt;
  &lt;property name="variable1" value="Initial Value1"&gt;
  &lt;property name="variable2" value="Initial Value2"&gt;
&lt;/bean&gt;</pre>
<p>In JavaFX, as you know, CustomNode is the preferred base class for all custom UI. So, I create a subclass of CustomNode. Listing 4 shows this subclass. Pretty simple – nothing fancy. Amon other things, you will also notice the create() function. This is an abstract function in CustomNode. It has to be implemented by concrete subclasses of CustomNode. The create method is your passport to creating all the UI, so JavaFX runtime could use it when needed.</p>
<p>Listing 4</p>
<pre>public class MyNode extends CustomNode {

    public-init var variable1:String on replace {
        println("variable1 repacement called");
    }

    public var variable2:String on replace {
        println("variable2 repacement called");
    }

    init {
        println("init called");
    }

    postinit {
        println("postinit called");
    }

    public override function create() {
        println("create called");
        return HBox {
            content: [  Text { content: "Default Node" }  ]
        }

    }

    public function setVariable1(s:String):Void {
        println("setVariable1 called");
        variable1 = s;
    }

    public function setVariable2(s:String):Void {
        println("setVariable2 called");
        variable2 = s;
    }

}</pre>
<p> Instead of calling Spring, I used traditional JavaFX invocation to look at the order of invocation. as in Listing 5 i.e. by initializing the node in the traditional way .</p>
<p>Listing 5</p>
<pre>var myNode:MyNode = MyNode {
    variable1: "init blah1"
    variable2: "init blah2"
};

myNode.setVariable1("Later blah1");
myNode.setVariable2("Later blah2");

Stage {
    title: "Application title"
    width: 250
    height: 80
    scene: Scene {
        content: [ myNode ]
    }
}</pre>
<p>Listing below shows the output I got.</p>
<pre>variable1 repacement called
variable2 repacement called
create called
init called
postinit called
setVariable1 called
variable1 repacement called
setVariable2 called
variable2 repacement called</pre>
<p>See the output carefully. <strong>(This is the key take away from this blog). </strong></p>
<p><strong>Notice that create() gets implicitly called even before init(), postInit() and setters. That means if the UI creation logic in create() depended on the initialization of variables for some reason, then Spring setter injection results in bugs. </strong></p>
<p>Granted, UIs do not always depend on initialization variables, but there are enough cases where they do. In such cases, keep this gotcha in mind and tweak your implementation to rely on other mechanisms.</p>
<p>One such mechanism is to write a plain vanilla create and then bind the visibility of UI elements to the instance variables. These variables will be initialized in the very next step anyway.</p>
<p>This way, you keep an eye out for this Spring &#8220;gotcha&#8221; coding pattern in create() and quash the problem before it even occurs.</p>
<p>Happy JavaFx&#8217;ing with Spring</p>
]]></content:encoded>
			<wfw:commentRss>http://objectsource.com/blogs/2010/06/javafx-and-spring-a-good-match-but-there-is-a-little-catch/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>JavaFX Memory leak &#8211; Addendum</title>
		<link>http://objectsource.com/blogs/2010/02/javafx-memory-leak-addendum/</link>
		<comments>http://objectsource.com/blogs/2010/02/javafx-memory-leak-addendum/#comments</comments>
		<pubDate>Sat, 13 Feb 2010 15:50:57 +0000</pubDate>
		<dc:creator>Srikanth Shenoy</dc:creator>
				<category><![CDATA[JavaFX]]></category>

		<guid isPermaLink="false">http://objectsource.com/blogs/?p=31</guid>
		<description><![CDATA[I&#8217;ve observed that the JavaFX memory leak so clearly occuring on my machine is not reproducible on many other machines. On other machines &#8211; The memory usage keeps going up, some amount of memory can never be reclaimed. But there is nothing very conclusive as I saw on my own laptop. Perhaps there is memory [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve observed that the JavaFX memory leak so clearly occuring on my machine is not reproducible on many other machines.</p>
<p>On other machines &#8211; The memory usage keeps going up, some amount of memory can never be reclaimed. But there is nothing very conclusive as I saw on my own laptop. Perhaps there is memory leak.. perhaps there is not.. I dont know. I havent had time to check on this again. Just wanted to keep the readers of my blog informed</p>
]]></content:encoded>
			<wfw:commentRss>http://objectsource.com/blogs/2010/02/javafx-memory-leak-addendum/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Memory Leaks in JavaFX (?)</title>
		<link>http://objectsource.com/blogs/2009/11/memory-leaks-in-javafx/</link>
		<comments>http://objectsource.com/blogs/2009/11/memory-leaks-in-javafx/#comments</comments>
		<pubDate>Sat, 14 Nov 2009 06:23:33 +0000</pubDate>
		<dc:creator>Srikanth Shenoy</dc:creator>
				<category><![CDATA[JavaFX]]></category>

		<guid isPermaLink="false">http://objectsource.com/blogs/?p=10</guid>
		<description><![CDATA[I am a happy GWT and GXT user and have been using them building RIA for a while now. However, every once in a while, I have to embark on learning new technologies, venturing into uncharted territories simply because the project requirements demand it.  Once such uncharted territory (for me) was JavaFX. I had to [...]]]></description>
			<content:encoded><![CDATA[<p>I am a happy GWT and GXT user and have been using them building RIA for a while now. However, every once in a while, I have to embark on learning new technologies, venturing into uncharted territories simply because the project requirements demand it.  Once such uncharted territory (for me) was JavaFX. I had to do extensive image manipulation and I knew GWT would be a no go. And so, I started building with JavaFX (1.2), including the first few traditional web 2.0 UIs.</p>
<p><strong>And I noticed something weird along the way. Anytime I change a node bound to the Scene by creating a new node instance, the previously abandoned Node was not getting garbage collected at all, even when there were no references to it in my application. </strong></p>
<p>&#8220;That&#8217;s weird&#8221;, I thought. &#8220;I must be doing something wrong&#8221;. And I started paring down the UI until it was no more than a Stage, Scene and a custom node bound to Scene. And funny thing is that I saw the memory leak even then. Here is how my main code looks like:</p>
<pre>var myCustomNode:MyCustomNode = MyCustomNode{}</pre>
<pre>var newNodeImage = Image {
  url: "{__DIR__}folder-new.png"
  width: 50
  height: 50
}</pre>
<pre>var newNodeImageView = ImageView {
  x: 10
  y: 10
  image: newNodeImage
  onMouseClicked: function(e: MouseEvent): Void {
    myCustomNode = MyCustomNode{ };
  }
}</pre>
<pre>var appBody = VBox { content: [newNodeImageView, myCustomNode] };</pre>
<pre>Stage {
  title: "Memory Leak Demo"
  width: 800
  height: 200
  scene: Scene { content: bind appBody }
}</pre>
<p>The order of events is as follows:</p>
<ol>
<li>Everytime I click the ImageView, a new CustomNode instance is created.</li>
<li>This custom node is indirectly bound to the scene. (In fact, as I understand it, this is the only way of switching scenes in JavaFX.) And by the way, my Custom Node looks like this:</li>
</ol>
<pre>public class MyCustomNode extends CustomNode {

  //bunch of UI components defined here. A few text boxes, radio buttons nothing fancy

  override function create() {
    VBox {
      content: [
        HBox { content: [ ....] }
<pre>        HBox { content: [ ....] }
        ....
      ]
    }</pre>
<p>}</pre>
<pre>}</pre>
<p>As you can see, it is a pretty simple node. Nothing fancy.</p>
<p><strong>Here is the code for you to grab and try it out yourself: <a title="Main.fx" href="../wp-content/uploads/2009/11/Main.fx" target="_blank">Main.fx</a> <a title="MyCustomNode.fx" href="http://objectsource.com/blogs/wp-content/uploads/2009/11/MyCustomNode.fx" target="_blank"> MyCustomNode.fx</a></strong></p>
<p>When I ran this, I monitored using JConsole. Here is what I saw:</p>
<div id="attachment_16" class="wp-caption aligncenter" style="width: 700px"><img class="size-full wp-image-16" src="http://objectsource.com/blogs/wp-content/uploads/2009/11/2console5.jpg" alt="Memory status in JConsole" width="690" height="573" /><p class="wp-caption-text">Memory status in JConsole</p></div>
<p>The JConsole screenshot showing the memory usage is self explanatory.</p>
<ol>
<li>Every time I created a new CustomNode, the memory usage went up</li>
<li>Even when it reached the critical point, full GC never occurred to recollect all orphaned nodes.</li>
<li>Fair enoguh, to say that there is are loitering objects that never get garbage collected, as if somebody is holding on to them.</li>
<li>I believe it the JavaFX engine itself that builds complex internal graphs and holds on to previously bound variables. (I am not sure how I can prove it though)</li>
</ol>
<p>Then I did something interesting.</p>
<p>I removed all radio buttons and all instance variables from MyCustomNode.fx and retained only Texts (a whole lot of them, but only Texts) and ran the tests again.</p>
<p>Surprise Surprise! No Memory leaks this time.</p>
<p>This is the memory usage I saw:</p>
<div id="attachment_17" class="wp-caption aligncenter" style="width: 688px"><img class="size-full wp-image-17" src="http://objectsource.com/blogs/wp-content/uploads/2009/11/jconsole5.jpg" alt="Memory monitored in JConsole when CustomNode only had Text" width="678" height="537" /><p class="wp-caption-text">Memory monitored in JConsole when CustomNode only had Text</p></div>
<p>As you can see, when I used a Node with only Text{}, there was no memory leaks. The moment I introduced radio buttons into the node and made them instance variables, I began to see memory leaks.</p>
<p>There is always a chance that I might be doing something wrong, but seems unlikely since this is a simple example and almost all examples I saw for switching scene involved binding.</p>
<p><strong>Moral of the story:</strong></p>
<ol>
<li><strong>All switched scenes should be created once and retained in memory for the duration of the application. </strong></li>
<li><strong>All data populated into the scenes could be recycled but not the underlying nodes that make up the scenes</strong></li>
</ol>
<p>That seems very limiting for a new platform that aspires to be the ruler of Web 2.0 and Flash and Silverlight killer.</p>
<p><strong>Here is the code for you to grab and try it out yourself: <a title="Main.fx" href="../wp-content/uploads/2009/11/Main.fx" target="_blank">Main.fx</a> <a title="MyCustomNode.fx" href="../wp-content/uploads/2009/11/MyCustomNode.fx" target="_blank"> MyCustomNode.fx</a></strong></p>
<p><strong><br />
</strong></p>
<p>Cheers,</p>
<p>Srikanth Shenoy</p>
]]></content:encoded>
			<wfw:commentRss>http://objectsource.com/blogs/2009/11/memory-leaks-in-javafx/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

