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

<channel>
	<title>Sam&#039;s occasional tech thinkings &#187; java</title>
	<atom:link href="http://www.ziazoo.co.uk/blog/category/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ziazoo.co.uk/blog</link>
	<description>I wish I got it right more!</description>
	<lastBuildDate>Wed, 12 May 2010 13:05:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1-alpha-15359</generator>
		<item>
		<title>Looking towards declarative interfaces in GWT</title>
		<link>http://www.ziazoo.co.uk/blog/2009/06/07/looking-towards-declarative-interfaces-in-gwt/</link>
		<comments>http://www.ziazoo.co.uk/blog/2009/06/07/looking-towards-declarative-interfaces-in-gwt/#comments</comments>
		<pubDate>Sun, 07 Jun 2009 10:25:43 +0000</pubDate>
		<dc:creator>sammy</dc:creator>
				<category><![CDATA[RIA]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[gwt]]></category>
		<category><![CDATA[wave]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.ziazoo.co.uk/blog/?p=112</guid>
		<description><![CDATA[I have been doing some work with GWT lately, and there is a lot I really like about it. Developing in Java (or any OO language) not only makes me more productive, it enables me to solve problems in the way I understand, without having first to grapple with how another language requires me to [...]]]></description>
			<content:encoded><![CDATA[<p>I have been doing some work with <a href="http://code.google.com/webtoolkit/">GWT</a> lately, and there is a lot I really like about it. Developing in Java (or any OO language) not only makes me more productive, it enables me to solve problems in the way I understand, without having first to grapple with how another language requires me to think.  The output is awesome since its rendered natively in the browser, making it fast, and familiar.  Basically there is a lot I really like about GWT, and I&#8217;m going to be using it wherever I get a chance from now on, but that not to say its all good.</p>
<h4>Mini Gripe</h4>
<p>I do have a mini gripe with the current implementation (well maybe I&#8217;ll have a few, but this one stands out), it&#8217;s the way interfaces are described in Java.  For all Java&#8217;s benefits, it remains a verbose language, and developing UI structure with it looks clumsy and hard to maintain, in fact I know it is.  I can say that with some confidence since development  in GWT is almost identical to <a href="http://www.adobe.com/products/flex/">Flex</a> development.</p>
<p>In Flex, if you try to develop all your interface in actionscript you end up in a similar situation. Classes quickly become very large (huge createChildren methods) as many nested components are instantiated and associated with one another.  Fortunately this can be avoided in Flex, as its is better practice to construct your layout using xml, leaving the declarative part of interface development in the language that suits it.  Xml is not just better for interface development because its declarative, it also lends itself to input from other disciplines since many types of developers and designer are used to html as the language of website structure.</p>
<h4>Gripe Solved (soon)</h4>
<p>That&#8217;s not the end of the story, as I learnt from the <a href="http://code.google.com/events/io/sessions/GoogleWaveUnderTheHood.html">Google Wave: Under the Hood</a> video, where a project named UiBinder is briefly mentioned.  The project sounded like exactly what I am after, and means of defining <a href="http://code.google.com/webtoolkit/">GWT</a> interface in xml.  After a little hunting I found this <a href="http://code.google.com/p/google-web-toolkit-incubator/wiki/UiBinder">document</a> and this <a href="http://groups.google.co.uk/group/Google-Web-Toolkit-Contributors/browse_thread/thread/4539b203c2aba4ad?">post</a>.  Which explain <strong>what</strong> UiBinder is and importantly <strong>where</strong> it is (currently only internal to Google, though shortly to be released to you and me, w00).</p>
<h4>UiBinder, briefly</h4>
<p>UiBinder, according to the docs is a &#8220;<em>service to generate Widget and DOM structures from XML markup</em>&#8220;.  Which after reading the proposal (the document is a proposal for UiBinder as a GWT feature) I figured out basically means it does exactly what I was hoping.  So how does it work?</p>
<p>(I&#8217;ve taken the code below out of the proposal document since I cant yet try this myself. humph)</p>
<p>First the interface is defined using XML</p>
<pre name="code" class="xml">&lt;!-- HelloWorld.ui.xml --&gt;
&lt;ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'&gt;
  &lt;div&gt;
    Hello, &lt;span ui:field='nameSpan'/&gt;.
  &lt;/div&gt;
&lt;/ui:UiBinder&gt;</pre>
<p>This describes the interface for a a classic hello world component.  What I particularly like about the approach is how this file is then used from the Java, there are no nasty inline script tags or clumsy code behind super classes.  The template xml file is bound to the Java class explicitly.</p>
<pre name="code" class="java">public class HelloWorld extends UIObject {

  interface MyUiBinder extends UiBinder{}
  private static MyUiBinder uiBinder = GWT.create(MyUiBinder.class);

  @UiField SpanElement nameSpan;

  public HelloWorld(String name) {
    setElement(uiBinder.createAndBindUi(this));
    nameSpan.setInnerText(name);
  }
}</pre>
<p>The first line of the constructor is the interesting one, the <code>UiBinder</code> method <code>createAndBindUi</code> is called passing in <code>this</code> as the argument.  This constructs your UI components and assigns them to corresponding private variables within the class, making the next line where the text is assigned to the span possible without ever having to directly construct the <code>SpanElement</code> within the java.</p>
<p>What you end up with is a very elegant separation of layout from logic.  Cant wait to get my hands on it!</p>
<p>If you don&#8217;t have much patience there are other options, if you take a look to the bottom of the UiBinder proposal there are some links to similar projects at the bottom, though I&#8217;ve yet to look into them.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ziazoo.co.uk/blog/2009/06/07/looking-towards-declarative-interfaces-in-gwt/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>BlazeDS with Spring</title>
		<link>http://www.ziazoo.co.uk/blog/2008/01/14/blazeds-with-spring/</link>
		<comments>http://www.ziazoo.co.uk/blog/2008/01/14/blazeds-with-spring/#comments</comments>
		<pubDate>Mon, 14 Jan 2008 14:25:48 +0000</pubDate>
		<dc:creator>sammy</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[blazeds]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.ziazoo.co.uk/blog/index.php/2008/01/14/blazeds-with-spring/</guid>
		<description><![CDATA[With the release of BlazeDS from Adobe building your business logic in java just became a lot more accessible! In this post I&#8217;m going show the basics of setting up a Java, spring based application, then connecting to it from Flex via the flex.messaging.factory.SpringFactory . I&#8217;m going to keep the the domain (business logic) as [...]]]></description>
			<content:encoded><![CDATA[<p>With the release of BlazeDS from Adobe building your business logic in java just became a lot more accessible! In this post I&#8217;m going show the basics of setting up a Java, spring based application, then connecting to it from Flex via the <code>flex.messaging.factory.SpringFactory</code> .  I&#8217;m going to keep the the domain (business logic) as simple as possible, and I&#8217;m not going to be persisting anything to a database.  This is so I don&#8217;t get bogged down in details and can get straight to the point&#8230; connecting Flex to Java/Spring with BlazeDS&#8230;. so here we go!<strong> </strong></p>
<p><strong>What you&#8217;ll need.</strong></p>
<ul>
<li><a href="http://labs.adobe.com/technologies/blazeds/" target="_blank">BlazeDS</a></li>
<li><a href="http://www.springframework.org/" target="_blank">Spring Framework</a> (I&#8217;ve used 2.5)</li>
<li><a href="http://labs.adobe.com/technologies/flex/sdk/flex3sdk.html" target="_blank">Flex 3.0 </a>(I&#8217;ll be using Flex Builder, but you are free to just use the SDK)</li>
<li><a href="http://www.eclipse.org/" target="_blank">Eclipse</a> with <a href="http://springide.org/blog/" target="_blank">Spring IDE plugin</a></li>
<li><a href="http://www.igenko.org/archiva/repository/igenko/com/adobe/flex/blazeds-spring/beta1/blazeds-spring-beta1.jar" title="blaze-spring">blazeds-spring-beta1.jar</a></li>
</ul>
<p><strong>The Steps!</strong></p>
<p><strong>Creating The Java  </strong></p>
<ol>
<li>Create a Spring project in eclipse named BlogExample and set the output folder to be war/WEB-INF/classes.</li>
<li>Find the directory you unzipped the BlazeDS download into and navigate to the following directory {blaze install dir}/tomcat/webapps/blazeds/</li>
<li>copy the contents of this directory into the new project (you should have copied two folders, called WEB-INF and META-INF.  These folders contain the necessary libraries and config files for connecting to Java from Flex)</li>
<li> Copy spring.jar file from {Spring unzip directory}/dist/ into the war/WEB-INF/lib directory of the project.  <em>The project now contains all the necessary library&#8217;s to connect Flex to Java.  However as we are using Spring we will still need one more jar file which we will get in step 9</em></li>
<li>Next you need to create your business logic, I have created a very simple POJO called SimpleBook.java, which contains two properties with getters and setters (you can download the complete project here which contains this simple class).</li>
<li>Create a new Spring Bean Definition File called beans.xml inside the WEB-INF directory.</li>
<li>Add the following lines to the new beans.xml file, it tells spring to instantiate SimpleBook and set its properties<em><br />
&lt;bean id=&#8221;myBook&#8221; class=&#8221;uk.co.ziazoo.example.domain.SimpleBook&#8221;&gt;<br />
&lt;property name=&#8221;name&#8221; value=&#8221;my book&#8221; /&gt;<br />
&lt;/bean&gt;</em></li>
<li>Next we need to edit the services-config.xml and remoting-config.xml so that flex can connect to the application.  Your can download mine from here (<a href="http://www.ziazoo.co.uk/blog/wp-content/uploads/2008/01/remoting-config.xml" title="remoting-config.xml">remoting-config.xml</a>, <a href="http://www.ziazoo.co.uk/blog/wp-content/uploads/2008/01/services-config.xml" title="services-config.xml">services-config.xml</a>). Be sure to change the endpoint in the services-config.xml to point to your local tomcat server.  I have used the tomcat that come with the BlazeDS download as it comes pre-configured to work with BlazeDS.</li>
<li>If you take a look within the services-config.xml you will see I am referencing a class named flex.messaging.factory.SpringFactory  which doesn&#8217;t currently exist in the project. We can get this file thanks to http://www.igenko.org&#8230; here <a href="http://www.igenko.org/archiva/repository/igenko/com/adobe/flex/blazeds-spring/beta1/blazeds-spring-beta1.jar" title="blaze-spring">blazeds-spring-beta1.jar</a></li>
<li>Once you have downloaded the blaze-spring-beta1.jar just copy it into the war/WEB-INF/lib folder</li>
<li>Next its time to configure the web.xml file.  The web.xml file that come with BlazeDS needs a little tweaking to get it to work with our spring app.  Firstly the included file uses the older DTD based syntax, we need to change this to the newer XML scheme method.  Once we have done that we need to change the &lt;listener&gt; property such that it fits the spring based development ideas. (The changes essentially allow Spring to instantiate the business classes, rather than letting Flex do it&#8230; this is crucial to the whole idea of Spring, and its called IoC, Inversion of Control). Once that changes are made the web.xml file should look like this <a href="http://www.ziazoo.co.uk/blog/wp-content/uploads/2008/01/web.xml" title="web.xml">web.xml</a></li>
<li>The Java code is now complete, all that remains is to deploy it to the tomcat server, I have done this using Ant, blogging how to setup Ant and starting tomcat are all fairly in depth and very dependent on the system they are being installed on, so I&#8217;ll keep quite on that.  If you are stuck I recommend reading the build.properties and build.xml files in my project.</li>
</ol>
<p><strong> The Flex</strong></p>
<p>I am using Flex Builder 3.0, so these steps will vary for other IDS etc</p>
<ol>
<li>Create a new project and select the application type J2EE</li>
<li>Set the root folder to to the context root of the java app withing tomcat ie /Users/Sam/Documents/blazeds_b1_121307/tomcat/webapps/blogexample</li>
<li>Replace the contents of the main mxml file with the follow <a href="http://www.ziazoo.co.uk/blog/wp-content/uploads/2008/01/hohumm1.mxml.xml" title="main.mxml">main.mxml</a></li>
<li>Run the flex app.. and you should see the following<a href="http://www.ziazoo.co.uk/blog/wp-content/uploads/2008/01/picture-4.png" title="Result"><br />
</a><a href="http://www.ziazoo.co.uk/blog/wp-content/uploads/2008/01/picture-4.png" title="Result"><img src="http://www.ziazoo.co.uk/blog/wp-content/uploads/2008/01/picture-4.thumbnail.png" alt="Result" /><br />
</a></li>
</ol>
<p>And thats your lot!!!  <img src='http://www.ziazoo.co.uk/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>OOPS&#8230; forgot to upload the full Java code&#8230; here ya go <a href="http://www.ziazoo.co.uk/blog/wp-content/uploads/2008/01/blogexample.zip" title="Java code">Java code</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ziazoo.co.uk/blog/2008/01/14/blazeds-with-spring/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>
