<?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>First Zero</title>
	<atom:link href="http://www.firstzero.co.uk/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.firstzero.co.uk</link>
	<description>Undercover Junk to Developing and Stuff</description>
	<lastBuildDate>Sun, 25 Dec 2011 17:18:58 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>node.js and socket.io</title>
		<link>http://www.firstzero.co.uk/2011/12/node-js-and-socket-io/</link>
		<comments>http://www.firstzero.co.uk/2011/12/node-js-and-socket-io/#comments</comments>
		<pubDate>Sun, 25 Dec 2011 14:51:48 +0000</pubDate>
		<dc:creator>fz</dc:creator>
				<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://www.firstzero.co.uk/?p=92</guid>
		<description><![CDATA[<p><a href="http://www.firstzero.co.uk/wp-content/uploads/2011/12/nodejs_logo.png"></a>There is something visceral to code a server and getting it to run. <a title="node.js" href="http://nodejs.org/" target="_blank">node.js</a> is just that, an unassuming ferocity that draws developers in.</p> <p>The Node beginner book &#8211; <a href="http://www.nodebeginner.org/" title="http://www.nodebeginner.org/" target="_blank">http://www.nodebeginner.org/</a>, helps developers take the first baby steps. </p> <p>This post is meant for people who have gone past [...]]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.firstzero.co.uk/wp-content/uploads/2011/12/nodejs_logo.png"><img src="http://www.firstzero.co.uk/wp-content/uploads/2011/12/nodejs_logo.png" alt="" title="nodejs_logo" width="212" height="114" class="alignleft size-full wp-image-119" /></a>There is something visceral to code a server and getting it to run. <a title="node.js" href="http://nodejs.org/" target="_blank">node.js</a> is just that, an unassuming ferocity that draws developers in.</p>
<p>The Node beginner book &#8211; <a href="http://www.nodebeginner.org/" title="http://www.nodebeginner.org/" target="_blank">http://www.nodebeginner.org/</a>, helps developers take the first baby steps. </p>
<p>This post is meant for people who have gone past that and want to do a realtime <a title="socket.io" href="http://socket.io" target="_blank">socket.io</a> program.</p>
<p>Why <code>socket.io</code> &#8211; Ever wanted to send realtime data to all the people connected in any language &#8211; its like walking on broken glass. You have solutions like <code>cometd</code> or <code>mq</code>, which involves setting up an application on the server and then setting up something on the client and then figuring why your config doesn&#8217;t work, or it&#8217;s only supported on 1 platform *shudder*</p>
<p>What we are going to do here is put together a simple program to send time to all the clients connected to the server &#8211; with very few lines of code. I have assumed you have installed node.js already and rubbing your hands together&#8230; and created an empty directory to get started.</p>
<p>I have used the directory created is called <code>/tmp/foo</code></p>
<p>First you will need to install <a href="http://socket.io" title="socket.io" target="_blank">socket.io</a> and <a href="http://expressjs.com/" title="express" target="_blank">express</a></p>
<pre class="brush: bash">
cd /tmp/foo
npm install express socket.io
</pre>
<p>You should see</p>
<pre class="brush: bash">
npm http GET https://registry.npmjs.org/express
npm http GET https://registry.npmjs.org/socket.io
.
.
express@2.5.2 ./node_modules/express
├── mkdirp@0.0.7
├── qs@0.4.0
├── mime@1.2.4
└── connect@1.8.5
socket.io@0.8.7 ./node_modules/socket.io
├── policyfile@0.0.4
├── redis@0.6.7
└── socket.io-client@0.8.7
</pre>
<p>Nice and dandy, you should see under <code>/tmp/foo</code> a directory called <code>node_modules</code> with <code>socket.io</code> and <code>express</code></p>
<pre class="brush: bash">
parj@ubuntu:/tmp/foo$ ll node_modules/
total 20
drwxr-xr-x 5 parj parj 4096 2011-12-25 14:44 ./
drwxr-xr-x 3 parj parj 4096 2011-12-25 14:44 ../
drwxr-xr-x 2 parj parj 4096 2011-12-25 14:44 .bin/
drwxr-xr-x 6 parj parj 4096 2011-12-25 14:44 express/
drwxr-xr-x 7 parj parj 4096 2011-12-25 14:44 socket.io/
</pre>
<p>But wait, what if you have several projects and all using <code>socket.io</code> and <code>express</code>. If any component gets updated how are you going to deal with that? Update every project individually. There is a better solution &#8211; use <code>npm link</code>. </p>
<blockquote><p> NOTE:This section about symbolic linking does not work on Windows &#8211; This is because the file system does not support symbolic links.</p></blockquote>
<pre class="brush: bash">
npm install -g socket.io express #Install globally
cd /tmp/foo
rm -rf node_modules
npm link express socket.io
</pre>
<p>Now if you do a listing, it shows that symbolic links have been created for the modules</p>
<pre class="brush: bash">

parj@ubuntu:/tmp/foo$ ll node_modules/
total 12
drwxr-xr-x 3 parj parj 4096 2011-12-25 14:48 ./
drwxr-xr-x 3 parj parj 4096 2011-12-25 14:48 ../
drwxr-xr-x 2 parj parj 4096 2011-12-25 14:48 .bin/
lrwxrwxrwx 1 parj parj 52 2011-12-25 14:48 express -&gt; /opt/node/lib/node_modules/express/
lrwxrwxrwx 1 parj parj 54 2011-12-25 14:48 socket.io -&gt; /opt/node/lib/node_modules/socket.io/
</pre>
<p>Create <strong>server.js</strong> under <code>/tmp/foo</code> and paste the following &#8211; Code is also available on <a href="https://github.com/parj/node-websocket-demo" title="https://github.com/parj/node-websocket-demo" target="_blank">https://github.com/parj/node-websocket-demo</a></p>
<blockquote><p>
Tip: For copying and pasting code, just hover over the code you should see <> sign, click that and that will popup a dialog with unescaped HTML code, so when you copy &#038; paste, there are no surprises
</p></blockquote>
<pre class="brush: javascript">
var http = require(&#039;http&#039;),
io = require(&#039;socket.io&#039;),
sys = require(&#039;sys&#039;),
express = require(&#039;express&#039;);

var port = 8111;   //The port to listen on

var server = express.createServer();  //Create server app
server.use(express.static(__dirname + &#039;/public&#039;));   //The directory in which static files would be stored, js, images
server.use(express.errorHandler({showStack: true, dumpExceptions: true}));  //Show exceptions
server.listen(port);     //Start the server

var socket = io.listen(server);  //socket.io listen

//When a client connects
socket.sockets.on(&#039;connection&#039;, function(client){
  //Set connected flag true
  var connected = true;

  //Upon receiving a message type it out to the console
  client.on(&#039;message&#039;, function(m){
    sys.log(&#039;Message received: &#039;+m);
  });

  //Upon disconnecting set connected flag to flase
  client.on(&#039;disconnect&#039;, function(){
    connected = false;
  });

  //Get the time every second and publish
  var tick = function(){
    if (!connected) {
      return;
    }

    var dateTime = new Date();
    var msg = dateTime.getHours() + &quot;:&quot; + dateTime.getMinutes() + &quot;:&quot; + dateTime.getSeconds();

    console.log(&quot;Sending &quot; + dateTime);
    client.send(msg);    //Send using socket.io to the client
    setTimeout(tick, 1000);  //Wait 1 second before redoing
  };
  
  tick();
});
</pre>
<p>Create a folder called <strong>public</strong> under <code>/tmp/foo</code> and under that create <strong>main.js</strong> &#8211; the client which will connect and get the messages</p>
<pre class="brush: javascript">
var socket = io.connect();    //Can be left blank as host and port will be autodetected

socket.on(&#039;connect&#039;, function(){
  $(&#039;#status&#039;).text(&#039;Connected&#039;);
});

socket.on(&#039;message&#039;, function(m){
  $(&#039;#message&#039;).text(m);
});

socket.on(&#039;disconnect&#039;, function(){
  $(&#039;#status&#039;).text(&#039;Disconnected&#039;);
});
</pre>
<p>Create under <code>/tmp/foo/public</code>, <strong>index.html</strong></p>
<pre class="brush: html">
&lt;!DOCTYPE html&gt;
&lt;html&gt;
  &lt;head&gt;
    &lt;script src=&quot;/jquery.min.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;/socket.io/socket.io.js&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;/main.js&quot;&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;h1&gt;WebSocket Test&lt;/h1&gt;
    &lt;h2&gt;Status: &lt;span id=&quot;status&quot;&gt;Waiting&lt;/span&gt;&lt;/h2&gt;
    &lt;pre id=&quot;message&quot;&gt;&lt;/pre&gt;
  &lt;/body&gt;
&lt;/body&gt;
</pre>
<p>Finally, download <a href="http://jquery.com/" target="_blank">jquery</a> and place the file in <code>/tmp/foo/public</code> &#8211; ensure the file is named <strong>jquery.min.js</strong>.</p>
<p>&#8230;.</p>
<p>Start the server</p>
<pre class="brush: bash">
cd /tmp/foo
node server.js
</pre>
<p>You will get</p>
<pre class="brush: bash">

parj@ubuntu:/tmp/foo$ node server.js 
The &quot;sys&quot; module is now called &quot;util&quot;. It should have a similar interface.
   info  - socket.io started
</pre>
<p>Open a browser (Chrome, Firefox) and head to <a href="http://localhost:8111/" title="http://localhost:8111/" target="_blank">http://localhost:8111/</a></p>
<p>On the server you should see</p>
<pre class="brush: bash">

parj@ubuntu:/tmp/foo$ node server.js 
The &quot;sys&quot; module is now called &quot;util&quot;. It should have a similar interface.
   info  - socket.io started
   debug - client authorized
   info  - handshake authorized 1465125961783431727
   debug - setting request GET /socket.io/1/websocket/1465125961783431727
   debug - set heartbeat interval for client 1465125961783431727
   debug - client authorized for 
   debug - websocket writing 1::
Sending Sun Dec 25 2011 16:45:30 GMT+0000 (GMT)
   debug - websocket writing 3:::16:45:30
Sending Sun Dec 25 2011 16:45:31 GMT+0000 (GMT)
   debug - websocket writing 3:::16:45:31
Sending Sun Dec 25 2011 16:45:32 GMT+0000 (GMT)
   debug - websocket writing 3:::16:45:32
Sending Sun Dec 25 2011 16:45:33 GMT+0000 (GMT)
   debug - websocket writing 3:::16:45:33
</pre>
<p>On the client in the browser, you should see status connected and the time moving</p>
<pre class="brush: bash">
WebSocket Test

Status: Connected

16:46:20
</pre>
<p>If you want to check out the code and play around with it</p>
<pre class="brush: bash">
git clone git://github.com/parj/node-websocket-demo.git
</pre>
<p>PS: Please note no badgers where harmed in writing this code&#8230;<br />
PPS: The same could not be said for the keyboard and the network packets involved..</p>
]]></content:encoded>
			<wfw:commentRss>http://www.firstzero.co.uk/2011/12/node-js-and-socket-io/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ilford Church</title>
		<link>http://www.firstzero.co.uk/2011/10/ilford-church/</link>
		<comments>http://www.firstzero.co.uk/2011/10/ilford-church/#comments</comments>
		<pubDate>Sun, 30 Oct 2011 10:00:10 +0000</pubDate>
		<dc:creator>fz</dc:creator>
				<category><![CDATA[Photos (Wallpapers)]]></category>

		<guid isPermaLink="false">http://www.firstzero.co.uk/?p=89</guid>
		<description><![CDATA[<p><a href="http://www.firstzero.co.uk/wp-content/uploads/2011/10/DSC_0293.jpg"></a>Church outside Ilford Shopping Mall</p>]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.firstzero.co.uk/wp-content/uploads/2011/10/DSC_0293.jpg"><img src="http://www.firstzero.co.uk/wp-content/uploads/2011/10/DSC_0293-300x200.jpg" alt="" title="Ilford Church - 1" width="300" height="200" class="alignleft size-medium wp-image-88" /></a>Church outside Ilford Shopping Mall</p>
]]></content:encoded>
			<wfw:commentRss>http://www.firstzero.co.uk/2011/10/ilford-church/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Comic Con 2011 &#8211; London</title>
		<link>http://www.firstzero.co.uk/2011/10/comic-con-2011-london/</link>
		<comments>http://www.firstzero.co.uk/2011/10/comic-con-2011-london/#comments</comments>
		<pubDate>Sun, 30 Oct 2011 09:33:50 +0000</pubDate>
		<dc:creator>fz</dc:creator>
				<category><![CDATA[Photos (Wallpapers)]]></category>

		<guid isPermaLink="false">http://www.firstzero.co.uk/?p=66</guid>
		<description><![CDATA[<p><a href="http://www.firstzero.co.uk/wp-content/uploads/2011/10/DSC_0397.jpg"></a><a href="http://www.firstzero.co.uk/wp-content/uploads/2011/10/DSC_0396.jpg"></a><a href="http://www.firstzero.co.uk/wp-content/uploads/2011/10/DSC_0395.jpg"></a><a href="http://www.firstzero.co.uk/wp-content/uploads/2011/10/DSC_0394.jpg"></a><a href="http://www.firstzero.co.uk/wp-content/uploads/2011/10/DSC_0393.jpg"></a><a href="http://www.firstzero.co.uk/wp-content/uploads/2011/10/DSC_0392.jpg"></a></p>]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.firstzero.co.uk/wp-content/uploads/2011/10/DSC_0397.jpg"><img src="http://www.firstzero.co.uk/wp-content/uploads/2011/10/DSC_0397-300x200.jpg" alt="" title="DSC_0397" width="300" height="200" class="alignleft size-medium wp-image-85" /></a><a href="http://www.firstzero.co.uk/wp-content/uploads/2011/10/DSC_0396.jpg"><img src="http://www.firstzero.co.uk/wp-content/uploads/2011/10/DSC_0396-300x200.jpg" alt="" title="DSC_0396" width="300" height="200" class="alignleft size-medium wp-image-84" /></a><a href="http://www.firstzero.co.uk/wp-content/uploads/2011/10/DSC_0395.jpg"><img src="http://www.firstzero.co.uk/wp-content/uploads/2011/10/DSC_0395-300x200.jpg" alt="" title="DSC_0395" width="300" height="200" class="alignleft size-medium wp-image-83" /></a><a href="http://www.firstzero.co.uk/wp-content/uploads/2011/10/DSC_0394.jpg"><img src="http://www.firstzero.co.uk/wp-content/uploads/2011/10/DSC_0394-300x200.jpg" alt="" title="DSC_0394" width="300" height="200" class="alignleft size-medium wp-image-82" /></a><a href="http://www.firstzero.co.uk/wp-content/uploads/2011/10/DSC_0393.jpg"><img src="http://www.firstzero.co.uk/wp-content/uploads/2011/10/DSC_0393-300x200.jpg" alt="" title="DSC_0393" width="300" height="200" class="alignleft size-medium wp-image-81" /></a><a href="http://www.firstzero.co.uk/wp-content/uploads/2011/10/DSC_0392.jpg"><img src="http://www.firstzero.co.uk/wp-content/uploads/2011/10/DSC_0392-300x200.jpg" alt="" title="Comic Con Car - 1" width="300" height="200" class="alignleft size-medium wp-image-80" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.firstzero.co.uk/2011/10/comic-con-2011-london/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bangalore Rooftop Panorama</title>
		<link>http://www.firstzero.co.uk/2011/05/bangalore-rooftop-panorama/</link>
		<comments>http://www.firstzero.co.uk/2011/05/bangalore-rooftop-panorama/#comments</comments>
		<pubDate>Sun, 01 May 2011 17:04:46 +0000</pubDate>
		<dc:creator>fz</dc:creator>
				<category><![CDATA[Photos (Wallpapers)]]></category>
		<category><![CDATA[bangalore]]></category>
		<category><![CDATA[Barcelona]]></category>
		<category><![CDATA[Panorama]]></category>
		<category><![CDATA[Photo]]></category>

		<guid isPermaLink="false">http://www.firstzero.co.uk/?p=46</guid>
		<description><![CDATA[<p><a href="http://www.firstzero.co.uk/wp-content/uploads/2011/05/Banagalore_2.jpg"></a></p> <p>Shot outside my friend&#8217;s flat in Bangalore</p>]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.firstzero.co.uk/wp-content/uploads/2011/05/Banagalore_2.jpg"><img class="aligncenter size-large wp-image-47" title="Banagalore_2" src="http://www.firstzero.co.uk/wp-content/uploads/2011/05/Banagalore_2-1024x328.jpg" alt="" width="1024" height="328" /></a></p>
<p>Shot outside my friend&#8217;s flat in Bangalore</p>
]]></content:encoded>
			<wfw:commentRss>http://www.firstzero.co.uk/2011/05/bangalore-rooftop-panorama/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reflection in Groovy</title>
		<link>http://www.firstzero.co.uk/2011/04/reflection-in-groovy/</link>
		<comments>http://www.firstzero.co.uk/2011/04/reflection-in-groovy/#comments</comments>
		<pubDate>Fri, 29 Apr 2011 12:21:42 +0000</pubDate>
		<dc:creator>fz</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[groovy]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[reflection]]></category>

		<guid isPermaLink="false">http://undercoverjunk.wordpress.com/?p=18</guid>
		<description><![CDATA[<p>I wanted to dynamically load a class at runtime and run a function specified in the argument in groovy.</p> <p>Example&#160; ./run.sh Utilities.uptime <p>To get that to work,</p> Read in the argument from the command prompt String classFunctionName = args[0] logger.trace(&#34;classFunctionName - &#34; + classFunctionName) Split the name of class and function //Split the name of [...]]]></description>
				<content:encoded><![CDATA[<p>I wanted to dynamically load a class at runtime and run a function specified in the argument in groovy.</p>
<p>Example&nbsp;
<pre class="brush: bash">./run.sh Utilities.uptime</pre>
<p>To get that to work,</p>
<ol>
<li>Read in the argument from the command prompt</li>
<pre class="brush: groovy">String classFunctionName = args[0]
logger.trace(&quot;classFunctionName - &quot; + classFunctionName)
</pre>
<li>Split the name of class and function</li>
<pre class="brush: groovy">//Split the name of class and function
String[] split=classFunctionName.split(&quot;\.&quot;)
String className = split[0]
logger.trace(&quot;className - &quot; + className)

//Name of function
String action = split[1]
logger.trace(&quot;action - &quot; + action)
</pre>
<li>Dynamically looked up the function</li>
<pre class="brush: groovy">//Dynamically load class
Utilities.environment = Class.forName(environmentName)
logger.trace(Utilities.environment.toString())

def classAction = Class.forName(className)
logger.trace(classAction.toString())
</pre>
<li>Finally invoked it</li>
<pre class="brush: groovy">logger.trace(&quot;About to run &quot; + classAction + &quot;.&quot; + action + &quot;()&quot;)

classAction.&quot;${action}&quot;()

logger.trace(&quot;Completed &quot; + classAction + &quot;.&quot; + action + &quot;()&quot;)</pre>
<li>If an argument had to provided Example
<pre class="brush: bash"> ./run.sh test &quot;ABC D&quot;</pre>
<p>the code was modified very slightly</p>
</li>
<pre class="brush: groovy">//If arguments are passed - Example  ./run.sh test &quot;ABC D&quot;
if (args.size() &gt; 1) {
	String arguments = args[1]

	logger.trace(&quot;About to run &quot; + classAction + &quot;.&quot; + action + &quot;(&quot; + arguments + &quot;)&quot;)

	//Dynamically call function
	classAction.&quot;${action}&quot;(arguments)

	logger.trace(&quot;Completed &quot; + classAction + &quot;.&quot; + action + &quot;(&quot; + arguments + &quot;)&quot;)
}
</pre>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.firstzero.co.uk/2011/04/reflection-in-groovy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using AJAX in GRAILS</title>
		<link>http://www.firstzero.co.uk/2011/04/using-ajax-in-grails/</link>
		<comments>http://www.firstzero.co.uk/2011/04/using-ajax-in-grails/#comments</comments>
		<pubDate>Fri, 29 Apr 2011 11:34:10 +0000</pubDate>
		<dc:creator>fz</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[autocomplete]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[realtime]]></category>
		<category><![CDATA[submitToRemote]]></category>

		<guid isPermaLink="false">http://undercoverjunk.wordpress.com/?p=8</guid>
		<description><![CDATA[<p>The first step is to define a function in the controller you wish to invoke. For example, in my controller called RunnerController.groovy I defined the following</p> <p>- RunnerController.groovy</p> def printIt = { for (String e in params[&#039;runnersList&#039;].iterator()) { def runnerInstance = Runner.get(e) println runnerInstance.lastName + &#34;, &#34; + runnerInstance.firstName } redirect(action: &#34;index&#34;, params:params) } <p>Next,- [...]]]></description>
				<content:encoded><![CDATA[<p>The first step is to define a function in the controller you wish to invoke. For example, in my controller called RunnerController.groovy I defined the following</p>
<p><strong>- RunnerController.groovy</strong></p>
<pre class="brush: groovy">def printIt = { 
	for (String e in params[&#039;runnersList&#039;].iterator()) { 
		def runnerInstance = Runner.get(e) 
		println runnerInstance.lastName + &quot;, &quot; + runnerInstance.firstName 
	} 
	redirect(action: &quot;index&quot;, params:params) }</pre>
<p>Next,<strong>- views/index.gsp</strong></p>
<pre class="brush: html">&lt;g:submitToRemote id=&quot;buttonSubmit&quot; 
name=&quot;buttonSubmit&quot; 
controller=&quot;environment&quot; 
action=&quot;runIt&quot;
value=&quot;GO!&quot; 
before=&quot;hideSubmit()&quot; 
onComplete=&quot;showSubmit()&quot;&gt;&lt;/g:submitToRemote&gt;</pre>
<hr />
<p>However, if you want your webpage to keep refreshing automatically say for a web page.</p>
<p>Edit the following files</p>
<p><strong>- main.gsp</strong> &#8211; To allow the onLoad function to be propagated, otherwise the onLoad will disappear</p>
<pre class="brush: javascript">&lt;body onload=&quot;${pageProperty(name:&#039;body.onload&#039;)}&quot;&gt;</pre>
<p>Lastly, <strong>- index.gsp</strong></p>
<pre class="brush: javascript">function readLogFile() {
	var datafile = window.location.href.substring(0, window.location.href.lastIndexOf(&quot;/&quot;) + 1) + &quot;someLog.log&quot;
	var elLog = document.getElementById(&quot;txtLog&quot;);

	var xmlhttp = getXMLHTTP();
	xmlhttp.open(&quot;GET&quot;, datafile, true);

	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 &amp;&amp; xmlhttp.status == 200) { 

			//To prevent the textbook from continuosly scrolling , 
			//if nothing has changed, do not refresh
			if (elLog.value != xmlhttp.responseText) {
				//Set the log
				elLog.value = xmlhttp.responseText;
			}
		}
	}

	//To send a request
	xmlhttp.send(null);

	//To automatically refresh every 100 milliseconds
	setTimeout(&quot;readLogFile()&quot;,100);
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.firstzero.co.uk/2011/04/using-ajax-in-grails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Interference between JQuery and Prototype in Grails</title>
		<link>http://www.firstzero.co.uk/2011/04/interference-between-jquery-and-prototype-in-grails/</link>
		<comments>http://www.firstzero.co.uk/2011/04/interference-between-jquery-and-prototype-in-grails/#comments</comments>
		<pubDate>Fri, 29 Apr 2011 11:25:37 +0000</pubDate>
		<dc:creator>fz</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[autocomplete]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[grails]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[protoype]]></category>
		<category><![CDATA[realtime]]></category>
		<category><![CDATA[submitToRemote]]></category>

		<guid isPermaLink="false">http://undercoverjunk.wordpress.com/?p=4</guid>
		<description><![CDATA[<p><a href="http://www.firstzero.co.uk/wp-content/uploads/2011/04/DSC00466.jpg"></a></p> <p>&#160;<br /> So how did I reach this conclusion. To replicate the issue</p> In Grails, prototype.js is needed for AJAX calls. You declare in HTML/HEAD &#60;g:javascript library=&#34;prototype&#34;&#62;&#60;/g:javascript&#62; Then create your remote AJAX request &#60;g:submitToRemote id=&#34;buttonSubmit&#34; name=&#34;buttonSubmit&#34; controller=&#34;test&#34; action=&#34;echoIt&#34; value=&#34;GO!&#34; before=&#34;hide()&#34; onComplete=&#34;show()&#34;&#62;&#60;/g:submitToRemote&#62; It all works! I wanted an autocomplete JQuery, so I downloaded from [...]]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.firstzero.co.uk/wp-content/uploads/2011/04/DSC00466.jpg"><img src="http://www.firstzero.co.uk/wp-content/uploads/2011/04/DSC00466-1024x768.jpg" alt="Vatican - Fighting with Snakes" title="DSC00466" width="595" height="446" class="aligncenter size-large wp-image-41" /></a></p>
<p>&nbsp;<br />
So how did I reach this conclusion. To replicate the issue</p>
<ol>
<li>In Grails, prototype.js is needed for AJAX calls. You declare in HTML/HEAD</li>
<pre class="brush: javascript">&lt;g:javascript library=&quot;prototype&quot;&gt;&lt;/g:javascript&gt;</pre>
<li>Then create your remote AJAX request</li>
<pre class="brush: javascript">&lt;g:submitToRemote id=&quot;buttonSubmit&quot; 
name=&quot;buttonSubmit&quot; 
controller=&quot;test&quot; 
action=&quot;echoIt&quot; 
value=&quot;GO!&quot; 
before=&quot;hide()&quot; 
onComplete=&quot;show()&quot;&gt;&lt;/g:submitToRemote&gt;</pre>
<li>It all works!</li>
<li>I wanted an autocomplete JQuery, so I downloaded from <a href="http://www.devbridge.com/projects/autocomplete/jquery/">devbridge</a> an excellent and simple autocomplete. Declared the scripts</li>
<pre class="brush: javascript">&lt;g:javascript type=&quot;text/javascript&quot; src=&quot;jquery-1.3.2.min.js&quot;&gt;&lt;/g:javascript&gt;
&lt;g:javascript type=&quot;text/javascript&quot; src=&quot;jquery.autocomplete-min.js&quot;&gt;&lt;/g:javascript&gt;</pre>
<li>Wrote a piece of code to automatically cache the suggestions</li>
<pre class="brush: javascript">function loadSuggestions() {
	var datafile = window.location.href.substring(0, window.location.href.lastIndexOf(&quot;/&quot;) + 1) + &quot;suggestions.txt&quot;

	var xmlhttp = getXMLHTTP();
	xmlhttp.open(&quot;GET&quot;, datafile, true);
	var a;
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 &amp;amp;amp;amp;&amp;amp;amp;amp; xmlhttp.status == 200) {
			jQuery(function() {
				var options = {
					width: 300,
					delimiter: /(,|;)s*/, // regex or character
					minChars:1,
					deferRequestBy: 200, //miliseconds
					//Split out the value and data
					//As the data is stored on the server using A,B
					//Use regex to split and take the 3rd array
					onSelect: function(value, data){
							var splitValue = value.split(/,s*/);
							var elCommand = document.getElementById(&quot;txtCommand&quot;);
							elCommand.value = splitValue[1];
						 },
					lookup: xmlhttp.responseText.split(/r?n/)
				};
			  a = $(&#039;#txtCommand&#039;).autocomplete(options);
			})
		}
	};
	xmlhttp.send(null);
}
}</pre>
<hr />
<p>There was an interference which caused the error -</p>
<pre class="brush: javascript">$(form).getElementsByTagName is not a function.</pre>
<p>Drilling in chrome, the issue lies</p>
<pre class="brush: javascript">Uncaught TypeError: Object #&lt;Object&gt; has no method &#039;getElementsByTagName&#039;  prototype.js:3954
Form.Methods.getElements  prototype.js:3954
Form.Methods.serialize  prototype.js:3950</pre>
<p>For now the only way to correct was to remove JQuery and autocomplete which fixed issue.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.firstzero.co.uk/2011/04/interference-between-jquery-and-prototype-in-grails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
