<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>JDevZone</title>
	<atom:link href="http://jarzone.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://jarzone.wordpress.com</link>
	<description></description>
	<lastBuildDate>Fri, 22 Jan 2010 10:13:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='jarzone.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>JDevZone</title>
		<link>http://jarzone.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://jarzone.wordpress.com/osd.xml" title="JDevZone" />
	<atom:link rel='hub' href='http://jarzone.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Maintaining Your Value In the Software Industry</title>
		<link>http://jarzone.wordpress.com/2010/01/22/maintaining-your-value-in-the-software-industry/</link>
		<comments>http://jarzone.wordpress.com/2010/01/22/maintaining-your-value-in-the-software-industry/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 10:13:51 +0000</pubDate>
		<dc:creator>jarzone</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://jarzone.wordpress.com/?p=263</guid>
		<description><![CDATA[These days it can be tough to find the job you want as a software developer, either because the lack of opportunities out there, or facing huge competition in the process. In this article, I&#8217;d like to offer some tips that might help you to maintain your value as a software developer. All of these [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jarzone.wordpress.com&amp;blog=3156522&amp;post=263&amp;subd=jarzone&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>These days it can be tough to find the job you want as a software developer, either because the lack of opportunities out there, or facing huge competition in the process. In this article, I&#8217;d like to offer some tips that  might help you to maintain your value as a software developer.  All of these tips apply to those who are in current employment, or who are looking for a job. If you aren&#8217;t working right now, some of these points are essential: you don&#8217;t want it to appear as if you&#8217;ve lost interest in software when you&#8217;re not getting paid for it! Challenge Yourself  While you may think that you know all that you need to know, there&#8217;s no harm in expanding your experience and improving your CV by achieving some relevant certification.  Certification is a really effective way of learning new things and refreshing on the things you already know.  Java developers have huge certification options available through the Sun Java Certification exams. Starting off with the SCJP exam, you can choose the path that suits you, all the way to Enterprise Architect. Eclipse developers can earn RCP and OSGi certification through the Eclipse Training Alliance. Stay Educated  If certification isn&#8217;t an option for your technology, or you&#8217;ve done it all before, make sure that at the very least you stay educated. This can be as simple as buying a book, or doing an online tutorial. As well as keeping up to date on technologies that you use, it&#8217;s really rewarding to educate yourself in a new framework or technology. Once again, your CV gets a nice update and you&#8217;ll probably find ways to apply what you&#8217;ve learned in your current job.  Training course can be expensive, but if you can afford it &#8211; go for it. Make sure that you do a sufficient amount of research into the course to make sure it suits your needs and covers what you expect.   However,once you know the basics of software development, it&#8217;s easy to teach yourself.  There&#8217;s a lot of information available out there, and a large amount of the tools and IDEs that you need are probably free. Join A Community   If you have a local user group, or gathering of other technologists, why not try to go to the meetings once in a while? Maybe start up a local technology conference and work on your presentation skills.   If you&#8217;re out of work right now, joining an open source project can be of huge benefit. You get to work as a team with other people passionate about technology, and pick up new skills from them. More importantly, joining an open source project can fill that empty year in your CV, and show that you&#8217;ve kept your skills sharp.  Find Your Voice  Finally, starting up your own blog can really help your confidence. It&#8217;s never been easier to set up a blog, with so many providers available. Teaching can be the best way of learning &#8211; so as you write about the technologies, tools and frameworks that interest you, you&#8217;ll find that you have an even better understanding. Researching new topics for your blog can be really interesting too. The most rewarding part is when you find that you have an audience and people are interested in what you have to say.   I should point out here that we do have an MVB program here at DZone, which is a really effective way of getting traffic to your blog from the DZone platform.  The key point I&#8217;d like to make is that you should never stand still as a software developer &#8211; there&#8217;s always someone behind you who will pass you out. Have you any other tips to share on staying sharp?</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jarzone.wordpress.com/263/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jarzone.wordpress.com/263/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jarzone.wordpress.com/263/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jarzone.wordpress.com/263/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jarzone.wordpress.com/263/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jarzone.wordpress.com/263/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jarzone.wordpress.com/263/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jarzone.wordpress.com/263/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jarzone.wordpress.com/263/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jarzone.wordpress.com/263/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jarzone.wordpress.com/263/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jarzone.wordpress.com/263/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jarzone.wordpress.com/263/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jarzone.wordpress.com/263/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jarzone.wordpress.com&amp;blog=3156522&amp;post=263&amp;subd=jarzone&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jarzone.wordpress.com/2010/01/22/maintaining-your-value-in-the-software-industry/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<georss:point>6.011700 80.287862</georss:point>
		<geo:lat>6.011700</geo:lat>
		<geo:long>80.287862</geo:long>
		<media:content url="http://1.gravatar.com/avatar/16e5993227472808e5f16bc598927775?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jarzone</media:title>
		</media:content>
	</item>
		<item>
		<title>Tools ‹ JDevZone — WordPress</title>
		<link>http://jarzone.wordpress.com/2010/01/13/tools-%e2%80%b9-jdevzone-%e2%80%94-wordpress/</link>
		<comments>http://jarzone.wordpress.com/2010/01/13/tools-%e2%80%b9-jdevzone-%e2%80%94-wordpress/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 09:14:38 +0000</pubDate>
		<dc:creator>jarzone</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://jarzone.wordpress.com/?p=261</guid>
		<description><![CDATA[Tools ‹ JDevZone — WordPress.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jarzone.wordpress.com&amp;blog=3156522&amp;post=261&amp;subd=jarzone&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://jarzone.wordpress.com/wp-admin/tools.php">Tools ‹ JDevZone — WordPress</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jarzone.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jarzone.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jarzone.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jarzone.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jarzone.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jarzone.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jarzone.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jarzone.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jarzone.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jarzone.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jarzone.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jarzone.wordpress.com/261/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jarzone.wordpress.com/261/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jarzone.wordpress.com/261/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jarzone.wordpress.com&amp;blog=3156522&amp;post=261&amp;subd=jarzone&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jarzone.wordpress.com/2010/01/13/tools-%e2%80%b9-jdevzone-%e2%80%94-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/16e5993227472808e5f16bc598927775?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jarzone</media:title>
		</media:content>
	</item>
		<item>
		<title>Hibernate best practices</title>
		<link>http://jarzone.wordpress.com/2008/10/17/hibernate-best-practices/</link>
		<comments>http://jarzone.wordpress.com/2008/10/17/hibernate-best-practices/#comments</comments>
		<pubDate>Fri, 17 Oct 2008 05:06:44 +0000</pubDate>
		<dc:creator>jarzone</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Hibernate]]></category>

		<guid isPermaLink="false">http://jarzone.wordpress.com/?p=256</guid>
		<description><![CDATA[I have been on a very large enterprise project using hibernate for the persistence. Our data model is upwards of 200 objects. It is a clustered web application and thus requires high performance so we&#8217;ve implemented caching and have all our objects and relationship set to lazy load. The typical database interaction is lots of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jarzone.wordpress.com&amp;blog=3156522&amp;post=256&amp;subd=jarzone&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I have been on a very large enterprise project using hibernate for the persistence. Our data model is upwards of 200 objects. It is a clustered web application and thus requires high performance so we&#8217;ve implemented caching and have all our objects and relationship set to lazy load. The typical database interaction is lots of reads and few rights. The data of one user does not affect the data of another.</p>
<p>Here are some of my best practices which I would have loved to have had in place from the beginning. They would have saved a lot of time and reduced bugs&#8230;</p>
<p><strong>Use id based Equality</strong><br />
This is contrary to a lot of the typical recommendations but I don&#8217;t see a problem with it. It means that you have a working equality method without any further effort. Furthermore, you have a guaranteed equality, the same equality that the database uses. There are some issues with this when it comes to one-to-one relationships, but those can be resolved by adjusting the equals method. The other issue is that there are instances where there is no business based unique key.</p>
<p><strong>Don&#8217;t use auto generated Keys</strong><br />
So in your model classes set the id. This will mean you need another field as a persistence marker. The fundamental reason for this, coupled with the fact that you&#8217;re using the id for equals, is that you have immediate equality, both prior to persisting the object and in your tests. By using auto generated keys you you have to wait until the object is persisted before its equals method works. You cannot thus use it in a set prior to persistence, and when you run tests you have to manually set the id every time you create the object.</p>
<p><strong>Use instrumentation</strong><br />
Hibernate has an issue (a big issue IMHO) that if you execute the following code (Person is set to be Lazy loaded).<span style="font-family:Courier New;"></p>
<p></span> <span style="font-family:Courier New;">Person p = session.load(Person.class, id);<br />
ContactDetails cd = p.getContactDetails();</p>
<p><span style="font-family:sans-serif;">And on the database that particular object (contact details) is actually a subclass of ContactDetails called AddressDetails, the real type of the variable cd will be ContactDetails and _not_ Address Details as you would have expected. In order to get the real type you have to do first ask hibernate for the real type of the object and then call load again with that real type. So in order for the variable cd to be the correct type you would require the following code:</p>
<p></span></span> <span style="font-family:Courier New;">Person p = session.load(Person.class, id);</p>
<p>ContactDetails cd = p.getContactDetails();<br />
cd = (ContactDetails)load(id, Hibernate.getClass(cd));</p>
<p><span style="font-family:sans-serif;">An extra line is required.</p>
<p>Instrumentation however injects code into the compiled class of ContactDetails and intercepts the call to getContactDetails to add the bit to load the real type. It&#8217;s a small little ant job that runs within the context of our IDE and sorts it all out.</p>
<p><strong>Use Field access over method access</strong><br />
Unfortunately, I only discovered that hibernate had the ability to directly act on the fields rather than go via methods too late to make use of this ability. It would have enabled me to setup some nice validation and/or side effects on the setting of a value in a hibernate managed object. I&#8217;m sorry I didn&#8217;t do it earlier. This is a practice which I have thus not been able to test, it does sound like a good idea but maybe there are other issues I do not know about.</p>
<p><strong>Think hard about your Cascades</strong><br />
Hibernate is not good at saving a whole object tree in one go. The problem is that as soon as any sql is executed on the database, the sql is validated against the state of the database. So any constraint violations are immediately raised. If you think hard on the cascades the ability so save whole trees is significantly improved though it is not totally enabled. One obvious practice is that if it has a not-null constraint the cascade must be set. If this is not set unless you save the foreign object before the local one you will get a constraint violation. The objects go together (thus the not-null) so the cascade should be on.</p>
<p>The above recommendations are fairly generic to any project that uses hibernate in the real world. There&#8217;s a few that I&#8217;ve learnt on this project that are specific to a high performance and high concurrency web application&#8230;</p>
<p><strong>Prefer trawling the object model over running queries</strong><br />
The kind of application we have is one where a user would login and probably send on average 10 &#8211; 20 minutes on the web site. Thus we would typically have a lot of the objects they require in cache already. Thus when you need to find some data for the person concerned it is a lot better to simply trawl the objects rather than use a hibernate query. The reason for this is twofold..<br />
</span></span></p>
<ul>
<li>Querying in hibernate always causes a flush. Data is therefore written to the database at a time when it shouldn&#8217;t necessarily be. Even though you know the query does not touch any of the pending writes, the flush will still happen.</li>
<li>A data connection is made. On our application we gained significant performance concurrency improvements by removing queries &#8211; the objects were already in the cache in any case. Where we had deadlocks we simply removed the query from the equation (changed to trawling the model) and the deadlocks were significantly reduced.</li>
</ul>
<p><strong>Make everying lazy</strong><br />
On our application where isn&#8217;t a single relationship which is not lazy. We can&#8217;t think of a case where having lazy off would be useful to us. Yes, I understand that it means the first read will be slow, but after that it&#8217;ll be in the cache so it will be fast. If lazy is off even if the object is in the cache it will still load that object from the cache</p>
<p>In other words, if you have an object A which has a reference to object B and the reference is specified as non lazy. When you load A it will _always_ load B even if you don&#8217;t go near B. Even if B is in the cache it will still load B from the cache. On our application we have a lot of static data. This static data was initially set to be lazy disabled (prefetching). Then we would preload all this static data. We found that the preload was very slow &#8211; even though it was coming from the cache &#8211; because it would have to load the root object plus all the non lazy relationship stemming from that object.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jarzone.wordpress.com/256/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jarzone.wordpress.com/256/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jarzone.wordpress.com/256/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jarzone.wordpress.com/256/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jarzone.wordpress.com/256/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jarzone.wordpress.com/256/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jarzone.wordpress.com/256/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jarzone.wordpress.com/256/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jarzone.wordpress.com/256/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jarzone.wordpress.com/256/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jarzone.wordpress.com/256/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jarzone.wordpress.com/256/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jarzone.wordpress.com/256/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jarzone.wordpress.com/256/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jarzone.wordpress.com&amp;blog=3156522&amp;post=256&amp;subd=jarzone&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jarzone.wordpress.com/2008/10/17/hibernate-best-practices/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/16e5993227472808e5f16bc598927775?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jarzone</media:title>
		</media:content>
	</item>
		<item>
		<title>Never return Null Arrays!</title>
		<link>http://jarzone.wordpress.com/2008/10/16/never-return-null-arrays/</link>
		<comments>http://jarzone.wordpress.com/2008/10/16/never-return-null-arrays/#comments</comments>
		<pubDate>Thu, 16 Oct 2008 09:13:04 +0000</pubDate>
		<dc:creator>jarzone</dc:creator>
				<category><![CDATA[SW Development Best Practices]]></category>

		<guid isPermaLink="false">http://jarzone.wordpress.com/?p=254</guid>
		<description><![CDATA[Continuing on Jeanne’s theme of nulls, its a pet peeve of mine when I come across code that returns null arrays instead of empty arrays. The purpose of this post is to discuss some of the reasons why its a good practice to return empty arrays over null arrays, including Collection objects or typed array. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jarzone.wordpress.com&amp;blog=3156522&amp;post=254&amp;subd=jarzone&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Continuing on Jeanne’s theme of nulls, its a pet peeve of mine when I come across code that returns null arrays instead of empty arrays. The purpose of this post is to discuss some of the reasons why its a good practice to return empty arrays over null arrays, including Collection objects or typed array.</p>
<p><img src="http://www.selikoff.net/blog-files/NullPointerException.gif" alt="Null Pointer Exception" width="129" height="136" /><br />
Consider the reusability of the following code:</p>
<div class="codesnip-container">
<div class="codesnip"><span class="kw2">public</span> <a href="http://www.google.com/search?q=allinurl%3AList+java.sun.com&amp;bntl=1"><span class="kw3">List</span></a> getItems<span class="br0">(</span><span class="br0">)</span> <span class="br0">{</span><br />
…<br />
<span class="co1">// There are no items, return null</span><br />
<span class="kw2">return</span> <span class="kw2">null</span>;<br />
<span class="br0">}</span></div>
</div>
<p>Let’s say you want to iterate on the results, the following code would throw a NullPointerException if used in conjunction with the code above:</p>
<div class="codesnip-container">
<div class="codesnip"><a href="http://www.google.com/search?q=allinurl%3AList+java.sun.com&amp;bntl=1"><span class="kw3">List</span></a> items = getItems<span class="br0">(</span><span class="br0">)</span>;<br />
<span class="kw1">for</span><span class="br0">(</span><span class="kw4">int</span> i=<span class="nu0">0</span>; i&lt;items.<span class="me1">size</span><span class="br0">(</span><span class="br0">)</span>; i++<span class="br0">)</span> <span class="br0">{</span><br />
<span class="co1">// If there are no items, this code will throw a null pointer</span><br />
<span class="br0">}</span></div>
</div>
<p>Iterating on an array is one of the most commons practices in Java, so returning null instead of an empty array means the person is going to have to do extra null checks when they really don’t need to. In this situation, an empty array would suffice and would not produce any errors.</p>
<p>To summarize, it makes the code shorter, easier to read, and less likely to throw a NullPointerException. Also, there is some confusion with returning null since you may (or may not) be saying an empty array is the same thing as null. For example, the following would be confusing logic:</p>
<div class="codesnip-container">
<div class="codesnip"><a href="http://www.google.com/search?q=allinurl%3AList+java.sun.com&amp;bntl=1"><span class="kw3">List</span></a> items = getItems<span class="br0">(</span><span class="br0">)</span>;<br />
<span class="kw1">if</span><span class="br0">(</span>items == <span class="kw2">null</span><span class="br0">)</span> <span class="br0">{</span><br />
<span class="co1">// If null do one thing</span><br />
<span class="br0">}</span> <span class="kw1">else</span> <span class="kw1">if</span><span class="br0">(</span>items.<span class="me1">size</span>==<span class="nu0">0</span><span class="br0">)</span> <span class="br0">{</span><br />
<span class="co1">// If empty do another?</span><br />
<span class="br0">}</span></div>
</div>
<p>In this situation its not clear why you might act differently on the two return values and this can lead to confusing, ambiguous code.</p>
<p>The only time I might consider returning null valid is if there was an error of some kind, but then you should be throwing an exception (something more programmers are hesitant to do). Think of it like this, would you rather read a stack trace with a detailed error what went wrong in the code created by you, or would you rather see NullPointerException and wonder what of a dozen objects might have been null?</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jarzone.wordpress.com/254/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jarzone.wordpress.com/254/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jarzone.wordpress.com/254/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jarzone.wordpress.com/254/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jarzone.wordpress.com/254/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jarzone.wordpress.com/254/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jarzone.wordpress.com/254/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jarzone.wordpress.com/254/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jarzone.wordpress.com/254/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jarzone.wordpress.com/254/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jarzone.wordpress.com/254/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jarzone.wordpress.com/254/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jarzone.wordpress.com/254/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jarzone.wordpress.com/254/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jarzone.wordpress.com&amp;blog=3156522&amp;post=254&amp;subd=jarzone&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jarzone.wordpress.com/2008/10/16/never-return-null-arrays/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/16e5993227472808e5f16bc598927775?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jarzone</media:title>
		</media:content>

		<media:content url="http://www.selikoff.net/blog-files/NullPointerException.gif" medium="image">
			<media:title type="html">Null Pointer Exception</media:title>
		</media:content>
	</item>
		<item>
		<title>Using JSF and Flex Components Together</title>
		<link>http://jarzone.wordpress.com/2008/10/15/using-jsf-and-flex-components-together/</link>
		<comments>http://jarzone.wordpress.com/2008/10/15/using-jsf-and-flex-components-together/#comments</comments>
		<pubDate>Wed, 15 Oct 2008 03:32:09 +0000</pubDate>
		<dc:creator>jarzone</dc:creator>
				<category><![CDATA[Java Web Frame Work]]></category>
		<category><![CDATA[JSF]]></category>

		<guid isPermaLink="false">http://jarzone.wordpress.com/?p=252</guid>
		<description><![CDATA[Exadel Fiji extends JavaServer Faces (JSF) by allowing the use of Flex components within a JSF page. Fiji stands for “Flex and JSF Integration.” When using Fiji components, developers use Flex with the same component-based approach to building user interfaces that they are familiar with from JSF. This means that Flex components are bound to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jarzone.wordpress.com&amp;blog=3156522&amp;post=252&amp;subd=jarzone&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Exadel Fiji extends JavaServer Faces (JSF) by allowing the use of Flex components within a JSF page. Fiji stands for “Flex and JSF Integration.” When using Fiji components, developers use Flex with the same component-based approach to building user interfaces that they are familiar with from JSF. This means that Flex components are bound to standard JSF managed beans.</p>
<p>Fiji is a framework that provides the following:</p>
<ul>
<li>A library of ready-to-use Flex charting components for JSF</li>
<li>A universal wrapper that allows the use of any Flex component within a JSF page</li>
<li>Most importantly, with Fiji, you can bind Flex components to the same JSF-managed beans properties or methods (or Seam components or Spring beans) used by the rest of your JSF application.</li>
</ul>
<p>The current version ships with the following ready-to-use charts:</p>
<ul>
<li>Column chart</li>
<li>Stacked column chart</li>
<li>Bar chart</li>
<li>Stacked bar chart</li>
<li>Line chart</li>
</ul>
<p>For example, here is a screen shot of a Flex component inside a JSF page</p>
<p><span class="inline inline-undefined"><img class="image image-_original" src="http://java.dzone.com/sites/all/files/images/fiji1.jpg" alt="" width="341" height="398" /></span></p>
<p>You can see all Fiji components in action at <a href="http://livedemo.exadel.com/fiji-demo">http://livedemo.exadel.com/fiji-demo</a></p>
<p>Now that I have given you a short introduction to Fiji, you are probably wondering what problem Fiji is trying to solve. Let&#8217;s see.</p>
<h3>Why Fiji?</h3>
<p>Let&#8217;s start with the basics. JavaServer Faces (JSF) is a standard (Java EE) framework for building Web user interfaces out of components. Today, we are interested in building Rich Internet Applications, so RichFaces was created takes JSF a step further by allowing the easier building of AJAX-based applications in JSF. (In case you don&#8217;t know, <a href="http://richfaces.org/">RichFaces</a> offers a large number of ready-to-use AJAX components.)</p>
<p>While JSF has been constantly growing, one area where it&#8217;s still lacking is in displaying rich and interactive charts, graphs, and other similar visuals. Even with AJAX, any serious charting is extremely difficult, not to mention the testing that would be required for different browsers. It really comes down to two things. First, the technologies used behind JSF such as HTML, JavaScript, and CSS are not meant for displaying rich and interactive visual data (possible, but very difficult). Second, people have much higher expectations from a browser. The browser alone was never meant to display such visual data. It was primarily meant to display text and static images. So, in the end, it&#8217;s not really JSF’s fault, we are simply asking the underlying technologies (HTML, JavaScript, CSS, the browser) to do too much.</p>
<p>Of course, there is hope. We can use a Flash player to display rich and interactive charts.</p>
<h3>Adobe Flash</h3>
<p>With Flex, complex rich applications can be compiled and then run inside a Flash player. A Flash player is a virtual machine that installs as a plug-in into any browser. Because the application (built with Flex) is running inside a virtual machine, it provides a far more superior environment for rich and interactive charts and graphs than the browser alone (which just interprets HTML, JavaScript, etc.).</p>
<p>The obvious next question is: So, why not use Flex and JSF components together right now? While it&#8217;s possible to use Flex and JSF components inside the same page, the two technologies are not aware of each other. This means that JSF components are bound to JSF managed beans (or Seam components or Spring beans) while Flex is bound to completely different objects. This kind of integration is equivalent to inserting an image into a JSF page – in other words, not much integration.<br />
Back to Fiji</p>
<p>This is a good place to revisit Fiji. Fiji is the perfect fit for helping with the above problem. Not only does Fiji provide ready-to-use chart components and a universal wrapper to use any Flex component, but, with Fiji, you can bind Flex components to standard JSF managed beans. As a JSF developer, you just use the standard and the familiar JSF component-centric approach, while now also being able to use Flex components.</p>
<p>So, where does it make sense to use Fiji. One scenario is if you have an existing JSF application and you would like to insert richer content based on Flash while still using your existing model (JSF managed beans, Seam components or Spring beans). This content can be charts, graphs or any other rich content.</p>
<p>Another situation where Fiji would make sense is where you have an existing JSF application, but want to use a Flash-based user interface (instead of HTML/JavaScript). By using Fiji, you can still use the existing model part of your application.</p>
<p>However, to be honest, it wouldn&#8217;t make sense to use Fiji if you have an existing Flash-only application and are using a service like GraniteDS, BlazeDS, or Exadel Flamingo.</p>
<p>There are three basic steps to get started.</p>
<ol>
<li>Download project <a href="http://java.dzone.com/sites/all/files/fiji.zip">template</a></li>
<li>Download JAR file and add them to project template</li>
<li>Open the project in your favorite IDE</li>
</ol>
<h3>Download Project template</h3>
<p>Download and unzip the project template. &lt;link&gt;</p>
<h3>Download Fiji JAR files</h3>
<ol>
<li>Go to <a href="http://exadel.com/web/portal/fiji">http://exadel.com/web/portal/fiji</a> and click on Download to download Fiji distribution</li>
<li>Unzip the downloaded file</li>
<li>In the next step you are going to copy JAR files from lib folder to fiji/web/WEB-INF/lib directory<br />
1. If running Tomcat 5.5, copy all files<br />
2. If you are running Tomcat 6, copy all files except:<br />
¦ el-api.1.0.jar<br />
¦ el-impl-1.0.jar</li>
</ol>
<h3>Import Project</h3>
<p>Import the project into your favorite IDE. Here is how to do it in JBoss Tools (same steps for JBoss Developer Studio).</p>
<ol>
<li>Select File/Import</li>
<li>Select Other</li>
<li>Select JSF Project</li>
<li>Point to the web.xml file location in the project</li>
<li>Click Next</li>
<li>Keep all setting as they are (I&#8217;m assuming you have a server defined)</li>
<li>Click Finish</li>
</ol>
<p>To tell you the truth, installing Fiji is very simple. It&#8217;s basically a RichFaces project (has to be RichFaces version 3.2.2 or higher) plus the JAR files for Fiji:</p>
<ul>
<li>fiji-api-1.x.x.jar</li>
<li>fiji-ui-1.x.x.jar</li>
<li>flamingo-service-jsf-1.6.x.jar &#8211; to use HttpService via &lt;fiji:endpoint&gt; component. Covered later in article.</li>
</ul>
<p>Besides using HttpService, if you would like to use DataServices (AMF format), you need two additional JAR files:</p>
<ul>
<li>amf-serializer-1.6.x.jar</li>
</ul>
<p>That&#8217;s it. Nothing else is needed, not even changes to web.xml.</p>
<h3>Using Bar Chart</h3>
<p>Let&#8217;s start with a simple example using bar chart. The first step is to create the data for the chart. Because we can easily bind charts to JSF managed beans, that&#8217;s where we are going to create our data.</p>
<p>The Java bean looks like this:</p>
<div class="dp-highlighter">
<div class="bar">
<div class="tools"><a href="http://java.dzone.com/articles/using-jsf-and-flex-components-?page=0%2C1#">view plain</a><a href="http://java.dzone.com/articles/using-jsf-and-flex-components-?page=0%2C1#">copy to clipboard</a><a href="http://java.dzone.com/articles/using-jsf-and-flex-components-?page=0%2C1#">print</a><a href="http://java.dzone.com/articles/using-jsf-and-flex-components-?page=0%2C1#">?</a></div>
</div>
<ol class="dp-j">
<li class="alt"><span><span class="keyword">public</span><span> </span><span class="keyword">class</span><span> BarChartBean { </span></span></li>
<li><span> <span class="keyword">public</span><span> BarChartBean() { </span></span></li>
<li class="alt"><span> } </span></li>
<li><span> <span class="keyword">private</span><span> Integer[] data; </span></span></li>
<li class="alt"><span> </span></li>
<li><span> <span class="keyword">public</span><span> Integer[] getData() { </span></span></li>
<li class="alt"><span> <span class="keyword">return</span><span> data; </span></span></li>
<li><span> } </span></li>
<li class="alt"><span> <span class="annotation">@PostConstruct</span><span> </span></span></li>
<li><span> <span class="keyword">public</span><span> </span><span class="keyword">void</span><span> init () { </span></span></li>
<li class="alt"><span> data = <span class="keyword">new</span><span> Integer[</span><span class="number">5</span><span>]; </span></span></li>
<li><span> data[<span class="number">0</span><span>] = </span><span class="number">5</span><span>; </span></span></li>
<li class="alt"><span> data[<span class="number">1</span><span>] = </span><span class="number">2</span><span>; </span></span></li>
<li><span> data[<span class="number">2</span><span>] = -</span><span class="number">3</span><span>; </span></span></li>
<li class="alt"><span> data[<span class="number">3</span><span>] = </span><span class="number">10</span><span>; </span></span></li>
<li><span> data[<span class="number">4</span><span>] = </span><span class="number">9</span><span>; </span></span></li>
<li class="alt"><span> } </span></li>
<li><span>} </span></li>
</ol>
</div>
<pre class="java" style="display:none;">public class BarChartBean {
 public BarChartBean() {
 }
 private Integer[] data;

 public Integer[] getData() {
  return data;
 }
 @PostConstruct
 public void init () {
  data = new Integer[5];
  data[0] = 5;
  data[1] = 2;
  data[2] = -3;
  data[3] = 10;
  data[4] = 9;
 }
}</pre>
<p>To make it a JSF managed bean we need to register it in a JSF configuration file:</p>
<div class="dp-highlighter">
<div class="bar">
<div class="tools"><a href="http://java.dzone.com/articles/using-jsf-and-flex-components-?page=0%2C1#">view plain</a><a href="http://java.dzone.com/articles/using-jsf-and-flex-components-?page=0%2C1#">copy to clipboard</a><a href="http://java.dzone.com/articles/using-jsf-and-flex-components-?page=0%2C1#">print</a><a href="http://java.dzone.com/articles/using-jsf-and-flex-components-?page=0%2C1#">?</a></div>
</div>
<ol class="dp-xml">
<li class="alt"><span><span class="tag">&lt;</span><span class="tag-name">managed-bean</span><span class="tag">&gt;</span><span> </span></span></li>
<li><span> <span class="tag">&lt;</span><span class="tag-name">managed-bean-name</span><span class="tag">&gt;</span><span>barChartBean</span><span class="tag">&lt;/</span><span class="tag-name">managed-bean-name</span><span class="tag">&gt;</span><span> </span></span></li>
<li class="alt"><span> <span class="tag">&lt;</span><span class="tag-name">managed-bean-class</span><span class="tag">&gt;</span><span>fiji.BarChartBean</span><span class="tag">&lt;/</span><span class="tag-name">managed-bean-class</span><span class="tag">&gt;</span><span> </span></span></li>
<li><span> <span class="tag">&lt;</span><span class="tag-name">managed-bean-scope</span><span class="tag">&gt;</span><span>session</span><span class="tag">&lt;/</span><span class="tag-name">managed-bean-scope</span><span class="tag">&gt;</span><span> </span></span></li>
<li class="alt"><span> <span class="tag">&lt;/</span><span class="tag-name">managed-bean</span><span class="tag">&gt;</span><span> </span></span></li>
</ol>
</div>
<pre class="xml" style="display:none;">&lt;managed-bean&gt;
  &lt;managed-bean-name&gt;barChartBean&lt;/managed-bean-name&gt;
  &lt;managed-bean-class&gt;fiji.BarChartBean&lt;/managed-bean-class&gt;
  &lt;managed-bean-scope&gt;session&lt;/managed-bean-scope&gt;
 &lt;/managed-bean&gt;</pre>
<p>So far this is just basic JSF. Let&#8217;s now create the page.</p>
<p>Open start.xhtml. Look at the top, the page already contains a namespace for the Fiji tag library. Insert the following between &lt;body&gt; tags:</p>
<div class="dp-highlighter">
<div class="bar">
<div class="tools"><a href="http://java.dzone.com/articles/using-jsf-and-flex-components-?page=0%2C1#">view plain</a><a href="http://java.dzone.com/articles/using-jsf-and-flex-components-?page=0%2C1#">copy to clipboard</a><a href="http://java.dzone.com/articles/using-jsf-and-flex-components-?page=0%2C1#">print</a><a href="http://java.dzone.com/articles/using-jsf-and-flex-components-?page=0%2C1#">?</a></div>
</div>
<ol class="dp-xml">
<li class="alt"><span><span class="tag">&lt;</span><span class="tag-name">h:form</span><span class="tag">&gt;</span><span> </span></span></li>
<li><span> <span class="tag">&lt;</span><span class="tag-name">fiji:barChart</span><span> </span><span class="attribute">id</span><span>=</span><span class="attribute-value">&#8220;barChart&#8221;</span><span> </span><span class="attribute">value</span><span>=</span><span class="attribute-value">&#8220;#{barChartBean.data}&#8221;</span><span> </span></span></li>
<li class="alt"><span> <span class="attribute">title</span><span>=</span><span class="attribute-value">&#8220;Bar chart&#8221;</span><span> </span><span class="attribute">width</span><span>=</span><span class="attribute-value">&#8220;500&#8243;</span><span> </span><span class="attribute">height</span><span>=</span><span class="attribute-value">&#8220;300&#8243;</span><span class="tag">&gt;</span><span> </span></span></li>
<li><span> <span class="tag">&lt;</span><span class="tag-name">fiji:chartData</span><span> </span><span class="attribute">type</span><span>=</span><span class="attribute-value">&#8220;name&#8221;</span><span> </span><span class="attribute">value</span><span>=</span><span class="attribute-value">&#8220;Just some numbers&#8221;</span><span> </span><span class="tag">/&gt;</span><span> </span></span></li>
<li class="alt"><span> <span class="tag">&lt;/</span><span class="tag-name">fiji:barChart</span><span class="tag">&gt;</span><span> </span></span></li>
<li><span><span class="tag">&lt;/</span><span class="tag-name">h:form</span><span class="tag">&gt;</span><span> </span></span></li>
</ol>
</div>
<pre class="xml" style="display:none;">&lt;h:form&gt;
 &lt;fiji:barChart id="barChart" value="#{barChartBean.data}"
  title="Bar chart" width="500" height="300"&gt;
  &lt;fiji:chartData type="name" value="Just some numbers" /&gt;
 &lt;/fiji:barChart&gt;
&lt;/h:form&gt;</pre>
<p>&lt;fiji:barChart&gt; is just like a standard JSF component. The value attribute is bound to chart data inside the managed bean. &lt;fiji:chartData type=”name”..&gt; sets the chart name.</p>
<p>Save everything and run the page. You should get the following:</p>
<p><span class="inline inline-undefined"><img class="image image-_original" src="http://java.dzone.com/sites/all/files/images/fiji2.jpg" alt="" width="672" height="394" /></span></p>
<p>Let&#8217;s try another example, this time using column chart. I&#8217;m sure most of you still remember the Summer Olympics, so we&#8217;ll take the medal count and display it in the chart.</p>
<h3>Using the column chart</h3>
<p>You can reuse the same page or create a new page if you would like. If you create a new page, make sure to include the namespace for Fiji.</p>
<p>We are going to take the top three countries (USA, China, and Russia) and display their gold, silver and bronze medal count. As before, let&#8217;s start with data for the chart.<br />
The Java bean looks like this:</p>
<pre class="java">public class MedalsBean {
    private  Map&lt;String, Integer[]&gt; medalsData = new LinkedHashMap&lt;String,Integer[]&gt;();
    private  ArrayList&lt;String&gt; colors = new ArrayList&lt;String&gt;();
    private  ArrayList&lt;String&gt; names = new ArrayList&lt;String&gt;();

    private Integer[] medalsChina = new Integer[]{51, 21, 28};
    private Integer[] medalsUSA = new Integer[]{36, 38, 36};
    private Integer[] medalsRussia = new Integer[]{23, 21, 28};

    @PostConstruct
    private void init() {
    	medalsData.put("China", medalsChina);
    	medalsData.put("USA", medalsUSA);
    	medalsData.put("Russia", medalsRussia);

        names.add("Gold");
        names.add("Silver");
        names.add("Bronze");

        colors.add("#DAA520");
        colors.add("#C0C0C0");
        colors.add("#B87333");
    }

    public Map&lt;String, Integer[]&gt; getMedalsData() {
		return medalsData;
	}
	public ArrayList&lt;String&gt; getColors() {
		return colors;
	}
	public ArrayList&lt;String&gt; getNames() {
		return names;
	}
	public Integer[] getMedalsChina() {
		return medalsChina;
	}
	public Integer[] getMedalsUSA() {
		return medalsUSA;
	}
	public Integer[] getMedalsRussia() {
		return medalsRussia;
	}
}</pre>
<p>Because we now display three bars per country (one for each medal), we use a Map object and inside it put an array of integers representing the medal count.</p>
<p>To make it a JSF managed bean, we need to register is in a JSF configuration file:</p>
<pre class="xml">&lt;managed-bean&gt;
  &lt;managed-bean-name&gt;medalsBean&lt;/managed-bean-name&gt;
  &lt;managed-bean-class&gt;fiji.MedalsBean&lt;/managed-bean-class&gt;
  &lt;managed-bean-scope&gt;request&lt;/managed-bean-scope&gt;
 &lt;/managed-bean&gt;</pre>
<p>Now we are ready to build the page. The page is not much different than in the first example:</p>
<pre class="xml">&lt;h:form&gt;
&lt;fiji:columnChart id="goldMedals" value="#{medalsBean.medalsData}"
   legendPosition="top"
   barColors="#{medalsBean.colors}"
   width="250" height="300"&gt;
	&lt;fiji:chartData type="name" value="#{medalsBean.names}" /&gt;
&lt;/fiji:columnChart&gt;
&lt;/h:form&gt;</pre>
<p>Running the page will produce the following:</p>
<p><span class="inline inline-undefined"><img class="image image-_original" title="fiji3" src="http://java.dzone.com/sites/all/files/images/fiji3.jpg" alt="fiji3" width="339" height="404" /><span class="caption" style="width:337px;"><strong>fiji3</strong></span></span></p>
<p>While the integration with JSF is neat (we can easily use JSF managed beans as a data model for Flex components), we can even take it a step further. It&#8217;s possible to click on a Flex chart, send an AJAX request and do a partial page update. Let&#8217;s see how it&#8217;s done.</p>
<h3>Event handlers</h3>
<p>Fiji components have event handlers such as onitemclick which are very similar to the standard DHTML event handlers such as onkeyup. Going back to our example, let&#8217;s say we want to click on any bar and display the medal information outside the chart. When a bar is clicked, an AJAX request will be sent to the server, properties will be set, and then rerendered.</p>
<p>The changes to the managed bean are minimal. All we do is add three properties:</p>
<pre class="java">private String countrySelected;
private String medalTypeSelected;
private String medalCountSelected;

// getter and setters methods</pre>
<p>Don&#8217;t forget to generate getters and setters.</p>
<p>This is how our page now looks.</p>
<pre class="xml">&lt;h:form&gt;
&lt;fiji:columnChart id="goldMedals" value="#{medalsBean.medalsData}"
   legendPosition="top"
   barColors="#{medalsBean.colors}"
   width="250" height="300"&gt;
	&lt;fiji:chartData type="name" value="#{medalsBean.names}" /&gt;
             &lt;a4j:support event="onitemclick" reRender="info"&gt;
   	     &lt;a4j:actionparam name="param1" value="event.x"                         assignTo="#{medalsBean.countrySelected}" noEscape="true"/&gt;
		&lt;a4j:actionparam name="param2" value="event.y" assignTo="#{medalsBean.medalCountSelected}" noEscape="true"/&gt;
		&lt;a4j:actionparam name="param3" value="event.name" assignTo="#{medalsBean.medalTypeSelected}" noEscape="true"/&gt;
   	&lt;/a4j:support&gt;
&lt;/fiji:columnChart&gt;
&lt;/h:form&gt;

&lt;h:panelGrid id="info"&gt;
	&lt;h:outputText value="#{medalsBean2.countrySelected}"
			style="text-decoration: underline;"/&gt;
	&lt;h:outputText value="#{medalsBean2.medalTypeSelected}
				   #{medalsBean2.medalCountSelected}"/&gt;
&lt;/h:panelGrid&gt;</pre>
<p>We use the most popular tag from RichFaces, &lt;a4j:support&gt; to attach an event (onitemclick) to the parent component, &lt;fiji:columnChart&gt;. When a bar is clicked on a chart, an Ajax request is sent to the server passing three arguments defined by the &lt;a4j:actionparam&gt; tag. The &lt;a4j:actionparam&gt; tag automatically takes the value from value attribute and assigns it to property defined in the assignTo attribute. The following three arguments are passed:</p>
<p>event.x – is the x-axis data. In our case, it is the country name<br />
event.y – is the y-axis data. In our case, it is the medal count<br />
event.name – is the the active bar. In our case, it will be the medal type selected</p>
<p>I have also set noEscape=”true” for each &lt;a4j:actionparam&gt;. This is necessary in order for the value to be treated as JavaScript code instead of being enclosed in single quotes and just passed to the server as a parameter.</p>
<p>Finally, we rerender the information inside the panel grid. As you can see, we are using standard RichFaces techniques to send and rerender information even though we are mixing in Flex components.</p>
<p>Using the universal wrapper</p>
<p>So far I have shown you how to use charting components that ship with Fiji. Obviously you might want to use other, existing Flex components or maybe even build your own. To use any other Flex components, we use the universal wrapper or &lt;fiji:swf&gt; component.</p>
<p>We will use one of the charts provided by <a href="http://www.amcharts.com/">amCharts.com</a>.<br />
<em>Note:</em> We can use their charts for free. The only limitation is that a small URL will appear pointing to their Web site. I don&#8217;t think it&#8217;s such a limitation for such nice charts.</p>
<p>The SWF file for the chart as well as chart data are included in the template under web/ampie directory. You can also download them from here:</p>
<p>SWF file – ampie.swf &lt;link&gt;<br />
Settings file – ampie_settings.xml &lt;link&gt;<br />
Data file – ampie_data.xml &lt;link&gt;</p>
<p>The page looks like this:</p>
<div class="dp-highlighter">
<div class="bar">
<div class="tools"><a href="http://java.dzone.com/articles/using-jsf-and-flex-components-?page=0%2C4#">view plain</a><a href="http://java.dzone.com/articles/using-jsf-and-flex-components-?page=0%2C4#">copy to clipboard</a><a href="http://java.dzone.com/articles/using-jsf-and-flex-components-?page=0%2C4#">print</a><a href="http://java.dzone.com/articles/using-jsf-and-flex-components-?page=0%2C4#">?</a></div>
</div>
<ol class="dp-xml">
<li class="alt"><span><span class="tag">&lt;</span><span class="tag-name">fiji:swf</span><span> </span><span class="attribute">src</span><span>=</span><span class="attribute-value">&#8220;/ampie/ampie.swf&#8221;</span><span> </span><span class="attribute">bgcolor</span><span>=</span><span class="attribute-value">&#8220;#FFFFFF&#8221;</span><span> </span><span class="attribute">width</span><span>=</span><span class="attribute-value">&#8220;420&#8243;</span><span> </span><span class="attribute">height</span><span>=</span><span class="attribute-value">&#8220;300&#8243;</span><span class="tag">&gt;</span><span> </span></span></li>
<li><span> <span class="tag">&lt;</span><span class="tag-name">f:param</span><span> </span><span class="attribute">name</span><span>=</span><span class="attribute-value">&#8220;path&#8221;</span><span> </span><span class="attribute">value</span><span>=</span><span class="attribute-value">&#8220;/ampie&#8221;</span><span> </span><span class="tag">/&gt;</span><span> </span></span></li>
<li class="alt"><span> <span class="tag">&lt;</span><span class="tag-name">f:param</span><span> </span></span></li>
<li><span> <span class="attribute">name</span><span>=</span><span class="attribute-value">&#8220;settings_file&#8221;</span><span> </span></span></li>
<li class="alt"><span> <span class="attribute">value</span><span>=</span><span class="attribute-value">&#8220;#{facesContext.externalContext.requestContextPath}/ampie/ampie_settings.xml&#8221;</span><span> </span><span class="tag">/&gt;</span><span> </span></span></li>
<li><span> <span class="tag">&lt;</span><span class="tag-name">f:param</span><span> </span></span></li>
<li class="alt"><span> <span class="attribute">name</span><span>=</span><span class="attribute-value">&#8220;data_file&#8221;</span><span> </span></span></li>
<li><span> <span class="attribute">value</span><span>=</span><span class="attribute-value">&#8220;#{facesContext.externalContext.requestContextPath}/ampie/ampie_data.xml&#8221;</span><span> </span><span class="tag">/&gt;</span><span> </span></span></li>
<li class="alt"><span> <span class="tag">&lt;</span><span class="tag-name">f:param</span><span> </span><span class="attribute">name</span><span>=</span><span class="attribute-value">&#8220;preloader_color&#8221;</span><span> </span><span class="attribute">value</span><span>=</span><span class="attribute-value">&#8220;#999999&#8243;</span><span> </span><span class="tag">/&gt;</span><span> </span></span></li>
<li><span><span class="tag">&lt;/</span><span class="tag-name">fiji:swf</span><span class="tag">&gt;</span><span> </span></span></li>
</ol>
</div>
<pre class="xml" style="display:none;">&lt;fiji:swf src="/ampie/ampie.swf" bgcolor="#FFFFFF" width="420" height="300"&gt;
   &lt;f:param name="path" value="/ampie" /&gt;
   &lt;f:param
       name="settings_file"
       value="#{facesContext.externalContext.requestContextPath}/ampie/ampie_settings.xml" /&gt;
 &lt;f:param
     name="data_file"
     value="#{facesContext.externalContext.requestContextPath}/ampie/ampie_data.xml" /&gt;
 &lt;f:param name="preloader_color" value="#999999" /&gt;
&lt;/fiji:swf&gt;</pre>
<p>Using the src attribute of &lt;fiji:swf&gt;, we point to a Flash component. The Flash component can also be loaded as a resource by using src=“resource:///file.swf”. This particular Flash component (ampie.swf) requires some data. The data is being passed using the standard JSF attribute, &lt;f:param&gt;. When a Flash object is rendered on a page, it has a special flashVars attribute that provides arguments to the Flash module. In our case, the &lt;f:param&gt; tags with their information are rendered as flashVar arguments to the Flash component. This is how the charts gets its data.</p>
<p>Running the page will produce the following:</p>
<p><span class="inline inline-undefined"><img class="image image-_original" src="http://java.dzone.com/sites/all/files/images/fiji4.jpg" alt="" width="539" height="384" /></span></p>
<p>In case you need to update the data for the chart, one possible way is to rerender the Flash component using the standard RichFaces approach.</p>
<p>Using &lt;fiji:endpoint&gt;</p>
<p>As a final example, I&#8217;m going to show you how to use &lt;fiji:swf&gt; together with &lt;fiji:endPoint&gt;. This will allow us to send a parameter from a Flash component to a JSF managed bean.</p>
<p>Let&#8217;s start with the Flash part. This is the Flex application we want to use in our JSF page:</p>
<p>hello.mxml:</p>
<pre class="xml">&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"&gt;
	&lt;mx:Script&gt;
		&lt;![CDATA[
			import mx.rpc.events.ResultEvent;
			import mx.rpc.http.HTTPService;

			private var userRequest:HTTPService;

	private function send():void {
                userRequest = new HTTPService();
                userRequest.url = Application.application.parameters.fiji;
                userRequest.addEventListener("result", httpResult);
                var param:Object = {};
                param["hello"] = username.text;
                userRequest.send(param);
            }
            public function httpResult(event:ResultEvent):void {
                if (event.result) {
                    helloLabel.text = event.result.value;
                }
            }
		]]&gt;
	&lt;/mx:Script&gt;

	&lt;mx:Form x="22" y="10" width="280"&gt;
    	&lt;mx:Label id="helloLabel" styleName="text"
    		      text="{Application.application.parameters.text}" /&gt;
        &lt;mx:HBox&gt;
            &lt;mx:Label id="helloPerson" text="Username"/&gt;
            &lt;mx:TextInput id="username"/&gt;
        &lt;/mx:HBox&gt;
        &lt;mx:Button label="Submit" click="send()"/&gt;
    &lt;/mx:Form&gt;
&lt;/mx:Application&gt;</pre>
<p>It&#8217;s a pretty simple MXML file which you can compile either in Flex Builder or just from the command line after installing Flex SDK</p>
<blockquote><p>&gt;mxmlc hello.mxml</p></blockquote>
<p>I have also provided the SWF file inside the template (and here hello.swf &lt;link&gt;) in case you want to skip the compilation step.</p>
<p>The MXML file will produce the following:</p>
<p>[img_assist|nid=5017|title=|desc=|link=none|align=undefined|width=267|height=110]</p>
<p>Now, let&#8217;s look at the JSF page:</p>
<pre class="xml">&lt;h:form&gt;

	&lt;fiji:swf src="/hello.swf"

		bgcolor="#FFFFFF" width="350" height="200"&gt;

		&lt;f:param name="text" value="Hello Fiji World"/&gt;

		&lt;fiji:endpoint name="fiji"

			decoder="fiji.HelloDecoder"

			encoder="fiji.HelloEncoder"

			service="#{serviceBean.greeting}"/&gt;

&lt;/h:form&gt;</pre>
<p>&lt;fiji:swf&gt; is used to include the Flash component as we did before. The service attribute points to a JSF managed bean with a method called greeting:</p>
<pre class="java">public Object greeting(Object value){
		if(value != null){
			return "What's up, "+value+"?";
		} else {
			return "What's up, unknown?";
		}
	}</pre>
<p>It also has to be registered in a JSF configuration file:</p>
<pre class="xml">&lt;managed-bean&gt;
  &lt;managed-bean-name&gt;serviceBean&lt;/managed-bean-name&gt;
  &lt;managed-bean-class&gt;fiji.ServiceBean&lt;/managed-bean-class&gt;
  &lt;managed-bean-scope&gt;request&lt;/managed-bean-scope&gt;
 &lt;/managed-bean&gt;</pre>
<p>I will cover HelloDecoder and HelloEncoder later.</p>
<p>When running this page, we will get something very similar to the previous image; however, now it&#8217;s inside a JSF page and, if we enter a value for Username and click Submit, we will get the following.</p>
<p>[img_assist|nid=5018|title=|desc=|link=none|align=undefined|width=271|height=118]</p>
<p>The question is, how are we able to send a request to the JSF managed bean from the Flash component? It&#8217;s done via the &lt;fiji:endpoint&gt; component:</p>
<pre class="xml">&lt;fiji:endpoint name="fiji"

			decoder="com.exadel.fiji.demo.simple.HelloDecoder"

			encoder="com.exadel.fiji.demo.simple.HelloEncoder"

			service="#{serviceBean.greeting}"/&gt;</pre>
<p>We define an endpoint with the name of fiji. If you look back at the MXML file, we have the following:</p>
<pre class="java">private function send():void {
                userRequest = new HTTPService();
                userRequest.url = Application.application.parameters.fiji;
                userRequest.addEventListener("result", httpResult);
                var param:Object = {};
                param["hello"] = username.text;
                userRequest.send(param);
            }</pre>
<p>Inside the Flex component, the HTTP URL points to Application.application.parameters.fiji which in turn points to the Fiji endpoint defined in the JSF page by &lt;fiji:endpoint&gt; tag. When the Submit button inside the Flash is clicked, the URL is resolved. This is a standard JSF request and that&#8217;s how we invoke the serviceBean.greeting method inside a JSF managed bean. The URL is again passed via the flashVars attribute when the page is rendered.</p>
<p>Finally, the initial label value is set via</p>
<p>{Application.application.parameters.text}</p>
<p>Its value is set via this &lt;f:param&gt; tag:</p>
<pre class="xml">&lt;f:param name="text" value="Hello Fiji World"/&gt;</pre>
<h3>Decoders and Encoders</h3>
<p>First, why do we even need these decoders and encoders? Well, when using the Flex HttpService, the data is being sent to the server and returned in XML format. The JSF managed bean that we are using doesn&#8217;t know anything about XML. It simply returns a string value. So, in order to convert the request into a format that the managed bean understands, we use a decoder. When we invoke a method, the value returned has to be encoded in order for the Flash module to understand it. I know, it sounds complicated, but it&#8217;s really not.</p>
<p>The decoder shown below will be called by Fiji and the value returned will be passed to the greeting(Object) method inside a JSF managed bean. The decoder will just pull the value from the XML sent by the request.</p>
<p>public class HelloDecoder implements FlexDecoder , Serializable {</p>
<p>private static final String ENDPOINT_PARAM = &#8220;hello&#8221;;</p>
<p>public Object decodeRequest(FacesContext context, UIComponent component) {<br />
return context.getExternalContext().getRequestParameterMap().get(ENDPOINT_PARAM);<br />
}<br />
}</p>
<p>When the greeting(Object) method inside the JSF managed bean returns a value, this encoder will be called to convert the response back to XML format.</p>
<p>public class HelloEncoder implements FlexEncoder {</p>
<p>private static final String VALUE = &#8220;value&#8221;;</p>
<p>public void encodeObject(FacesContext context, UIComponent component,<br />
Object object) throws IOException {<br />
ResponseWriter responseWriter = context.getResponseWriter();<br />
responseWriter.startElement(VALUE, component);<br />
responseWriter.writeText(object, null);<br />
responseWriter.endElement(VALUE);</p>
<p>}<br />
}</p>
<p>You can implement different encode and decode methods in case your Flash module requires the XML request/response to be in a specific format.</p>
<p>Orginal URL : <a href="http://java.dzone.com/articles/using-jsf-and-flex-components-?page=0%2C0">http://java.dzone.com/articles/using-jsf-and-flex-components-?page=0%2C0</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jarzone.wordpress.com/252/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jarzone.wordpress.com/252/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jarzone.wordpress.com/252/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jarzone.wordpress.com/252/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jarzone.wordpress.com/252/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jarzone.wordpress.com/252/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jarzone.wordpress.com/252/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jarzone.wordpress.com/252/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jarzone.wordpress.com/252/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jarzone.wordpress.com/252/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jarzone.wordpress.com/252/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jarzone.wordpress.com/252/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jarzone.wordpress.com/252/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jarzone.wordpress.com/252/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jarzone.wordpress.com&amp;blog=3156522&amp;post=252&amp;subd=jarzone&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jarzone.wordpress.com/2008/10/15/using-jsf-and-flex-components-together/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/16e5993227472808e5f16bc598927775?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jarzone</media:title>
		</media:content>

		<media:content url="http://java.dzone.com/sites/all/files/images/fiji1.jpg" medium="image" />

		<media:content url="http://java.dzone.com/sites/all/files/images/fiji2.jpg" medium="image" />

		<media:content url="http://java.dzone.com/sites/all/files/images/fiji3.jpg" medium="image">
			<media:title type="html">fiji3</media:title>
		</media:content>

		<media:content url="http://java.dzone.com/sites/all/files/images/fiji4.jpg" medium="image" />
	</item>
		<item>
		<title>JSF 2.0 New Feature Preview Series (Part 2.3): Resources</title>
		<link>http://jarzone.wordpress.com/2008/10/10/jsf-20-new-feature-preview-series-part-23-resources/</link>
		<comments>http://jarzone.wordpress.com/2008/10/10/jsf-20-new-feature-preview-series-part-23-resources/#comments</comments>
		<pubDate>Fri, 10 Oct 2008 03:11:09 +0000</pubDate>
		<dc:creator>jarzone</dc:creator>
				<category><![CDATA[Java Web Frame Work]]></category>
		<category><![CDATA[JSF]]></category>

		<guid isPermaLink="false">http://jarzone.wordpress.com/?p=248</guid>
		<description><![CDATA[This is the fourth blog in the JSF 2.0 New Feature Preview Series. The previous entry covered the new resource API. This will be the last part of the Resources portion of this series and will cover leveraging the resource handling from the expression language. A resource can be reference via the EL using the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jarzone.wordpress.com&amp;blog=3156522&amp;post=248&amp;subd=jarzone&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is the fourth blog in the JSF 2.0 New Feature Preview Series. The <a href="http://blogs.sun.com/rlubke/entry/jsf_2_0_new_feature">previous entry</a> covered the new resource API. This will be the last part of the Resources portion of this series and will cover leveraging the resource handling from the expression language.</p>
<p>A resource can be reference via the EL using the following syntax:</p>
<div class="dp-highlighter">
<div class="bar">
<div class="tools"><a href="http://java.dzone.com/news/jsf-20-new-feature-preview-ser-2#">view plain</a><a href="http://java.dzone.com/news/jsf-20-new-feature-preview-ser-2#">copy to clipboard</a><a href="http://java.dzone.com/news/jsf-20-new-feature-preview-ser-2#">print</a><a href="http://java.dzone.com/news/jsf-20-new-feature-preview-ser-2#">?</a></div>
</div>
<ol class="dp-j">
<li class="alt"><span><span>#{resource[</span><span class="string">'&lt;resource name&gt;'</span><span>]} </span></span></li>
<li><span> </span></li>
<li class="alt"><span>OR </span></li>
<li><span> </span></li>
<li class="alt"><span>#{resource[<span class="string">'&lt;library name&gt;:&lt;resource name&gt;'</span><span>]} </span></span></li>
</ol>
</div>
<pre class="java" style="display:none;">#{resource['&lt;resource name&gt;']}

OR

#{resource['&lt;library name&gt;:&lt;resource name&gt;']}</pre>
<p>Where and are both literals that map to a resource within the application. If using Facelets, it would be possible to output the resource URL directly without using a component:</p>
<div class="dp-highlighter">
<div class="bar">
<div class="tools"><a href="http://java.dzone.com/news/jsf-20-new-feature-preview-ser-2#">view plain</a><a href="http://java.dzone.com/news/jsf-20-new-feature-preview-ser-2#">copy to clipboard</a><a href="http://java.dzone.com/news/jsf-20-new-feature-preview-ser-2#">print</a><a href="http://java.dzone.com/news/jsf-20-new-feature-preview-ser-2#">?</a></div>
</div>
<ol class="dp-xml">
<li class="alt"><span><span class="tag">&lt;</span><span class="tag-name">a</span><span> </span><span class="attribute">href</span><span>=</span><span class="attribute-value">&#8220;#{resource['header.jpg']}&#8221;</span><span> </span><span class="tag">/&gt;</span><span>; </span></span></li>
</ol>
</div>
<pre class="xml" style="display:none;">&lt;a href="#{resource['header.jpg']}" /&gt;;</pre>
<p>The resource expression can also be used in h:graphicImage:</p>
<div class="dp-highlighter">
<div class="bar">
<div class="tools"><a href="http://java.dzone.com/news/jsf-20-new-feature-preview-ser-2#">view plain</a><a href="http://java.dzone.com/news/jsf-20-new-feature-preview-ser-2#">copy to clipboard</a><a href="http://java.dzone.com/news/jsf-20-new-feature-preview-ser-2#">print</a><a href="http://java.dzone.com/news/jsf-20-new-feature-preview-ser-2#">?</a></div>
</div>
<ol class="dp-j">
<li class="alt"><span><span>&lt;h:graphicImage value=</span><span class="string">&#8220;#{resource['corp:header.jpg']}&#8221;</span><span> /&gt;; </span></span></li>
</ol>
</div>
<pre class="java" style="display:none;">&lt;h:graphicImage value="#{resource['corp:header.jpg']}" /&gt;;</pre>
<p>That said, I do think the EL expression syntax is somewhat limiting (due to limitations of the EL itself). Consider theming. An application could have several themes partitioned as different resource libraries. In this situation it would be impossible to overload the library value of the expression without a custom ResourceHandler implementation.</p>
<p>However, it is possible to eschew the value attribute on h:graphicImage and specify a library and name attribute that accept expression to resolve the library and resource name dynamically.</p>
<p>Keep an eye out for the next blog entry where I&#8217;ll cover the expanded event system.</p>
<p>Orginal Link : <a href="http://java.dzone.com/news/jsf-20-new-feature-preview-ser-2"> http://java.dzone.com/news/jsf-20-new-feature-preview-ser-2</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jarzone.wordpress.com/248/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jarzone.wordpress.com/248/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jarzone.wordpress.com/248/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jarzone.wordpress.com/248/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jarzone.wordpress.com/248/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jarzone.wordpress.com/248/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jarzone.wordpress.com/248/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jarzone.wordpress.com/248/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jarzone.wordpress.com/248/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jarzone.wordpress.com/248/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jarzone.wordpress.com/248/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jarzone.wordpress.com/248/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jarzone.wordpress.com/248/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jarzone.wordpress.com/248/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jarzone.wordpress.com&amp;blog=3156522&amp;post=248&amp;subd=jarzone&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jarzone.wordpress.com/2008/10/10/jsf-20-new-feature-preview-series-part-23-resources/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/16e5993227472808e5f16bc598927775?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jarzone</media:title>
		</media:content>
	</item>
		<item>
		<title>JSF 2.0 New Feature Preview Series (Part 3) Publish/Subscribe Event System</title>
		<link>http://jarzone.wordpress.com/2008/10/10/jsf-20-new-feature-preview-series-part-3-publishsubscribe-event-system/</link>
		<comments>http://jarzone.wordpress.com/2008/10/10/jsf-20-new-feature-preview-series-part-3-publishsubscribe-event-system/#comments</comments>
		<pubDate>Fri, 10 Oct 2008 03:07:15 +0000</pubDate>
		<dc:creator>jarzone</dc:creator>
				<category><![CDATA[Java Web Frame Work]]></category>
		<category><![CDATA[JSF]]></category>

		<guid isPermaLink="false">http://jarzone.wordpress.com/?p=246</guid>
		<description><![CDATA[This is the fifth entry in the JSF 2.0 New Feature Preview Series. The last entry wrapped up the new application resource handling.  We&#8217;ll now switch focus to the new publish/subscribe event system. Several component and application level APIs have been added to enable a robust event system for component and application developers to take [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jarzone.wordpress.com&amp;blog=3156522&amp;post=246&amp;subd=jarzone&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is the fifth entry in the JSF 2.0 New Feature Preview Series.  The <a href="http://blogs.sun.com/rlubke/entry/jsf_2_0_new_feature3">last entry</a> wrapped up the new application resource handling.  We&#8217;ll now switch focus to the new publish/subscribe event system.</p>
<p>Several component and application level APIs have been added to enable a robust event system for component and application developers to take advantage of. Please note that this blog is based on EDR1 and as such the signatures of the APIs will change. When this is the case, I&#8217;ll try to remember to update the blog accordingly.</p>
<p>Let&#8217;s start with the changes to javax.faces.component.UIComponent.</p>
<div class="dp-highlighter">
<div class="bar">
<div class="tools"><a href="http://java.dzone.com/news/jsf-20-new-feature-preview-ser-3#">view plain</a><a href="http://java.dzone.com/news/jsf-20-new-feature-preview-ser-3#">copy to clipboard</a><a href="http://java.dzone.com/news/jsf-20-new-feature-preview-ser-3#">print</a><a href="http://java.dzone.com/news/jsf-20-new-feature-preview-ser-3#">?</a></div>
</div>
<ol class="dp-j">
<li class="alt"><span><span class="keyword">public</span><span> </span><span class="keyword">void</span><span> subscribeToEvent(Class&lt;? </span><span class="keyword">extends</span><span> SystemEvent&gt; systemEventClass, </span></span></li>
<li><span> ComponentSystemEventListener componentListener) </span></li>
<li class="alt"><span> </span></li>
<li><span><span class="keyword">public</span><span> </span><span class="keyword">void</span><span> unsubscribeFromEvent(Class&lt;? </span><span class="keyword">extends</span><span> SystemEvent&gt; systemEventClass, </span></span></li>
<li class="alt"><span> ComponentSystemEventListener listener) </span></li>
<li><span> </span></li>
<li class="alt"><span><span class="keyword">public</span><span> List&lt;SystemEventListener&gt; getListenersForEventClass(Class&lt;? </span><span class="keyword">extends</span><span> SystemEvent&gt; systemEventClass) </span></span></li>
</ol>
</div>
<pre class="java" style="display:none;">public void subscribeToEvent(Class&lt;? extends SystemEvent&gt; systemEventClass,
                                                               ComponentSystemEventListener componentListener)

public void unsubscribeFromEvent(Class&lt;? extends SystemEvent&gt; systemEventClass,
      ComponentSystemEventListener listener)

public List&lt;SystemEventListener&gt; getListenersForEventClass(Class&lt;? extends SystemEvent&gt; systemEventClass)</pre>
<p>The signatures are fairly straight forward. The API allows a developer to, on this single component instance, associate/disassocaite a <a href="https://mojarra.dev.java.net/source/browse/mojarra/trunk/jsf-api/src/javax/faces/event/ComponentSystemEventListener.java?rev=4879&amp;view=markup">ComponentSystemEventListener</a> with some event type extending <a href="https://mojarra.dev.java.net/source/browse/mojarra/trunk/jsf-api/src/javax/faces/event/SystemEvent.java?rev=4987&amp;view=markup">SystemEvent</a>.    The method, getListenersForEventClass() is leveraged by the Application implementation when an event is published.</p>
<p>The other class central to the event system is javax.faces.application.Application.  The following methods have been added:</p>
<div class="dp-highlighter">
<div class="bar">
<div class="tools"><a href="http://java.dzone.com/news/jsf-20-new-feature-preview-ser-3#">view plain</a><a href="http://java.dzone.com/news/jsf-20-new-feature-preview-ser-3#">copy to clipboard</a><a href="http://java.dzone.com/news/jsf-20-new-feature-preview-ser-3#">print</a><a href="http://java.dzone.com/news/jsf-20-new-feature-preview-ser-3#">?</a></div>
</div>
<ol class="dp-j">
<li class="alt"><span><span class="keyword">public</span><span> </span><span class="keyword">void</span><span> subscribeToEvent(Class&lt;? </span><span class="keyword">extends</span><span> SystemEvent&gt; systemEventClass, </span></span></li>
<li><span> Class sourceClass, </span></li>
<li class="alt"><span> SystemEventListener listener) </span></li>
<li><span> </span></li>
<li class="alt"><span><span class="keyword">public</span><span> </span><span class="keyword">void</span><span> publishEvent(Class&lt;? </span><span class="keyword">extends</span><span> SystemEvent&gt; systemEventClass, </span></span></li>
<li><span> SystemEventListenerHolder source) </span></li>
<li class="alt"><span> </span></li>
<li><span><span class="keyword">public</span><span> </span><span class="keyword">void</span><span> unsubscribeFromEvent(Class&lt;? </span><span class="keyword">extends</span><span> SystemEvent&gt; systemEventClass, </span></span></li>
<li class="alt"><span> Class sourceClass, </span></li>
<li><span> SystemEventListener listener) </span></li>
</ol>
</div>
<pre class="java" style="display:none;">public void subscribeToEvent(Class&lt;? extends SystemEvent&gt; systemEventClass,
                                                               Class sourceClass,
                                                               SystemEventListener listener)

public void publishEvent(Class&lt;? extends SystemEvent&gt; systemEventClass,
                                                       SystemEventListenerHolder source)

public void unsubscribeFromEvent(Class&lt;? extends SystemEvent&gt; systemEventClass,
                                                                          Class sourceClass,
                                                                          SystemEventListener listener)</pre>
<p>The subscripbe/unsubscribe methods are similar to those define on <em>UIComponent</em>, however, these are application-wide instead of per-component.   It should be noted that an optional <em>sourceClass</em> can be provided so that the listener will only be invoked when the source of the event is of the configured type. I should note, that there is a two argument version of the subscribe and publish methods on Application that do not have <em>sourceClass</em> in their signature.  These merely call through to the three argument version passing null as the <em>sourceClass</em>.</p>
<p>Now, <em>publishEvent</em> is where all the work happens.  As currently spec&#8217;d, <em>publishEvent</em> will look for any listeners defined within the provided <a href="https://mojarra.dev.java.net/source/browse/mojarra/trunk/jsf-api/src/javax/faces/event/SystemEventListenerHolder.java?rev=4771&amp;view=markup">SystemEventListenerHolder</a> (UIComponent implements this interface, hence the description of the methods on UIComponent) interested in the provided SystemEvent type. Following that, <em>publishEvent</em> will invoke any listeners interested in both the provided SystemEvent and source type.  Lastly, <em>publishEvent</em> will invoke any listeners interested in received the specified SystemEvent type regardless of the source.</p>
<p>The spec includes several new events:</p>
<ul>
<li><strong>AfterAddToParentEvent</strong>.  This event will be published under the following circumstances:
<ul>
<li>When UIComponent.getChildren().add(childToAdd) is called (<strong>*</strong>)</li>
<li>When UIComponent.getFacets().put(facetName, facetChildToAdd) is called (<strong>*</strong>)</li>
<li>After the the view has been built</li>
</ul>
</li>
<li><strong>BeforeRenderEvent</strong>.  This event will be published when UIComponent.encodeBegin() is called.</li>
<li><strong>ViewMapCreatedEvent</strong>. This event will be published when UIViewRoot.getViewMap() or UIViewRoot.getViewMap(true) has been called (this is the basis for the new <em>view</em> scope).</li>
<li><strong>ViewMapDestroyedEvent</strong>. This event will be published by the default NavigationHandler when the view is being transitioned to a new view (i.e. the view IDs are not equal) and the view map has been used by the application</li>
</ul>
<p>More events may be added by the time the JSF 2.0 specification is completed.</p>
<p>As you can see, the new event system is quite flexible and extensible enough to be adapted for many uses.  For example, the <em>jsf-guessNumber2.0</em> demo application (to be included with the Mojarra 2.0.0 EDR1 release some time this week) leverages the BeforeRenderEvent to perform a hybrid of client/server-side validation.   Having this system in place also allows for another new feature which I will be discussing in the next entry, resource relocation. I won&#8217;t give too many details here, but resource relocation is the facility that allows stylesheets or scripts to be rendered in one of several locations independent of where actual tag was placed within the view definition.</p>
<p>Orginal URL : &lt;a href=&#8221;http://java.dzone.com/news/jsf-20-new-feature-preview-ser-3&#8243;&gt;http://java.dzone.com/news/jsf-20-new-feature-preview-ser-3&lt;/a&gt;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jarzone.wordpress.com/246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jarzone.wordpress.com/246/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jarzone.wordpress.com/246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jarzone.wordpress.com/246/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jarzone.wordpress.com/246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jarzone.wordpress.com/246/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jarzone.wordpress.com/246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jarzone.wordpress.com/246/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jarzone.wordpress.com/246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jarzone.wordpress.com/246/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jarzone.wordpress.com/246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jarzone.wordpress.com/246/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jarzone.wordpress.com/246/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jarzone.wordpress.com/246/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jarzone.wordpress.com&amp;blog=3156522&amp;post=246&amp;subd=jarzone&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jarzone.wordpress.com/2008/10/10/jsf-20-new-feature-preview-series-part-3-publishsubscribe-event-system/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/16e5993227472808e5f16bc598927775?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jarzone</media:title>
		</media:content>
	</item>
		<item>
		<title>Design patterns and GWT</title>
		<link>http://jarzone.wordpress.com/2008/07/23/design-patterns-and-gwt/</link>
		<comments>http://jarzone.wordpress.com/2008/07/23/design-patterns-and-gwt/#comments</comments>
		<pubDate>Wed, 23 Jul 2008 04:43:40 +0000</pubDate>
		<dc:creator>jarzone</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Design patterns]]></category>

		<guid isPermaLink="false">http://jarzone.wordpress.com/?p=243</guid>
		<description><![CDATA[We have a calculator EntryPoint implementation that places a CalculatorWidget on the RootPanel, so we now need to provide this widget. This will be our own widget, composed of basic GWT components. CalculatorWidget will contain the view for our calculator application, a simple data and logic layer as the model, and an intermediary controller between [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jarzone.wordpress.com&amp;blog=3156522&amp;post=243&amp;subd=jarzone&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>We have a calculator EntryPoint implementation that places a CalculatorWidget on the RootPanel, so we now need to provide this widget. This will be our own widget, composed of basic GWT components. CalculatorWidget will contain the view for our calculator application, a simple data and logic layer as the model, and an intermediary controller between these layers. This, of course, means we&#8217;ll be using MVC and GWT together &#8211; keep in mind that all of these components will end up distributed to the client.</p>
<p>MVC will be the overarching pattern for the macro level of our application. Additionally, we&#8217;ll use some other common object-oriented (OO) patterns on other levels because of the general benefits these approaches provide. For example, we&#8217;ll use the Observer pattern for event handling as part of the mechanism of communication between our model and our view. We&#8217;ll also use the Strategy pattern within the logic and operations parts of our model. We&#8217;ll provide more detail about each of these patterns, and the reasoning behind their use in each situation, as we come to those portions of the application.</p>
<p>The most important pattern we need to consider is MVC itself. This pattern is the most useful we have found for creating GWT applications, while still keeping them manageable and testable.</p>
<h2>MVC and GWT</h2>
<p>MVC is a familiar pattern to many developers. The pattern was first described in the late 70s by Trygve Reenskaug, who was working on Smalltalk at the time, and it has since been adopted, in various forms, by a wide range of programmers using many languages. The pattern is intended to separate responsibilities and allow for reuse of the logic and data portion of an application&#8217; the model. The view layer represents the model graphically, as the UI. Delegation between these layers is handled by an intermediary that is invoked by the user&#8217;s input, the controller. The basic MVC pattern is shown in figure 1.</p>
<p><span class="inline inline-none"><img class="image image-_original" src="http://java.dzone.com/sites/all/files/images/mvc.jpg" alt="" width="128" height="84" /></span></p>
<p>Figure 1 A basic model-view-controller architectural pattern diagram. The solid lines indicate a direct association, and the dashed lines indicate an indirect association, such as through an observer/observable relationship.</p>
<p>The key concepts to take away from MVC are the following: the model should be completely unaware of the view and controller, and the pattern can be applied on many different levels within an application.</p>
<p>In MVC, the model can be equipped to alert observers of changes within it, using the Observer pattern (something we&#8217;ll look more closely at in the section on communicating by observing events). This is shown by the dashed line in figure 1. In this way, any other layer observing the model can react to events coming from the model. Nevertheless, the model does not directly update the view, and this distinction is important. The model is the reusable part in all incarnations of MVC; if the model had any direct knowledge of the view, that tenet would break down. How the view and controller are linked together is often more variable.</p>
<p>The view typically has a reference to the controller, and may invoke controller methods directly, based on user input. The controller ideally will have no direct references back to the view, and should simply update the model. If the view is an observer of the model, this effectively updates the view without direct controller/view coupling. Alternatively, it&#8217;s also common to see situations in which the controller and view are treated as a pair, with direct references from the controller to the view.</p>
<p>There are many ways to divide up the responsibilities, and the various approaches have their pros and cons. The important part, though, is that the separation of responsibilities makes the code clearer, and often also makes testing easier. MVC can be applied with GWT, and it can happen on many different levels. An overall application may have a master domain, or model, and an overarching controller. Individual widgets can have their own encapsulated MVC, and small elements, such as a button, can repeat the pattern on their own level.</p>
<p>The possible variations of MVC, and many somewhat similar GUI architectural patterns, such as Presentation Abstraction Control (PAC) and Model View Presenter (MVP), are very interesting but are beyond our scope here. Fortunately, entire tomes on the subject exist. For our purposes, weâ€™ll turn to concrete examples of MVC that we have found work well with GWT. To do this, we need to get into code and implement the pattern.</p>
<h2>Creating a widget</h2>
<p>The functional specifications for a calculator (at least a simple one) are fairly universal; they include a display, some buttons, and some mathematical operations defined by the likes of Pythagoras and Euclid. For our calculator, we&#8217;ll make use of one GWT TextBox for the display and many GWT Buttons for, well, the buttons. We&#8217;ll also use a layout derived from a Panel and a Grid to control the overall placement of the UI items. In terms of MVC, view elements are where all widgets begin, starting with the layout. The model and controller for our calculator will be implemented as separate classes that are referenced by the widget.</p>
<p>With GWT, you use widgets to create your application. These components are built from layout panels, input elements, events, data objects, and various combinations thereof. This is where GWT really departs from typical web applications and may seem somewhat foreign to those accustomed to standard server-side Java development. To create an application, you use widgets that are capable of being inserted or removed from the screen, in a single page, on the client side.</p>
<p>For our purposes, we&#8217;ll extend the GWT-provided VerticalPanel component to build our view, and then include references to our separate controller and model, as shown in the class diagram in figure 2.</p>
<p><span class="inline inline-none"><img class="image image-_original" src="http://java.dzone.com/sites/all/files/images/class_diagram.jpg" alt="" width="373" height="184" /></span></p>
<p>Figure 2 CalculatorWidget top-level class diagram showing the extension of GWT&#8217;s VerticalPanel as the view, and the included model and controller references</p>
<p>It&#8217;s worth noting that figure 2 does not display all the attributes or operations of the CalculatorWidget class. We have included just a representative sample of attributes to keep it concise. The code for the CalculatorWidget will be displayed in three parts in listings 1, 2, and 3. Listing 1 addresses the beginning of the class, showing what the class needs to import and how the class is derived from, and makes use of, other existing GWT classes.</p>
<p>Listing 1 CalculatorWidget.java, part one:</p>
<div class="dp-highlighter">
<div class="bar">
<div class="tools"><a href="http://java.dzone.com/news/design-patterns-and-gwt#">view plain</a><a href="http://java.dzone.com/news/design-patterns-and-gwt#">copy to clipboard</a><a href="http://java.dzone.com/news/design-patterns-and-gwt#">print</a><a href="http://java.dzone.com/news/design-patterns-and-gwt#">?</a></div>
</div>
<ol class="dp-j">
<li class="alt"><span><span class="keyword">package</span><span> com.manning.gwtip.calculator.client; </span></span></li>
<li><span> </span></li>
<li class="alt"><span><span class="keyword">import</span><span> com.google.gwt.user.client.ui.Button; </span></span></li>
<li><span><span class="keyword">import</span><span> com.google.gwt.user.client.ui.ClickListener; </span></span></li>
<li class="alt"><span><span class="keyword">import</span><span> com.google.gwt.user.client.ui.Grid; </span></span></li>
<li><span><span class="keyword">import</span><span> com.google.gwt.user.client.ui.TextBox; </span></span></li>
<li class="alt"><span> </span></li>
<li><span><span class="comment">//. . . remainder of imports omitted</span><span> </span></span></li>
<li class="alt"><span> </span></li>
<li><span><span class="keyword">public</span><span> </span><span class="keyword">class</span><span> CalculatorWidget </span><span class="keyword">extends</span><span> VerticalPanel { </span></span></li>
<li class="alt"><span> <span class="keyword">private</span><span> TextBox display; </span></span></li>
<li><span> </span></li>
<li class="alt"><span> <span class="keyword">public</span><span> CalculatorWidget(</span><span class="keyword">final</span><span> String title) { </span></span></li>
<li><span> <span class="keyword">super</span><span>(); </span></span></li>
<li class="alt"><span> </span></li>
<li><span> <span class="keyword">final</span><span> CalculatorData data = </span><span class="keyword">new</span><span> CalculatorData(); </span></span></li>
<li class="alt"><span> </span></li>
<li><span> <span class="keyword">final</span><span> CalculatorController controller = </span></span></li>
<li class="alt"><span><span class="keyword">new</span><span> CalculatorController(data); </span></span></li>
<li><span> </span></li>
<li class="alt"><span><span class="comment">//&#8230;</span><span> </span></span></li>
</ol>
</div>
<pre class="java" style="display:none;">package com.manning.gwtip.calculator.client;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.TextBox;          

//. . . remainder of imports omitted

public class CalculatorWidget extends VerticalPanel {
	private TextBox display;

	public CalculatorWidget(final String title) {
		super();

		final CalculatorData data = new CalculatorData();

	   final CalculatorController controller =
new CalculatorController(data);                           

//...</pre>
<p>Within the first part of the CalculatorWidget class there are several important items. First of all, we&#8217;re making use of some existing GWT client.ui classes to compose our view . Our entire class is, in fact, a subclass of VerticalPanel . This is significant in that we inherit all of the hierarchy of a GWT UI Widget automatically with this approach.</p>
<p>Directly extending a panel in this manner is simple (in this case, intentionally so), but it&#8217;s also limiting. It&#8217;s often better to use a GWT Composite. We&#8217;re using direct subclassing here to keep things very basic, and we&#8217;ll move on to Composite in due course.</p>
<p>In listing 1 we then go on to define a simple constructor, and within it we create an instance of CalculatorController . CalculatorController itself will be addressed in the section on controlling the action, after we complete the CalculatorWidget class. The controller we&#8217;ll be using is a client-side component, which itself contains a reference to the data portion of our model, which is a single CalculatorData object. That takes us to part two of the CalculatorWidget class: layout and buttons. These view elements are displayed in listing 2.</p>
<p>Listing 2 CalculatorWidget.java, part two:</p>
<div class="dp-highlighter">
<div class="bar">
<div class="tools"><a href="http://java.dzone.com/news/design-patterns-and-gwt#">view plain</a><a href="http://java.dzone.com/news/design-patterns-and-gwt#">copy to clipboard</a><a href="http://java.dzone.com/news/design-patterns-and-gwt#">print</a><a href="http://java.dzone.com/news/design-patterns-and-gwt#">?</a></div>
</div>
<ol class="dp-j">
<li class="alt"><span><span>VerticalPanel p = </span><span class="keyword">new</span><span> VerticalPanel(); </span></span></li>
<li><span>p.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT); </span></li>
<li class="alt"><span>p.setStyleName(CalculatorConstants.STYLE_PANEL); </span></li>
<li><span> </span></li>
<li class="alt"><span>Grid g = <span class="keyword">new</span><span> Grid(</span><span class="number">4</span><span>, </span><span class="number">5</span><span>); </span></span></li>
<li><span>g.setStyleName(CalculatorConstants.STYLE_GRID); </span></li>
<li class="alt"><span> </span></li>
<li><span><span class="keyword">final</span><span> Button zero = </span><span class="keyword">new</span><span> ButtonDigit(controller, </span><span class="string">&#8220;0&#8243;</span><span>); </span></span></li>
<li class="alt"><span>g.setWidget(<span class="number">3</span><span>, </span><span class="number">0</span><span>, zero); </span></span></li>
<li><span> </span></li>
<li class="alt"><span><span class="keyword">final</span><span> Button one = </span><span class="keyword">new</span><span> ButtonDigit(controller, </span><span class="string">&#8220;1&#8243;</span><span>); </span></span></li>
<li><span>g.setWidget(<span class="number">2</span><span>, </span><span class="number">0</span><span>, one); </span></span></li>
<li class="alt"><span> </span></li>
<li><span><span class="keyword">final</span><span> Button two = </span><span class="keyword">new</span><span> ButtonDigit(controller, </span><span class="string">&#8220;2&#8243;</span><span>); </span></span></li>
<li class="alt"><span>g.setWidget(<span class="number">2</span><span>, </span><span class="number">1</span><span>, two); </span></span></li>
<li><span> </span></li>
<li class="alt"><span><span class="comment">//. . .</span><span> </span></span></li>
<li><span> </span></li>
<li class="alt"><span><span class="keyword">final</span><span> Button divide = </span><span class="keyword">new</span><span> ButtonOperator(controller, </span><span class="keyword">new</span><span> OperatorDivide()); </span></span></li>
<li><span>g.setWidget(<span class="number">0</span><span>, </span><span class="number">3</span><span>, divide); </span></span></li>
<li class="alt"><span> </span></li>
<li><span><span class="keyword">final</span><span> Button multiply = </span><span class="keyword">new</span><span> ButtonOperator(controller, </span><span class="keyword">new</span><span> OperatorMultiply()); </span></span></li>
<li class="alt"><span>g.setWidget(<span class="number">1</span><span>, </span><span class="number">3</span><span>, multiply); </span></span></li>
<li><span> </span></li>
<li class="alt"><span><span class="comment">//. . .</span><span> </span></span></li>
<li><span> </span></li>
<li class="alt"><span><span class="keyword">final</span><span> Button clear = </span><span class="keyword">new</span><span> Button(CalculatorConstants.CLEAR); </span></span></li>
<li><span>clear.addClickListener(<span class="keyword">new</span><span> ClickListener() { </span></span></li>
<li class="alt"><span> <span class="keyword">public</span><span> </span><span class="keyword">void</span><span> onClick(Widget sender) { </span></span></li>
<li><span> controller.processClear(); </span></li>
<li class="alt"><span> } </span></li>
<li><span> }); </span></li>
<li class="alt"><span> clear.setStyleName(CalculatorConstants.STYLE_BUTTON); </span></li>
<li><span> g.setWidget(<span class="number">2</span><span>, </span><span class="number">4</span><span>, clear); </span></span></li>
<li class="alt"><span> </span></li>
<li><span><span class="comment">//&#8230;</span><span> </span></span></li>
</ol>
</div>
<pre class="java" style="display:none;">VerticalPanel p = new VerticalPanel();
p.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT);
p.setStyleName(CalculatorConstants.STYLE_PANEL);     

Grid g = new Grid(4, 5);
g.setStyleName(CalculatorConstants.STYLE_GRID);

final Button zero = new ButtonDigit(controller, "0");
g.setWidget(3, 0, zero);

final Button one = new ButtonDigit(controller, "1");
g.setWidget(2, 0, one);

final Button two = new ButtonDigit(controller, "2");
g.setWidget(2, 1, two);

//. . .

final Button divide = new ButtonOperator(controller, new OperatorDivide());
g.setWidget(0, 3, divide);

final Button multiply = new ButtonOperator(controller, new OperatorMultiply());
g.setWidget(1, 3, multiply);

//. . .

final Button clear = new Button(CalculatorConstants.CLEAR);
clear.addClickListener(new ClickListener() {
		public void onClick(Widget sender) {
				controller.processClear();
		}
	});
	clear.setStyleName(CalculatorConstants.STYLE_BUTTON);
	g.setWidget(2, 4, clear);

//...</pre>
<p>In this second part of the CalculatorWidget class, we add components to our widget and add event handlers for those components. First, we create a GWT Grid , a component made of rows and columns that ultimately will be implemented as an HTML table. We&#8217;ll use this to lay out our calculator buttons. Then we add our two different types of buttons: ButtonDigit and ButtonOperator . The digits on our calculator are implemented by our own class, ButtonDigit, which extends the GWT Button class. The operators are similarly implemented by our own ButtonOperator class. Once again, for the sake of brevity, we have not included the code for all the fairly self-explanatory buttons and operators.</p>
<p>We have yet to create ButtonDigit and ButtonOperator, which we&#8217;ll do next, but the important thing to know at this point is that these classes both implement a ClickListener. This listener gets the control when the buttons are clicked, and it invokes a controller method. Listeners are common in component-oriented development and enable an event-driven approach. Various listeners, such as ClickListeners, OnChangeListeners, KeyboardListeners, and more are available in GWT. By using listeners in this way, the controller is notified to perform an appropriate action when any button or operator is pressed on our calculator.</p>
<blockquote>
<h3>About KeyboardListeners</h3>
<p>In this example, we have not attached KeyboardListeners to our calculator, for brevity&#8217;s sake. But, obviously, including them would be very useful for a calculator. They can be enabled by setting a default focus element and then attaching the listeners.</p></blockquote>
<p>Finally, we also add a standard GWT Button for both our calculator&#8217;s CLEAR and EQUALS functions. These buttons directly invoke methods on our controller instance without our own Button subclass. This is done with regard to CLEAR and EQUALS because these are special cases in terms of calculator buttons, as we shall see when we get to the controller in the next section. Before moving on, though, we need to implement the remainder of the CalculatorWidget, as shown in listing 3.</p>
<p>Listing 3 CalculatorWidget.java, part three:</p>
<div class="dp-highlighter">
<div class="bar">
<div class="tools"><a href="http://java.dzone.com/news/design-patterns-and-gwt#">view plain</a><a href="http://java.dzone.com/news/design-patterns-and-gwt#">copy to clipboard</a><a href="http://java.dzone.com/news/design-patterns-and-gwt#">print</a><a href="http://java.dzone.com/news/design-patterns-and-gwt#">?</a></div>
</div>
<ol class="dp-j">
<li class="alt"><span><span class="comment">// . . .</span><span> </span></span></li>
<li><span> </span></li>
<li class="alt"><span>display = <span class="keyword">new</span><span> TextBox(); </span></span></li>
<li><span> </span></li>
<li class="alt"><span>data.addChangeListener(<span class="keyword">new</span><span> CalculatorChangeListener() { </span></span></li>
<li><span> <span class="keyword">public</span><span> </span><span class="keyword">void</span><span> onChange(CalculatorData data) { </span></span></li>
<li class="alt"><span> display.setText( </span></li>
<li><span> String.valueOf(data.getDisplay())); </span></li>
<li class="alt"><span> } </span></li>
<li><span> }); </span></li>
<li class="alt"><span> display.setText(<span class="string">&#8220;0&#8243;</span><span>); </span></span></li>
<li><span> display.setTextAlignment(TextBox.ALIGN_RIGHT); </span></li>
<li class="alt"><span> </span></li>
<li><span> p.add(display); </span></li>
<li class="alt"><span> p.add(g); </span></li>
<li><span> <span class="keyword">this</span><span>.add(p); </span></span></li>
<li class="alt"><span> } </span></li>
<li><span>} </span></li>
</ol>
</div>
<pre class="java" style="display:none;">// . . .

display = new TextBox();                                       

data.addChangeListener(new CalculatorChangeListener() {
	public void onChange(CalculatorData data) {
			display.setText(
			String.valueOf(data.getDisplay()));
			}
		});
	display.setText("0");
	display.setTextAlignment(TextBox.ALIGN_RIGHT);

	p.add(display);
	p.add(g);
	this.add(p);
	}
}</pre>
<p>The final part of the CalculatorWidget class creates a GWT TextBox for our calculator&#8217;s display area , and then adds that component and our Grid to an earlier created VerticalPanel, which is in turn added to the current instance of itself. This ensures that all of the items are visible when CalculatorWidget is used .</p>
<p>Getting back to event handling, we have also introduced a custom listener&#8217; our own CalculatorChangeListener interface . This is implemented as an anonymous inner class, and it connects our display widget (the view) to the data it represents (the model), through events.</p>
<p>These events are a manifestation of the Observer pattern. We&#8217;ll now take a closer look at this relationship, because it&#8217;s what facilitates the separate responsibilities in our MVC-powered GWT calculator.</p>
<p>We need to briefly elaborate on the event handling we have just introduced via CalculatorChangeListener. The general pattern, Observer, is how our calculator&#8217;s model and view will be connected. It&#8217;s also how default GWT components themselves generally communicate.</p>
<p>In addition to MVC, many developers will be accustomed to event handling. Some non-GUI programmers may also have realized the power of this approach and may be using it on the server side. If you&#8217;re already familiar with events, you may find our initial examples here primitive. This is because we&#8217;re trying to simplify and demonstrate the concepts, rather than to create the most efficient or streamlined code. (For example, we&#8217;re not using such standard Java event idioms as PropertyChangeSupport and related constructs.).</p>
<p>This approach should bring those who have not yet encountered event-based and asynchronous programming, especially in relation to a GUI, up to speed quickly. We&#8217;ll bring the pattern, itself, to the forefront with our first manually driven example. Listening for, and notifying of, events are all aspects of the Observer pattern. Figure 3 illustrates this pattern.</p>
<p><span class="inline inline-none"><img class="image image-_original" src="http://java.dzone.com/sites/all/files/images/observer_pattern.jpg" alt="" width="356" height="177" /></span></p>
<p>Figure 3 The Observer pattern, which is used in GWT to connect the model and view</p>
<p>In our example, the CalculatorChangeListener is used to register our view component (our CalculatorWidget itself) with the data portion of our model (CalculatorData). This is basically the first half of an observer/observable relationship between these components. Our change listener interface is shown in listing 4.</p>
<p>Listing 4 CalculatorChangeListener.java</p>
<div class="dp-highlighter">
<div class="bar">
<div class="tools"><a href="http://java.dzone.com/news/design-patterns-and-gwt?page=0%2C1#">view plain</a><a href="http://java.dzone.com/news/design-patterns-and-gwt?page=0%2C1#">copy to clipboard</a><a href="http://java.dzone.com/news/design-patterns-and-gwt?page=0%2C1#">print</a><a href="http://java.dzone.com/news/design-patterns-and-gwt?page=0%2C1#">?</a></div>
</div>
<ol class="dp-j">
<li class="alt"><span><span class="keyword">public</span><span> </span><span class="keyword">interface</span><span> CalculatorChangeListener { </span></span></li>
<li><span> <span class="keyword">public</span><span> </span><span class="keyword">void</span><span> onChange(CalculatorData data); </span></span></li>
<li class="alt"><span>} </span></li>
</ol>
</div>
<pre class="java" style="display:none;">public interface CalculatorChangeListener {
	public void onChange(CalculatorData data);
}</pre>
<p>CalculatorChangeListener has a single callback method, onChange() . This is a fairly typical basic listener interface. Our CalculatorData model component, as we&#8217;ll see in a bit, makes itself observable (available for listeners to listen to) by implementing another simple interface, CalculatorChangeNotifier. This change notifier interface is shown in listing 5.</p>
<p>Listing 5 CalculatorChangeNotifier.java</p>
<div class="dp-highlighter">
<div class="bar">
<div class="tools"><a href="http://java.dzone.com/news/design-patterns-and-gwt?page=0%2C1#">view plain</a><a href="http://java.dzone.com/news/design-patterns-and-gwt?page=0%2C1#">copy to clipboard</a><a href="http://java.dzone.com/news/design-patterns-and-gwt?page=0%2C1#">print</a><a href="http://java.dzone.com/news/design-patterns-and-gwt?page=0%2C1#">?</a></div>
</div>
<ol class="dp-j">
<li class="alt"><span><span class="keyword">public</span><span> </span><span class="keyword">interface</span><span> CalculatorChangeNotifier { </span></span></li>
<li><span> <span class="keyword">public</span><span> </span><span class="keyword">void</span><span> addChangeListener( </span></span></li>
<li class="alt"><span><span class="keyword">final</span><span> CalculatorChangeListener listener); </span></span></li>
<li><span>} </span></li>
</ol>
</div>
<pre class="java" style="display:none;">public interface CalculatorChangeNotifier {
	public void addChangeListener(
final CalculatorChangeListener listener);
}</pre>
<p>CalculatorData, as shown in listing 6, therefore carries out the other half of the observer/observable relationship and notifies any listeners that come along when things change.</p>
<p>Listing 6 CalculatorData.java: the data portion of the model layer:</p>
<div class="dp-highlighter">
<div class="bar">
<div class="tools"><a href="http://java.dzone.com/news/design-patterns-and-gwt?page=0%2C1#">view plain</a><a href="http://java.dzone.com/news/design-patterns-and-gwt?page=0%2C1#">copy to clipboard</a><a href="http://java.dzone.com/news/design-patterns-and-gwt?page=0%2C1#">print</a><a href="http://java.dzone.com/news/design-patterns-and-gwt?page=0%2C1#">?</a></div>
</div>
<ol class="dp-j">
<li class="alt"><span><span class="keyword">public</span><span> </span><span class="keyword">class</span><span> CalculatorData </span><span class="keyword">implements</span><span> CalculatorChangeNotifier { </span></span></li>
<li><span><span class="keyword">private</span><span> String display; </span></span></li>
<li class="alt"><span><span class="keyword">private</span><span> </span><span class="keyword">double</span><span> buffer; </span></span></li>
<li><span><span class="keyword">private</span><span> </span><span class="keyword">boolean</span><span> initDisplay; </span></span></li>
<li class="alt"><span><span class="keyword">private</span><span> </span><span class="keyword">boolean</span><span> lastOpEquals; </span></span></li>
<li><span><span class="keyword">private</span><span> CalculatorChangeListener listener; </span></span></li>
<li class="alt"><span> </span></li>
<li><span><span class="keyword">public</span><span> CalculatorData() { </span></span></li>
<li class="alt"><span> <span class="keyword">this</span><span>.clear(); </span></span></li>
<li><span>} </span></li>
<li class="alt"><span> </span></li>
<li><span><span class="keyword">public</span><span> </span><span class="keyword">void</span><span> addChangeListener( </span></span></li>
<li class="alt"><span><span class="keyword">final</span><span> CalculatorChangeListener listener) { </span></span></li>
<li><span> <span class="keyword">this</span><span>.listener = listener; </span></span></li>
<li class="alt"><span>} </span></li>
<li><span> </span></li>
<li class="alt"><span><span class="keyword">public</span><span> </span><span class="keyword">void</span><span> clear() { </span></span></li>
<li><span> <span class="keyword">this</span><span>.display = </span><span class="string">&#8220;0&#8243;</span><span>; </span></span></li>
<li class="alt"><span> <span class="keyword">this</span><span>.buffer = </span><span class="number">0.0</span><span>; </span></span></li>
<li><span> <span class="keyword">this</span><span>.initDisplay = </span><span class="keyword">true</span><span>; </span></span></li>
<li class="alt"><span> <span class="keyword">this</span><span>.lastOpEquals = </span><span class="keyword">false</span><span>; </span></span></li>
<li><span> <span class="keyword">if</span><span> (listener != </span><span class="keyword">null</span><span>) listener.onChange(</span><span class="keyword">this</span><span>); </span></span></li>
<li class="alt"><span>} </span></li>
<li><span> </span></li>
<li class="alt"><span><span class="keyword">public</span><span> </span><span class="keyword">double</span><span> getBuffer() { </span></span></li>
<li><span> <span class="keyword">return</span><span> buffer; </span></span></li>
<li class="alt"><span>} </span></li>
<li><span> </span></li>
<li class="alt"><span><span class="keyword">public</span><span> </span><span class="keyword">void</span><span> setBuffer(</span><span class="keyword">double</span><span> buffer) { </span></span></li>
<li><span> <span class="keyword">this</span><span>.buffer = buffer; </span></span></li>
<li class="alt"><span> listener.onChange(<span class="keyword">this</span><span>); </span></span></li>
<li><span>} </span></li>
<li class="alt"><span> </span></li>
<li><span><span class="keyword">public</span><span> String getDisplay() { </span></span></li>
<li class="alt"><span> <span class="keyword">return</span><span> display; </span></span></li>
<li><span>} </span></li>
<li class="alt"><span> </span></li>
<li><span><span class="keyword">public</span><span> </span><span class="keyword">void</span><span> setDisplay(String display) { </span></span></li>
<li class="alt"><span> <span class="keyword">this</span><span>.display = display; </span></span></li>
<li><span> listener.onChange(<span class="keyword">this</span><span>); </span></span></li>
<li class="alt"><span>} </span></li>
<li><span> </span></li>
<li class="alt"><span><span class="comment">//&#8230;</span><span> </span></span></li>
</ol>
</div>
<pre class="java" style="display:none;">public class CalculatorData implements CalculatorChangeNotifier {
private String display;
private double buffer;
private boolean initDisplay;
private boolean lastOpEquals;
private CalculatorChangeListener listener;

public CalculatorData() {
	this.clear();
}

public void addChangeListener(
final CalculatorChangeListener listener) {
	this.listener = listener;
}

public void clear() {
	this.display = "0";
	this.buffer = 0.0;
	this.initDisplay = true;
	this.lastOpEquals = false;
	if (listener != null) listener.onChange(this);
}

public double getBuffer() {
	return buffer;
}

public void setBuffer(double buffer) {
	this.buffer = buffer;
	listener.onChange(this);
}

public String getDisplay() {
	return display;
}

public void setDisplay(String display) {
	this.display = display;
	listener.onChange(this);
}	

//...</pre>
<p>CalculatorData allows a single listener to register , and then, when its own setters are invoked, it notifies that listener of the change. Again, keep in mind that we have simplified the approach here. In the real world, as is the case with GWT&#8217;s own components that use this same pattern, you will likely see more than one listener attached to an observable in a collection, and hierarchies of specialized interfaces or abstract classes used for both observable and observer support (and you will need support to remove and clean up observers).</p>
<p>Along with the event mechanism, you probably have also noticed by now that the CalculatorWidget makes references to CalculatorConstants. This is a simple constants class that defines CSS styles and String constants such as: ADD, SUBTRACT, SQRT, and EQUALS. Now that we have our CalculatorWidget in place and our event handling taken care of, we&#8217;ll go back to the remainder of our example. This means we need to address ButtonDigit and ButtonOperator, where weâ€™ll meet the other half of our model, the logic.</p>
<h2>Operator strategy</h2>
<p>As we saw in the code in the &#8216;Creating a widget&#8217; section, CalculatorWidget makes use of several custom button types. The buttons of a calculator handle the numeric and operator input. Buttons are, of course, view components, but the buttons we&#8217;ll create to fill these roles are also backed by the logic portion of our model, our calculator&#8217;s operators. We have used our own specific Java types, ButtonDigit and ButtonOperator, so that we can easily distinguish the logical types of buttons pressed, and so that we can further encapsulate the logic for each operation. Listing 7 shows our ButtonDigit implementation.</p>
<p>Listing 7 ButtonDigit.java</p>
<div class="dp-highlighter">
<div class="bar">
<div class="tools"><a href="http://java.dzone.com/news/design-patterns-and-gwt?page=0%2C1#">view plain</a><a href="http://java.dzone.com/news/design-patterns-and-gwt?page=0%2C1#">copy to clipboard</a><a href="http://java.dzone.com/news/design-patterns-and-gwt?page=0%2C1#">print</a><a href="http://java.dzone.com/news/design-patterns-and-gwt?page=0%2C1#">?</a></div>
</div>
<ol class="dp-j">
<li class="alt"><span><span class="keyword">public</span><span> </span><span class="keyword">class</span><span> ButtonDigit </span><span class="keyword">extends</span><span> Button { </span></span></li>
<li><span> <span class="keyword">public</span><span> ButtonDigit( </span></span></li>
<li class="alt"><span> <span class="keyword">final</span><span> CalculatorController controller, </span></span></li>
<li><span> <span class="keyword">final</span><span> String label) { </span></span></li>
<li class="alt"><span> <span class="keyword">super</span><span>(label); </span></span></li>
<li><span> <span class="keyword">this</span><span>.addClickListener(</span><span class="keyword">new</span><span> ClickListener() { </span></span></li>
<li class="alt"><span> <span class="keyword">public</span><span> </span><span class="keyword">void</span><span> onClick(Widget sender) { </span></span></li>
<li><span> controller.processDigit(label); </span></li>
<li class="alt"><span> } </span></li>
<li><span> }); </span></li>
<li class="alt"><span> <span class="keyword">this</span><span>.setStyleName(CalculatorConstants.STYLE_BUTTON_DIGIT); </span></span></li>
<li><span> } </span></li>
<li class="alt"><span>} </span></li>
</ol>
</div>
<pre class="java" style="display:none;">public class ButtonDigit extends Button {
	public ButtonDigit(
	  final CalculatorController controller,
	  final String label) {
		super(label);
		this.addClickListener(new ClickListener() {
				public void onClick(Widget sender) {
					controller.processDigit(label);
				}
			});
		this.setStyleName(CalculatorConstants.STYLE_BUTTON_DIGIT);
	}
}</pre>
<p>ButtonDigit is a very straightforward extension of the GWT Button class. It simply includes a CalculatorController object reference in its constructor , and then invokes the controller&#8217;s processDigit() method each time a ButtonDigit instance is clicked . This is a repeat of the pattern we&#8217;re using in the outer CalculatorWidget, using the same controller reference. This invocation is achieved via a ClickListener.</p>
<p>The primary point in this example, especially for server-oriented developers, is that extending the basic UI classes is not only possible, but desirable. Using OOP techniques to extend functionality allows for much cleaner separation and reuse of code. This is in contrast to HTML-based development, where the &lt;input type=&#8221;button&#8221;&gt; represents an opaque instruction. This fairly simple example just passes on a value, but you should note that the MVC pattern is present on multiple levels.</p>
<p>In listing 8 we see this pattern again with the ButtonOperator class. In this case, MVC comes into play on a micro level, while it&#8217;s also used on a macro level with the entire outer Widget. ButtonOperator has a model, represented by the label; a view, managed by the parent class of Button, tweaked by the designation of a style to the button; and a controller layer represented by an AbstractOperator instance, which translates actions up to the larger scope controller for the calculator widget.</p>
<p>Listing 8 ButtonOperator.java</p>
<div class="dp-highlighter">
<div class="bar">
<div class="tools"><a href="http://java.dzone.com/news/design-patterns-and-gwt?page=0%2C1#">view plain</a><a href="http://java.dzone.com/news/design-patterns-and-gwt?page=0%2C1#">copy to clipboard</a><a href="http://java.dzone.com/news/design-patterns-and-gwt?page=0%2C1#">print</a><a href="http://java.dzone.com/news/design-patterns-and-gwt?page=0%2C1#">?</a></div>
</div>
<ol class="dp-j">
<li class="alt"><span><span class="keyword">public</span><span> </span><span class="keyword">class</span><span> ButtonOperator </span><span class="keyword">extends</span><span> Button { </span></span></li>
<li><span> <span class="keyword">public</span><span> ButtonOperator(</span><span class="keyword">final</span><span> CalculatorController controller, </span></span></li>
<li class="alt"><span> <span class="keyword">final</span><span> AbstractOperator op) { </span></span></li>
<li><span> <span class="keyword">super</span><span>(op.label); </span></span></li>
<li class="alt"><span> <span class="keyword">this</span><span>.addClickListener(</span><span class="keyword">new</span><span> ClickListener() { </span></span></li>
<li><span> <span class="keyword">public</span><span> </span><span class="keyword">void</span><span> onClick(Widget sender) { </span></span></li>
<li class="alt"><span> controller.processOperator(op); </span></li>
<li><span> } </span></li>
<li class="alt"><span> }); </span></li>
<li><span> <span class="keyword">this</span><span>.setStyleName(CalculatorConstants.STYLE_BUTTON_OPERATOR); </span></span></li>
<li class="alt"><span> } </span></li>
<li><span>} </span></li>
</ol>
</div>
<pre class="java" style="display:none;">public class ButtonOperator extends Button {
	public ButtonOperator(final CalculatorController controller,
		final AbstractOperator op) {
		super(op.label);
		this.addClickListener(new ClickListener() {
				public void onClick(Widget sender) {
					controller.processOperator(op);
				}
			});
		this.setStyleName(CalculatorConstants.STYLE_BUTTON_OPERATOR);
	}
}</pre>
<p>ButtonOperator works in much the same way as ButtonDigit does. It extends the GWT Button class and includes a CalculatorController object reference in its constructor . Then it invokes the controller&#8217;s processOperator() method each time a ButtonOperator instance is clicked . The difference with ButtonOperator is that it includes a reference to an AbstractOperator class in its constructor.</p>
<p>Now that we have operator buttons, we obviously need operations to back these view components. To complete these components, we&#8217;ll use the Strategy pattern to encapsulate the logic. Rather than a monolithic if/else logic block, we&#8217;ll delegate each operation to a specified instance of an operator class (each an implementation of AbstractOperator) and let those classes update our calculator&#8217;s model. Using our operators in this manner makes our calculator easier to understand and allows for greater flexibility and extensibility. With this approach, we can add new operators later without affecting our existing logic. Figure 4 shows the Strategy pattern.</p>
<p><span class="inline inline-none"><img class="image image-_original" src="http://java.dzone.com/sites/all/files/images/strategy_pattern.jpg" alt="" width="356" height="86" /></span></p>
<p>Figure 4 The Strategy pattern used in the GWT calculator example to implement operators</p>
<p>The only exceptions to this strategic structure for operators are the CLEAR and EQUALS operations, which are handled directly by the calculator controller, not by operator subclasses. Doing it this way requires less code and makes things a bit clearer. (We have some global state information in the controller that CLEAR and EQUALS rely upon. A purist implementation could put this information in our model and make separate operators for CLEAR and EQUALS as well, but that would complicate the other operations just for the sake of the pattern, and we think that would be overkill in this instance.)</p>
<p>These concepts may seem slightly off the beaten GWT path, but they serve to demonstrate the important point that you can use many OO design principles within the context of the toolkit. This flexibility is one of the advantages of GWT. In addition, this approach provides a much more robust calculator at the end of the day.</p>
<p>To handle the individual operators for our calculator, we need to implement the AbstractOperator and the subclasses that will extend it. As we saw in listing 8, ButtonOperator includes a reference to AbstractOperator. This is because each operator needs to do something different within a calculator application; each has a unique behavior. AbstractOperator, the straightforward beginning of the hierarchy, is shown in listing 9.</p>
<p>Listing 9 AbstractOperator.java</p>
<div class="dp-highlighter">
<div class="bar">
<div class="tools"><a href="http://java.dzone.com/news/design-patterns-and-gwt?page=0%2C1#">view plain</a><a href="http://java.dzone.com/news/design-patterns-and-gwt?page=0%2C1#">copy to clipboard</a><a href="http://java.dzone.com/news/design-patterns-and-gwt?page=0%2C1#">print</a><a href="http://java.dzone.com/news/design-patterns-and-gwt?page=0%2C1#">?</a></div>
</div>
<ol class="dp-j">
<li class="alt"><span><span class="keyword">public</span><span> </span><span class="keyword">abstract</span><span> </span><span class="keyword">class</span><span> AbstractOperator { </span></span></li>
<li><span> <span class="keyword">public</span><span> String label; </span></span></li>
<li class="alt"><span> </span></li>
<li><span> AbstractOperator(<span class="keyword">final</span><span> String label) { </span></span></li>
<li class="alt"><span> <span class="keyword">this</span><span>.label = label; </span></span></li>
<li><span> } </span></li>
<li class="alt"><span> <span class="keyword">public</span><span> </span><span class="keyword">abstract</span><span> </span><span class="keyword">void</span><span> operate( </span></span></li>
<li><span> <span class="keyword">final</span><span> CalculatorData data); </span></span></li>
<li class="alt"><span>} </span></li>
</ol>
</div>
<pre class="java" style="display:none;">public abstract class AbstractOperator {
	public String label;

	AbstractOperator(final String label) {
		this.label = label;
	}
	public abstract void operate(
		final CalculatorData data);
}</pre>
<p>AbstractOperator defines a single abstract method, operate(), which takes CalculatorData as input and updates it accordingly . We further divide operators with abstract types that determine whether or not the operator being implemented is binary or unary. BinaryOperator and UnaryOperator are as follows:</p>
<div class="dp-highlighter">
<div class="bar">
<div class="tools"><a href="http://java.dzone.com/news/design-patterns-and-gwt?page=0%2C1#">view plain</a><a href="http://java.dzone.com/news/design-patterns-and-gwt?page=0%2C1#">copy to clipboard</a><a href="http://java.dzone.com/news/design-patterns-and-gwt?page=0%2C1#">print</a><a href="http://java.dzone.com/news/design-patterns-and-gwt?page=0%2C1#">?</a></div>
</div>
<ol class="dp-j">
<li class="alt"><span><span class="keyword">public</span><span> </span><span class="keyword">abstract</span><span> </span><span class="keyword">class</span><span> BinaryOperator </span><span class="keyword">extends</span><span> AbstractOperator { </span></span></li>
<li><span> BinaryOperator(<span class="keyword">final</span><span> String label) { </span></span></li>
<li class="alt"><span> <span class="keyword">super</span><span>(label); </span></span></li>
<li><span> } </span></li>
<li class="alt"><span> </span></li>
<li><span><span class="keyword">public</span><span> </span><span class="keyword">abstract</span><span> </span><span class="keyword">class</span><span> UnaryOperator </span><span class="keyword">extends</span><span> AbstractOperator { </span></span></li>
<li class="alt"><span> UnaryOperator(<span class="keyword">final</span><span> String label) { </span></span></li>
<li><span> <span class="keyword">super</span><span>(label); </span></span></li>
<li class="alt"><span> } </span></li>
<li><span>} </span></li>
</ol>
</div>
<pre class="java" style="display:none;">public abstract class BinaryOperator extends AbstractOperator {
	BinaryOperator(final String label) {
		super(label);
	}

public abstract class UnaryOperator extends AbstractOperator {
	UnaryOperator(final String label) {
		super(label);
	}
}</pre>
<p>With our operator abstractions in place, we&#8217;ll now implement a simple concrete operator for addition. (We&#8217;ll not explicitly cover all the concrete operators used in our CalculatorWidget in the text for the sake of brevity). Listing 10 displays OperatorAdd.</p>
<p>Listing 10 OperatorAdd</p>
<div class="dp-highlighter">
<div class="bar">
<div class="tools"><a href="http://java.dzone.com/news/design-patterns-and-gwt?page=0%2C1#">view plain</a><a href="http://java.dzone.com/news/design-patterns-and-gwt?page=0%2C1#">copy to clipboard</a><a href="http://java.dzone.com/news/design-patterns-and-gwt?page=0%2C1#">print</a><a href="http://java.dzone.com/news/design-patterns-and-gwt?page=0%2C1#">?</a></div>
</div>
<ol class="dp-j">
<li class="alt"><span><span class="keyword">public</span><span> </span><span class="keyword">class</span><span> OperatorAdd </span><span class="keyword">extends</span><span> BinaryOperator { </span></span></li>
<li><span> </span></li>
<li class="alt"><span> <span class="keyword">public</span><span> OperatorAdd() { </span></span></li>
<li><span> <span class="keyword">super</span><span>(CalculatorConstants.ADD); </span></span></li>
<li class="alt"><span> } </span></li>
<li><span> </span></li>
<li class="alt"><span> <span class="keyword">public</span><span> </span><span class="keyword">void</span><span> operate(</span><span class="keyword">final</span><span> CalculatorData data) { </span></span></li>
<li><span> data.setDisplay(String.valueOf(data.getBuffer() + </span></li>
<li class="alt"><span> Double.parseDouble(data.getDisplay()))); </span></li>
<li><span> data.setInitDisplay(<span class="keyword">true</span><span>); </span></span></li>
<li class="alt"><span> } </span></li>
<li><span>} </span></li>
</ol>
</div>
<pre class="java" style="display:none;">public class OperatorAdd extends BinaryOperator {

	public OperatorAdd() {
		super(CalculatorConstants.ADD);
	}

	public void operate(final CalculatorData data) {
		data.setDisplay(String.valueOf(data.getBuffer() +
			   Double.parseDouble(data.getDisplay())));
		data.setInitDisplay(true);
	}
}</pre>
<p>The binary addition operator adds the current buffer to the current display value, and then updates the display . Binary operators in this context are basically responsible for updating the display, based on the values in the CalculatorData object. Also, this operator sets the initDisplay status to true ; this indicates that, when the next digit is entered, the display should start over rather than append digits to any possible existing value. Now, with all of the other aspects of our CalculatorWidget in place, we can move on to the controller.</p>
<h2>Controlling the action</h2>
<p>The calculator&#8217;s controller handles the interaction between the other calculator components. The controller is called upon by the various buttons to perform actions such as invoking an operator or otherwise manipulating the model or internal state.</p>
<p>The GWT CalculatorWidget controller component is significant for several reasons beyond just the separation of responsibilities derived from the MVC pattern itself. We&#8217;ll write this component in Java, and it will be compiled into JavaScript by GWT along with our UI components, yet this has nothing to do with the interface. GWT allows you to create not only your UI but also any logic and data representations with client-side intentions. You can create classes, like we&#8217;re about to do with our CalculatorController and have already done with our CalculatorData, which end up in the client browser as completely non-view-related items.</p>
<p>In the CalculatorController, which is presented in listing 11, notice that there are no references to GWT-related classes.</p>
<p>Listing 11 CalculatorController.java</p>
<div class="dp-highlighter">
<div class="bar">
<div class="tools"><a href="http://java.dzone.com/news/design-patterns-and-gwt?page=0%2C1#">view plain</a><a href="http://java.dzone.com/news/design-patterns-and-gwt?page=0%2C1#">copy to clipboard</a><a href="http://java.dzone.com/news/design-patterns-and-gwt?page=0%2C1#">print</a><a href="http://java.dzone.com/news/design-patterns-and-gwt?page=0%2C1#">?</a></div>
</div>
<ol class="dp-j">
<li class="alt"><span><span class="keyword">public</span><span> </span><span class="keyword">class</span><span> CalculatorController { </span></span></li>
<li><span> </span></li>
<li class="alt"><span> CalculatorData data; </span></li>
<li><span> AbstractOperator lastOperator; </span></li>
<li class="alt"><span> Private <span class="keyword">double</span><span> prevBuffer; </span></span></li>
<li><span> </span></li>
<li class="alt"><span> <span class="keyword">public</span><span> CalculatorController( </span></span></li>
<li><span> <span class="keyword">final</span><span> CalculatorData data) { </span></span></li>
<li class="alt"><span> <span class="keyword">this</span><span>.data = data; </span></span></li>
<li><span> } </span></li>
<li class="alt"><span> </span></li>
<li><span> <span class="keyword">public</span><span> </span><span class="keyword">void</span><span> processClear() { </span></span></li>
<li class="alt"><span> data.clear(); </span></li>
<li><span> lastOperator = <span class="keyword">null</span><span>; </span></span></li>
<li class="alt"><span> } </span></li>
<li><span> </span></li>
<li class="alt"><span> <span class="keyword">public</span><span> </span><span class="keyword">void</span><span> processEquals() { </span></span></li>
<li><span> <span class="keyword">if</span><span> (lastOperator != </span><span class="keyword">null</span><span>) { </span></span></li>
<li class="alt"><span> <span class="keyword">if</span><span> (!data.isLastOpEquals()) { </span></span></li>
<li><span> prevBuffer = Double.parseDouble(data.getDisplay()); </span></li>
<li class="alt"><span> } </span></li>
<li><span> lastOperator.operate(data); </span></li>
<li class="alt"><span> data.setBuffer(prevBuffer); </span></li>
<li><span> data.setLastOpEquals(<span class="keyword">true</span><span>); </span></span></li>
<li class="alt"><span> } </span></li>
<li><span> } </span></li>
<li class="alt"><span> </span></li>
<li><span> <span class="keyword">public</span><span> </span><span class="keyword">void</span><span> processOperator( </span></span></li>
<li class="alt"><span> <span class="keyword">final</span><span> AbstractOperator op) { </span></span></li>
<li><span> <span class="keyword">if</span><span> (op </span><span class="keyword">instanceof</span><span> BinaryOperator) { </span></span></li>
<li class="alt"><span> <span class="keyword">if</span><span> ((lastOperator == </span><span class="keyword">null</span><span>) || (data.isLastOpEquals())) { </span></span></li>
<li><span> data.setBuffer(Double.parseDouble(data.getDisplay())); </span></li>
<li class="alt"><span> data.setInitDisplay(<span class="keyword">true</span><span>); </span></span></li>
<li><span> } <span class="keyword">else</span><span> { </span></span></li>
<li class="alt"><span> lastOperator.operate(data); </span></li>
<li><span> } </span></li>
<li class="alt"><span> lastOperator = op; </span></li>
<li><span> } <span class="keyword">else</span><span> </span><span class="keyword">if</span><span> (op </span><span class="keyword">instanceof</span><span> UnaryOperator) { </span></span></li>
<li class="alt"><span> op.operate(data); </span></li>
<li><span> } </span></li>
<li class="alt"><span> data.setLastOpEquals(<span class="keyword">false</span><span>); </span></span></li>
<li><span> } </span></li>
<li class="alt"><span> </span></li>
<li><span> <span class="keyword">public</span><span> </span><span class="keyword">void</span><span> processDigit(</span><span class="keyword">final</span><span> String s) { </span></span></li>
<li class="alt"><span> <span class="keyword">if</span><span> (data.isLastOpEquals()) { </span></span></li>
<li><span> lastOperator = <span class="keyword">null</span><span>; </span></span></li>
<li class="alt"><span> } </span></li>
<li><span> <span class="keyword">if</span><span> (data.isInitDisplay()) { </span></span></li>
<li class="alt"><span> <span class="keyword">if</span><span> (data.isLastOpEquals()) { </span></span></li>
<li><span> data.setBuffer(<span class="number">0.0</span><span>); </span></span></li>
<li class="alt"><span> } <span class="keyword">else</span><span> { </span></span></li>
<li><span> data.setBuffer(Double.parseDouble(data.getDisplay())); </span></li>
<li class="alt"><span> } </span></li>
<li><span> data.setDisplay(s); </span></li>
<li class="alt"><span> data.setInitDisplay(<span class="keyword">false</span><span>); </span></span></li>
<li><span> } <span class="keyword">else</span><span> { </span></span></li>
<li class="alt"><span> <span class="keyword">if</span><span> (data.getDisplay().indexOf( </span></span></li>
<li><span> CalculatorConstants.POINT) == -<span class="number">1</span><span>) { </span></span></li>
<li class="alt"><span> data.setDisplay(data.getDisplay() + s); </span></li>
<li><span> } <span class="keyword">else</span><span> </span><span class="keyword">if</span><span> (!s.equals(CalculatorConstants.POINT)) { </span></span></li>
<li class="alt"><span> data.setDisplay(data.getDisplay() + s); </span></li>
<li><span> } </span></li>
<li class="alt"><span> } </span></li>
<li><span> data.setLastOpEquals(<span class="keyword">false</span><span>); </span></span></li>
<li class="alt"><span> } </span></li>
<li><span>} </span></li>
</ol>
</div>
<pre class="java" style="display:none;">public class CalculatorController {

	CalculatorData data;
	AbstractOperator lastOperator;
	Private double prevBuffer; 

	public CalculatorController(
		   final CalculatorData data) {
		this.data = data;
	}

	public void processClear() {
		data.clear();
		lastOperator = null;
	}

	public void processEquals() {
		if (lastOperator != null) {
			if (!data.isLastOpEquals()) {
				prevBuffer = Double.parseDouble(data.getDisplay());
			}
			lastOperator.operate(data);
			data.setBuffer(prevBuffer);
			data.setLastOpEquals(true);
		}
	}

	public void processOperator(
				final AbstractOperator op) {
		if (op instanceof BinaryOperator) {
			if ((lastOperator == null) || (data.isLastOpEquals())) {
				data.setBuffer(Double.parseDouble(data.getDisplay()));
				data.setInitDisplay(true);
			} else {
				lastOperator.operate(data);
			}
				lastOperator = op;
		} else if (op instanceof UnaryOperator) {
			op.operate(data);
		}
		data.setLastOpEquals(false);
	}

	public void processDigit(final String s) {
		if (data.isLastOpEquals()) {
			lastOperator = null;
		}
		if (data.isInitDisplay()) {
			if (data.isLastOpEquals()) {
				data.setBuffer(0.0);
			} else {
				data.setBuffer(Double.parseDouble(data.getDisplay()));
			}
			data.setDisplay(s);
			data.setInitDisplay(false);
		} else {
			if (data.getDisplay().indexOf(
				   CalculatorConstants.POINT) == -1) {
				data.setDisplay(data.getDisplay() + s);
			} else if (!s.equals(CalculatorConstants.POINT)) {
				data.setDisplay(data.getDisplay() + s);
			}
		}
		data.setLastOpEquals(false);
	}
}</pre>
<p>CalculatorController is instantiated with a new instance of CalculatorData . Along with the data object member, our controller also has four main actions: equals() and clear(), which are used for the calculator operations of the same names, and processOperator() and processDigit() , which are used when their respective operator buttons are clicked.</p>
<p>Controller actions, such as the pressing of a digit or an operator, update the model, which fires the corresponding events. When the data in the model changes, in response to actions from the controller, components that are registered to listen will be notified. Our view, CalculatorWidget, is one such component. The controller also contains a reference to the lastOperator so that it can make decisions about what to do in the chain of operations it provides. Figure 5 shows an overview of the classes involved in our now-complete MVC-enabled calculator project.</p>
<p><span class="inline inline-none"><img class="image image-_original" src="http://java.dzone.com/sites/all/files/images/calculator_example.jpg" alt="" width="356" height="258" /></span></p>
<p>Figure 5 Overview of the classes involved with the GWT calculator example</p>
<p>This use of CalculatorController allows our client-side application, all by its lonesome, to handle state, logic, delegation, and the use of a separate model, along with the view. It&#8217;s important to remember this expression of the MVC pattern, and where the responsibilities lie. Java developers accustomed to the request-response cycle will be used to the view being rendered in a single, generally procedural action based on a single-state model. In GWT, as in well-designed desktop applications, the model can change independently of a singular view layer. This is notably different from a more transient view that performs a single operation and then goes away. Dealing with the state of the view, not just of the model, is something you will need to keep in mind during your development.</p>
<p>Now we have an event-driven GWT calculator in the form of a reusable CalculatorWidget. In addition, our code is fairly resilient to change and is extensible because we have used an OO approach with operators responsible for their own individual operations.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/jarzone.wordpress.com/243/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/jarzone.wordpress.com/243/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jarzone.wordpress.com/243/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jarzone.wordpress.com/243/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jarzone.wordpress.com/243/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jarzone.wordpress.com/243/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jarzone.wordpress.com/243/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jarzone.wordpress.com/243/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jarzone.wordpress.com/243/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jarzone.wordpress.com/243/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jarzone.wordpress.com/243/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jarzone.wordpress.com/243/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jarzone.wordpress.com/243/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jarzone.wordpress.com/243/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jarzone.wordpress.com/243/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jarzone.wordpress.com/243/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jarzone.wordpress.com&amp;blog=3156522&amp;post=243&amp;subd=jarzone&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jarzone.wordpress.com/2008/07/23/design-patterns-and-gwt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/16e5993227472808e5f16bc598927775?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jarzone</media:title>
		</media:content>

		<media:content url="http://java.dzone.com/sites/all/files/images/mvc.jpg" medium="image" />

		<media:content url="http://java.dzone.com/sites/all/files/images/class_diagram.jpg" medium="image" />

		<media:content url="http://java.dzone.com/sites/all/files/images/observer_pattern.jpg" medium="image" />

		<media:content url="http://java.dzone.com/sites/all/files/images/strategy_pattern.jpg" medium="image" />

		<media:content url="http://java.dzone.com/sites/all/files/images/calculator_example.jpg" medium="image" />
	</item>
		<item>
		<title>My New Favorite IDE for Compiled JavaFX Script Development</title>
		<link>http://jarzone.wordpress.com/2008/03/26/my-new-favorite-ide-for-compiled-javafx-script-development/</link>
		<comments>http://jarzone.wordpress.com/2008/03/26/my-new-favorite-ide-for-compiled-javafx-script-development/#comments</comments>
		<pubDate>Wed, 26 Mar 2008 03:05:22 +0000</pubDate>
		<dc:creator>jarzone</dc:creator>
				<category><![CDATA[IDE]]></category>
		<category><![CDATA[My New Favorite IDE for Compiled JavaFX Script Developm]]></category>

		<guid isPermaLink="false">http://jarzone.wordpress.com/2008/03/26/my-new-favorite-ide-for-compiled-javafx-script-development/</guid>
		<description><![CDATA[As you may know, in order to develop compiled JavaFX Script applications, it has been necessary to compile and run from the command line.  That is no longer true, as the compiled JavaFX Script plug-in is now available for NetBeans (6.1 beta).  Here&#8217;s a screenshot of the program example (a Yahtzee dice roller and scorer) [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jarzone.wordpress.com&amp;blog=3156522&amp;post=241&amp;subd=jarzone&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>As you may know, in order to develop compiled JavaFX Script applications, it has been necessary to compile and run from the command line.  That is no longer true, as the compiled JavaFX Script plug-in is now available for NetBeans (6.1 beta).  Here&#8217;s a screenshot of the program example (a Yahtzee dice roller and scorer) for my next blog post being developed in my new favorite IDE <img src='http://s2.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p><a href="http://learnjavafx.typepad.com/photos/uncategorized/2008/03/25/netbeans_wjavafxplugin_2.png"><img src="http://learnjavafx.typepad.com/weblog/images/2008/03/25/netbeans_wjavafxplugin_2.png" alt="Netbeans_wjavafxplugin_2" border="0" height="429" width="600" /></a></p>
<p>The compiled JavaFX Script plug-in is built in the same continuous build that compiled JavaFX Script is, so updates will be available frequently.  To get both NetBeans 6.1 beta and the compiled JavaFX Script plug-in, visit the <a href="https://openjfx.dev.java.net/">OpenJFX Community site</a> and check for the <b>JavaFX Script Plugin Daily Builds Available</b> news item.</p>
<p>Enjoy!<br />
Jim Weaver<a href="http://www.amazon.com/gp/redirect.html?ie=UTF8&amp;location=http%3A%2F%2Fwww.amazon.com%2FJavaFx-Script-Scripting-client-side-Applications%2Fdp%2F1590599454&amp;tag=jmentor-20&amp;linkCode=ur2&amp;camp=1789&amp;creative=9325"><br />
JavaFX Script: Dynamic Java Scripting for Rich Internet/Client-side Applications</a><br />
Immediate eBook (PDF) download available at <a href="http://www.apress.com/book/view/1590599454">the book&#8217;s Apress site</a></p>
<p><b>Link : http://java.dzone.com/articles/my-new-favorite-ide-compiled-j</b></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/jarzone.wordpress.com/241/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/jarzone.wordpress.com/241/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jarzone.wordpress.com/241/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jarzone.wordpress.com/241/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jarzone.wordpress.com/241/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jarzone.wordpress.com/241/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jarzone.wordpress.com/241/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jarzone.wordpress.com/241/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jarzone.wordpress.com/241/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jarzone.wordpress.com/241/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jarzone.wordpress.com/241/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jarzone.wordpress.com/241/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jarzone.wordpress.com/241/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jarzone.wordpress.com/241/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jarzone.wordpress.com/241/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jarzone.wordpress.com/241/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jarzone.wordpress.com&amp;blog=3156522&amp;post=241&amp;subd=jarzone&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jarzone.wordpress.com/2008/03/26/my-new-favorite-ide-for-compiled-javafx-script-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/16e5993227472808e5f16bc598927775?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jarzone</media:title>
		</media:content>

		<media:content url="http://learnjavafx.typepad.com/weblog/images/2008/03/25/netbeans_wjavafxplugin_2.png" medium="image">
			<media:title type="html">Netbeans_wjavafxplugin_2</media:title>
		</media:content>
	</item>
		<item>
		<title>Chronos 0.2.1 beta: Database Desktop Client for Oracle and Microsoft SQL Server</title>
		<link>http://jarzone.wordpress.com/2008/03/25/chronos-021-beta-database-desktop-client-for-oracle-and-microsoft-sql-server/</link>
		<comments>http://jarzone.wordpress.com/2008/03/25/chronos-021-beta-database-desktop-client-for-oracle-and-microsoft-sql-server/#comments</comments>
		<pubDate>Tue, 25 Mar 2008 03:46:29 +0000</pubDate>
		<dc:creator>jarzone</dc:creator>
				<category><![CDATA[DBMS]]></category>
		<category><![CDATA[Chronos 0.2.1 beta: Database Desktop Client for Oracle]]></category>

		<guid isPermaLink="false">http://jarzone.wordpress.com/2008/03/25/chronos-021-beta-database-desktop-client-for-oracle-and-microsoft-sql-server/</guid>
		<description><![CDATA[Chronos is a free cross platform database tool. It currently supports Oracle and MSSQL (Sybase) and includes highlighting of Primary and Foreign keys as a major new feature in this release. * Oracle support * MSSQL and Sybase support (experimental) * Multithreading (experimental) * SQL syntax highlight * Query history * TOAD-like schema browser * [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jarzone.wordpress.com&amp;blog=3156522&amp;post=199&amp;subd=jarzone&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Chronos is a free cross platform database tool. It currently supports Oracle and MSSQL (Sybase) and includes highlighting of Primary and Foreign keys as a major new feature in this release.</p>
<p>* Oracle support<br />
* MSSQL and Sybase support (experimental)<br />
* Multithreading (experimental)<br />
* SQL syntax highlight<br />
* Query history<br />
* TOAD-like schema browser<br />
* Schema browser data filter<br />
* Primary and foreign keys highlighting (experimental)<br />
* Table creation interface (experimental)</p>
<p>Requirements:<br />
Java 6.0</p>
<p>Screenshots:<br />
<img src="http://farm3.static.flickr.com/2128/2189827858_92f7a7f607.jpg" /></p>
<p><img src="http://farm3.static.flickr.com/2028/2189052125_26c27bfb3e.jpg" /></p>
<p><b>Link : http://java.dzone.com/announcements/chronos-021-beta</b></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/jarzone.wordpress.com/199/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/jarzone.wordpress.com/199/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jarzone.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jarzone.wordpress.com/199/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jarzone.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jarzone.wordpress.com/199/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jarzone.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jarzone.wordpress.com/199/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jarzone.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jarzone.wordpress.com/199/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jarzone.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jarzone.wordpress.com/199/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jarzone.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jarzone.wordpress.com/199/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jarzone.wordpress.com/199/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jarzone.wordpress.com/199/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jarzone.wordpress.com&amp;blog=3156522&amp;post=199&amp;subd=jarzone&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jarzone.wordpress.com/2008/03/25/chronos-021-beta-database-desktop-client-for-oracle-and-microsoft-sql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/16e5993227472808e5f16bc598927775?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jarzone</media:title>
		</media:content>

		<media:content url="http://farm3.static.flickr.com/2128/2189827858_92f7a7f607.jpg" medium="image" />

		<media:content url="http://farm3.static.flickr.com/2028/2189052125_26c27bfb3e.jpg" medium="image" />
	</item>
	</channel>
</rss>
