<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1569789499442484210</id><updated>2026-11-04T01:48:57.086-08:00</updated><category term="Core Java"/><category term="Groovy"/><category term="Android-Java"/><category term="Javascript"/><category term="Spring"/><category term="JSF"/><category term="Sencha Touch"/><category term="Mobile Development"/><category term="PhoneGap"/><category term="Ext JS"/><category term="Servlet"/><category term="JQuery Mobile"/><category term="NodeJs"/><category term="Hibernate"/><category term="Meteor"/><category term="CSS"/><category term="Design Pattern"/><category term="GRUNT"/><category term="Grails"/><category term="MongoDB"/><category term="iOS"/><category term="jQuery"/><title type='text'>Gnanasuriyan</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://www.pointerunits.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://www.pointerunits.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Gnanasuriyan</name><uri>http://www.blogger.com/profile/00525742121019222480</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjL7B6Ihy-xFMB19J-LEHU17qD7kpYY5iUfvlkSSOLR05wDJog8MuQDxNjJTrxAl3duQVgP9Fm4pwYHqA7aMlWMswcUyeTtax-3KogXfLJqN7Uk7sX7N2iEXVKNB54lplQ/s220/IMG_0826.JPG'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>86</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1569789499442484210.post-1048649387743583980</id><published>2018-09-08T13:06:00.000-07:00</published><updated>2018-09-08T21:09:22.934-07:00</updated><title type='text'>Node.JS - File operation examples</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
File operations are very common requirements and I thought of providing some simple examples in Node.js. The Node.js provide a module called &quot;fs&quot; which is having all necessary functions for performing file operations. Let&#39;s start with very simple examples.&lt;br /&gt;
&lt;b&gt;Audience&lt;/b&gt;
&lt;br /&gt;
The examples are very basic and focused for beginners.&lt;br /&gt;
&lt;b&gt;Reading and Writing Files&lt;/b&gt;
&lt;br /&gt;
The file system module provide a synchronous and asynchronous functions for reading and writing a file.&lt;br /&gt;
Example for reading a file using synchronous function fs.readFileSync.&lt;br /&gt;
&lt;pre&gt;
const fs = require(&#39;fs&#39;);
const information = fs.readFileSync(&#39;files/file1.txt&#39;, &#39;utf8&#39;);
console.log(information);
&lt;/pre&gt;
&lt;p&gt;Example for reading a file using asynchronous function fs.readFile.&lt;/p&gt;
&lt;pre&gt;
const fs = require(&#39;fs&#39;);
const information = fs.readFile(&#39;files/file1.txt&#39;, &#39;utf8&#39;, (err, information) =&gt; {
    if (err) {
        console.log(&#39;Error occured while reading a file&#39;);
        return;
    }
    console.log(information);
});
&lt;/pre&gt;
&lt;p&gt;Example for creating a file using synchronous function fs.writeFileSync.&lt;/p&gt;
&lt;pre&gt;
const fs = require(&#39;fs&#39;);

const content = `
The file is created for demonstrating file I/O operation using Node.js
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry&#39;s standard dummy text ever since the 1500s, 
when an unknown printer took a galley of type and scrambled it to make a type specimen book. 
It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more 
recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
`;

fs.writeFileSync(&#39;files/file-write-sync.txt&#39;, content, {
    encoding: &#39;utf8&#39;
});

console.log(&#39;file was created successfully&#39;);
&lt;/pre&gt;
&lt;p&gt;Example for creating a file using asynchronous function fs.writeFile.&lt;/p&gt;
&lt;pre&gt;
const fs = require(&#39;fs&#39;);

const content = `
The file is created for demonstrating file I/O operation using Node.js
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry&#39;s standard dummy text ever since the 1500s, 
when an unknown printer took a galley of type and scrambled it to make a type specimen book. 
It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more 
recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
`;

fs.writeFile(&#39;files/file-write-async.txt&#39;, content, {
    encoding: &#39;utf8&#39;
}, (err) =&gt; {
    if (err) {
        console.log(&#39;file was not created!!&#39;);
        return;
    }
    console.log(&#39;file was created successfully&#39;);
});
&lt;/pre&gt;
&lt;b&gt;Now when do you use synchronous and asynchronous function?&lt;/b&gt;
&lt;p&gt;
The synchronous function will block event loop until finishing their operations, which means the other functions are will be in event loop for a while (waiting for long time) when do you perform complex operations in synchronous mode. The synchronous operation will slow down the application performance and asynchronous functions are mostly advisable in Node.js.
&lt;/p&gt;
&lt;b&gt;Example for renaming a file.&lt;/b&gt;
&lt;pre&gt;
const fs = require(&#39;fs&#39;);

fs.rename(&#39;files/file1.txt&#39;, &#39;files/file1-rename.txt&#39;, (err) =&gt; {
    if (err) {
        console.log(&#39;file was not renamed successfully&#39;);
        return;
    }
    console.log(&#39;file was renamed successfully&#39;);
});
&lt;/pre&gt;
&lt;b&gt;Example for deleting a file.&lt;/b&gt;
&lt;pre&gt;
const fs = require(&#39;fs&#39;);

fs.unlink(&#39;files/file-write-async.txt&#39;, (err) =&gt; {
    if (err) {
        console.log(&#39;file was not deleted!!&#39;);
    }
    console.log(&#39;file was deleted!!&#39;);
});
&lt;/pre&gt;
&lt;b&gt;Example for checking whether a file is exists.&lt;/b&gt;
&lt;pre&gt;
const fs = require(&#39;fs&#39;);

if (fs.exists(&#39;files/file1.txt&#39;)) {
    console.log(&#39;File exists&#39;);
} else {
    console.log(&#39;File does not exists&#39;);
}
&lt;/pre&gt;
&lt;p&gt;For some cases we may need to check whether a particular user has access for a directory or files. We can easily do it node and here is an example.&lt;/p&gt;
&lt;pre&gt;
const fs = require(&#39;fs&#39;);

fs.access(&#39;files/file1.txt&#39;, fs.constants.R_OK | fs.constants.W_OK, (err) =&gt; {
    console.log(err ? &#39;no access&#39; : &#39;can read and write&#39;);
});

&lt;/pre&gt;
&lt;p&gt;
fs.constants is an object which has constant values related to file operations.
&lt;/p&gt;
&lt;pre&gt;
fs.constants.R_OK // path can be read by calling process
fs.constants.W_OK // path can be write by calling process
&lt;/pre&gt;
&lt;b&gt;Reading a file using stream&lt;/b&gt;
&lt;p&gt;
The file system module provide a function called fs.ReadStream for reading a file using streams. We need to open a stream and listen for events for reading a data and this is desired method for reading big size files. Here is an example.
&lt;/p&gt;
&lt;pre&gt;
const fs = require(&#39;fs&#39;);

const stream = fs.ReadStream(&#39;files/file1.txt&#39;);

stream.on(&#39;data&#39;, (chunk) =&gt; {
    console.log(`Received ${chunk.length} bytes of data.`);
});

stream.on(&#39;end&#39;, () =&gt; {
    console.log(&#39;No more data available for read&#39;);
});

stream.on(&#39;error&#39;, (err) =&gt; {
    console.log(`some error occured while reading a file ${err}`);
});

&lt;/pre&gt;
&lt;b&gt;Writing a file using stream&lt;/b&gt;
&lt;p&gt;
The file system module provide a function called fs.WriteStream which is similar to read stream method. This allow us to open a stream and write a chunk of data. Here I am providing a simple example for copying a file using write stream method.
&lt;/p&gt;
&lt;pre&gt;
const fs = require(&#39;fs&#39;);

const source = fs.ReadStream(&#39;files/file1.txt&#39;);
const dest = fs.WriteStream(&#39;files/file2.txt&#39;);

source.on(&#39;data&#39;, (chunk) =&gt; {
    dest.write(chunk);
});

source.on(&#39;end&#39;, () =&gt; {
    console.log(&#39;File was copied successfully&#39;);
    dest.end();
});

&lt;/pre&gt;
&lt;b&gt;Reading a file using ReadLine module&lt;/b&gt;
&lt;p&gt;
The ReadLine module is helpful for reading a data from readble stream one line at a time. Here is an example will read a content from file (line by line) and print it in console.
&lt;/p&gt;
&lt;pre&gt;
const fs = require(&#39;fs&#39;);
const readline = require(&#39;readline&#39;);

const rl = readline.createInterface({
    input: fs.createReadStream(&#39;files/file1.txt&#39;)
});

rl.on(&#39;line&#39;, (line) =&gt; {
    console.log(line);
});

rl.on(&#39;close&#39;, () =&gt; {
    console.log(&#39;done!!&#39;);
});

&lt;/pre&gt;
&lt;p&gt;I have provided some simple examples of file operations using Node. Actually Node is having more capabilities for handling I/O and look at &lt;a href=&quot;https://nodejs.org/en/docs/&quot;&gt;official documentation&lt;/a&gt; for more information. 
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.pointerunits.com/feeds/1048649387743583980/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1569789499442484210/1048649387743583980' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/1048649387743583980'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/1048649387743583980'/><link rel='alternate' type='text/html' href='http://www.pointerunits.com/2018/09/nodejs-file-operation-examples.html' title='Node.JS - File operation examples'/><author><name>Gnanasuriyan</name><uri>http://www.blogger.com/profile/00525742121019222480</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjL7B6Ihy-xFMB19J-LEHU17qD7kpYY5iUfvlkSSOLR05wDJog8MuQDxNjJTrxAl3duQVgP9Fm4pwYHqA7aMlWMswcUyeTtax-3KogXfLJqN7Uk7sX7N2iEXVKNB54lplQ/s220/IMG_0826.JPG'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1569789499442484210.post-4287785060731410896</id><published>2015-06-23T13:00:00.000-07:00</published><updated>2015-06-23T13:00:05.466-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Javascript"/><category scheme="http://www.blogger.com/atom/ns#" term="Meteor"/><category scheme="http://www.blogger.com/atom/ns#" term="Mobile Development"/><category scheme="http://www.blogger.com/atom/ns#" term="NodeJs"/><category scheme="http://www.blogger.com/atom/ns#" term="PhoneGap"/><title type='text'>Meteor tutorial - Part II - Building mobile applications</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;a href=&quot;http://www.pointerunits.com/2015/06/meteor-tutorial-part-i.html&quot; target=&quot;_blank&quot;&gt;In my previous blog post&lt;/a&gt;, I have explained basics of meteor. In this tutorial I am going to add mobile support to the existing meteor application.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Installing mobile SDKs&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Before going to start we need to install IOS and android SDKs (Software development kit). Here I am installing SDKs for iOS. Please keep in mind this is one time process.&lt;br /&gt;
&lt;br /&gt;
For installing iOS SDKs, we need to invoke “meteor install-sdk ios”.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUFELFY6PL7wlQQwGWy1hEI5ikpYiGD9dwd6RDeebnfETKVHkpYa0jHIg4paaNwPzPwgt-o7YyoiTZcNmoyD2AtnLQQ86ycNxtqyBGpXX7yzPsAe9IfKTBabP1Q6E5vm0Era-TaDgHYJON/s1600/Screen+Shot+2015-06-23+at+10.32.33+pm.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;84&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUFELFY6PL7wlQQwGWy1hEI5ikpYiGD9dwd6RDeebnfETKVHkpYa0jHIg4paaNwPzPwgt-o7YyoiTZcNmoyD2AtnLQQ86ycNxtqyBGpXX7yzPsAe9IfKTBabP1Q6E5vm0Era-TaDgHYJON/s320/Screen+Shot+2015-06-23+at+10.32.33+pm.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
The same way you can install android SKDs by invoking “meteor install-sdk android” command.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Adding mobile platform support&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
I am using already created application called “myapp” and going to add iOS platform support by invoking a command “&lt;b&gt;meteor add-platform ios&lt;/b&gt;”.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxVzRvYuVOe6Z8_wWtwnMaBgJ7rEM0DxFDl_b2IFRvILwZniSZbruThbARc8_HNEBk77Wglftg8EwegBfEO1fee-ZafQgg3LOij1RkL4qglNVFMgsQwElQCvI89-CjIlN_PrmTmkv4SfrV/s1600/Screen+Shot+2015-06-24+at+12.10.54+am.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;75&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxVzRvYuVOe6Z8_wWtwnMaBgJ7rEM0DxFDl_b2IFRvILwZniSZbruThbARc8_HNEBk77Wglftg8EwegBfEO1fee-ZafQgg3LOij1RkL4qglNVFMgsQwElQCvI89-CjIlN_PrmTmkv4SfrV/s320/Screen+Shot+2015-06-24+at+12.10.54+am.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;
We can add android platform by invoking a command &amp;nbsp;“&lt;b&gt;meteor add-platform android&lt;/b&gt;”.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;Running application on mobile emulator&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Once we add mobile platform then we can run our application by using real mobile device or emulator. I have added IOS platform to myapp already. Now I am going to run that application by using iPhone emulator by invoking command called “&lt;b&gt;meteor run ios&lt;/b&gt;”.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgF_4S08T6HBtBp6eq0y8FZVflMP2DbkjI8IzybG5naxPz7a1SpeQTRZbJj6QyP6spsJrM-smhLQAMrjvwWFo_SS9PK8R9Re8IVr7wzcOSeB-SN_34QGgMwqI85RDKHsEV35340Fwic1SIw/s1600/Screen+Shot+2015-06-24+at+12.11.56+am.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;86&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgF_4S08T6HBtBp6eq0y8FZVflMP2DbkjI8IzybG5naxPz7a1SpeQTRZbJj6QyP6spsJrM-smhLQAMrjvwWFo_SS9PK8R9Re8IVr7wzcOSeB-SN_34QGgMwqI85RDKHsEV35340Fwic1SIw/s320/Screen+Shot+2015-06-24+at+12.11.56+am.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Whenever we run above command that will add cordova support to the application and convert our web application into mobile hybrid application by using cordova. Cordova internally use webview for rendering web page. If everything is done, you can see iPhone simulator, that will display our web page.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2_W1GS8QciHBphA02skZo7i0ysbdjMAs0aIz2pLXlQ281Mbc1ZeLRFVybCT9AqOXLNfddpKjsA80HqDtYvytjByrKnAig1mAzWy9DQpyZR2iB1s3SI-Zjw8pTejgT5iFzbzoLF76MMBp-/s1600/Screen+Shot+2015-06-24+at+12.13.39+am.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2_W1GS8QciHBphA02skZo7i0ysbdjMAs0aIz2pLXlQ281Mbc1ZeLRFVybCT9AqOXLNfddpKjsA80HqDtYvytjByrKnAig1mAzWy9DQpyZR2iB1s3SI-Zjw8pTejgT5iFzbzoLF76MMBp-/s320/Screen+Shot+2015-06-24+at+12.13.39+am.png&quot; width=&quot;252&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-size: xx-small;&quot;&gt;Running application&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
By using same way we can launch android simulator by invoking “meteor run android” command.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;Running application on real device&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
We can run our application on real device by invoking below commands.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
For iOS -&amp;nbsp;meteor run ios-device&lt;/div&gt;
&lt;div&gt;
For android -&amp;nbsp;meteor run android-device&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Obviously the mobile should be connected to the computer. For iOS, we need to install corresponding provisioning profile into the device before using it for testing.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
Personally I like this approach because there is no real IDE like XCode, Eclipse involved in this process. This is really helpful for beginners because it is very simple and hides lot of internal mechanism involved in the process.&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;Configuring mobile app – metadata&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
In mobile application we need to configure lot of information in info.plist (for iOS) and android manifestfile.xml (for android). The meteor simplifies lot of stuffs, which involved in the configuration. For configuring, we simply need to create a JavaScript file called mobile-config.js and needs to include our configuration. Look into the below url for more information.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;a href=&quot;http://docs.meteor.com/#/full/mobileconfigjs&quot;&gt;http://docs.meteor.com/#/full/mobileconfigjs&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;Conclusion&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
In this tutorial we got steps involved in,&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
1.&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Adding mobile support to meteor application.&lt;/div&gt;
&lt;div&gt;
2.&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Running application on emulators.&lt;/div&gt;
&lt;div&gt;
3.&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Running application on real devices&lt;/div&gt;
&lt;div&gt;
4.&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Configuring mobile application metadata by using mobile-config.js.&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
In my next tutorial, I am going to explain internal architecture of the meteor application.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.pointerunits.com/feeds/4287785060731410896/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1569789499442484210/4287785060731410896' title='18 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/4287785060731410896'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/4287785060731410896'/><link rel='alternate' type='text/html' href='http://www.pointerunits.com/2015/06/meteor-tutorial-part-ii-building-mobile.html' title='Meteor tutorial - Part II - Building mobile applications'/><author><name>Gnanasuriyan</name><uri>http://www.blogger.com/profile/00525742121019222480</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjL7B6Ihy-xFMB19J-LEHU17qD7kpYY5iUfvlkSSOLR05wDJog8MuQDxNjJTrxAl3duQVgP9Fm4pwYHqA7aMlWMswcUyeTtax-3KogXfLJqN7Uk7sX7N2iEXVKNB54lplQ/s220/IMG_0826.JPG'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUFELFY6PL7wlQQwGWy1hEI5ikpYiGD9dwd6RDeebnfETKVHkpYa0jHIg4paaNwPzPwgt-o7YyoiTZcNmoyD2AtnLQQ86ycNxtqyBGpXX7yzPsAe9IfKTBabP1Q6E5vm0Era-TaDgHYJON/s72-c/Screen+Shot+2015-06-23+at+10.32.33+pm.png" height="72" width="72"/><thr:total>18</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1569789499442484210.post-3414427328529839882</id><published>2015-06-23T08:54:00.001-07:00</published><updated>2015-06-23T13:02:02.643-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Javascript"/><category scheme="http://www.blogger.com/atom/ns#" term="Meteor"/><category scheme="http://www.blogger.com/atom/ns#" term="MongoDB"/><category scheme="http://www.blogger.com/atom/ns#" term="NodeJs"/><title type='text'>Meteor tutorial - Part I</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;b&gt;What is Meteor?&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Meteor is a complete open source platform for building web and mobile application by using JavaScript. It is a combination of NodeJs, MongoDB and client side JavaScript.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Installing meteor&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Meteor supports windows, linux and Mac operating systems. Invoke below command in terminal for installing meteor in mac operating system.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYa1zezF1hTLtipMzJkxnLRfMfoQo5wOLeMmwdyQht8voeXzHz36fgtYmeyDZ2NZBOE_w-8EwTdB9v_54I1KR8ZfDldST-1_Gq4FrqtCNCf2vQCzUXJCBd7zUWFvLfSzJNFVIod5MLrrMX/s1600/Screen+Shot+2015-06-21+at+10.03.40+pm.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;185&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYa1zezF1hTLtipMzJkxnLRfMfoQo5wOLeMmwdyQht8voeXzHz36fgtYmeyDZ2NZBOE_w-8EwTdB9v_54I1KR8ZfDldST-1_Gq4FrqtCNCf2vQCzUXJCBd7zUWFvLfSzJNFVIod5MLrrMX/s320/Screen+Shot+2015-06-21+at+10.03.40+pm.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
Check below link for installing meteor on other operating systems.&lt;br /&gt;
&lt;a href=&quot;http://docs.meteor.com/#/basic/quickstart&quot;&gt;http://docs.meteor.com/#/basic/quickstart&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Creating an application&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The command “meteor create &amp;lt;&amp;lt;app_name&amp;gt;&amp;gt;” is used for creating new meteor application. I have created an app called “myapp” and will see how we can run the application.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Running an application&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
“meteor run” command is used for running meteor application. Internally it start a node js server and by default that will listen 3000 port number. Just make sure you are in project directory (myapp) before invoking run command.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiygNjnecTVSnvvA8dad1dvL3DXax6nlFnEhyDIpfNE2NVxbPeVIrRcOiw1vspFUXov1IKA2P09Gq5xtm_1TuMlVS-MJCRjjm7DzPWwRPy6ueQ2QzjW13KypBHe-C_ygYHLROxL8k3JCdhb/s1600/Screen+Shot+2015-06-23+at+5.42.07+pm.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;110&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiygNjnecTVSnvvA8dad1dvL3DXax6nlFnEhyDIpfNE2NVxbPeVIrRcOiw1vspFUXov1IKA2P09Gq5xtm_1TuMlVS-MJCRjjm7DzPWwRPy6ueQ2QzjW13KypBHe-C_ygYHLROxL8k3JCdhb/s320/Screen+Shot+2015-06-23+at+5.42.07+pm.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&#39;&lt;/div&gt;
&lt;b&gt;Other useful meteor commands&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Meteor provides lot of useful commands for simplifying development process. This is very simple introduction about other meteor commands.&lt;br /&gt;
&lt;br /&gt;
1.&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;meteor help – This command is used for understanding purpose of other meteor commands. Example – I got the purpose of create command by using help command.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbVq4qTCfAJzJ5JJVEBrKe1wMNf4CxSmBHQ91XoIrIkkt7mteLBpETXKmjG1Z8OYtyp4SO7tbztbbKh28tXu1a4h87ibTfY2Rqx6JeqJB0FoEEPHqudEhlzZACLWIT309rXCvaOZeZy-KP/s1600/Screen+Shot+2015-06-23+at+5.49.04+pm.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbVq4qTCfAJzJ5JJVEBrKe1wMNf4CxSmBHQ91XoIrIkkt7mteLBpETXKmjG1Z8OYtyp4SO7tbztbbKh28tXu1a4h87ibTfY2Rqx6JeqJB0FoEEPHqudEhlzZACLWIT309rXCvaOZeZy-KP/s320/Screen+Shot+2015-06-23+at+5.49.04+pm.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
2.&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;meteor debug – This is very useful command for debugging server side code. &amp;nbsp;Just use JavaScript keyword “debugger” for creating break points. By default it will wait at first statement of server side code.&lt;br /&gt;
&lt;br /&gt;
3.&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;meteor deploy &amp;lt;&amp;lt;site&amp;gt;&amp;gt; - This command is really useful for deploying application. Meteor provide free hosting and you can deploy application in &amp;lt;&amp;lt;appname&amp;gt;&amp;gt;.meteor.com. If someone already used app name then you will have to use different application name for deploying. Let me deploy my application and it will take a while for deploying.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiR1Njbvas73NYjyUBLZXQVpYEVVwvQRxBN7wKAaK0TAMFyzy93d5fhiVXRkqxpfbzfpVZT_u9D2puz9OdgDKBBXwn49nSx6zWx13BA9iSX9KVyc21KBLsyzuBCW-FjMB-CTelNPWlgLusK/s1600/Screen+Shot+2015-06-23+at+6.00.57+pm.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;83&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiR1Njbvas73NYjyUBLZXQVpYEVVwvQRxBN7wKAaK0TAMFyzy93d5fhiVXRkqxpfbzfpVZT_u9D2puz9OdgDKBBXwn49nSx6zWx13BA9iSX9KVyc21KBLsyzuBCW-FjMB-CTelNPWlgLusK/s320/Screen+Shot+2015-06-23+at+6.00.57+pm.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
It is deployed successfully and for verification load the URL in browser, which we have used while deploying the application.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgl9AEXmDW9mMDsMUOFdNCBc8_ll99W12RmSf_ioZgn-CoCdO0wcVYHhdu8BSVY6Yl3BI4nlNG5YeSaOaDXIiyOtp4Pbbr101_uv9ZAq0ocerXs9_Ydo-UKsA1Jgfw2p_cVqWfiqamlmwJH/s1600/Screen+Shot+2015-06-23+at+6.02.21+pm.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;165&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgl9AEXmDW9mMDsMUOFdNCBc8_ll99W12RmSf_ioZgn-CoCdO0wcVYHhdu8BSVY6Yl3BI4nlNG5YeSaOaDXIiyOtp4Pbbr101_uv9ZAq0ocerXs9_Ydo-UKsA1Jgfw2p_cVqWfiqamlmwJH/s320/Screen+Shot+2015-06-23+at+6.02.21+pm.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
4.&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;meteor update – This is used for updating meteor version used by an application. You will have to run this command from your application folder and make sure you are upgrading other packages for avoiding compatibility issues.&lt;br /&gt;
&lt;br /&gt;
5.&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;meteor add – This is used for adding new package into the application.&lt;br /&gt;
&lt;br /&gt;
6.&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;meteor remove – This is used for removing previously added package from the application.&lt;br /&gt;
&lt;br /&gt;
7.&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;meteor search – This command is used for searching available packages in meteor.&lt;br /&gt;
&lt;br /&gt;
8.&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;meteor mongo – This is used for opening MongoDB shell command for modifying mongo database collection. Meteor internally use mongo-db for saving data.&lt;br /&gt;
&lt;br /&gt;
9.&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;mongo reset – This is used for resetting current project to fresh state and it removes all local data.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Meteor File Structure&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Meteor is very flexible for structuring application. It automatically loads all of our files, so we don’t need to use script and link tag for loading JavaScript and CSS files. It does the following while loading files.&lt;br /&gt;
&lt;br /&gt;
1.&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;All CSS files are sent to the browser and in production mode it is automatically concatenate and minify the source files.&lt;br /&gt;
&lt;br /&gt;
2.&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;JavaScript is loaded on the both client and server. We need to use Meteor.isClient and Meteor.isServer condition for stopping execution of certain part of the source code.&lt;br /&gt;
&lt;br /&gt;
3.&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;HTML templates are compiled and sent to the client.&lt;br /&gt;
&lt;br /&gt;
Actually meteor provides some directory structure for securing and improving performance of the application.&lt;br /&gt;
&lt;br /&gt;
/client – The files, which are in client directory, are only served to the client. This is a good place for keeping our client side source codes like CSS, HTML templates and client side JavaScript files.&lt;br /&gt;
&lt;br /&gt;
/server – The files, which are in server directory are used and loaded while starting server. These files are never sent to the client. This is good place for keeping server side JavaScript files and by the way we can secure our application.&lt;br /&gt;
&lt;br /&gt;
/public – The files in public folder are served to the client as-is. So this is good place for keeping our static contents like images, and fonts.&lt;br /&gt;
&lt;br /&gt;
/private – The files in private are not sent to the client and also contents are loaded only when access through Assets - server side.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Conclusion&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
In this tutorial we have seen,&lt;br /&gt;
&lt;br /&gt;
1.&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;What is meteor?&lt;br /&gt;
&lt;br /&gt;
2.&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Steps for&amp;nbsp;Installing and Configuring meteor.&lt;br /&gt;
&lt;br /&gt;
3.&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Meteor available commands and corresponding usage.&lt;br /&gt;
&lt;br /&gt;
4.&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Directory structure of meteor application and deploying meteor application.&lt;br /&gt;
&lt;br /&gt;
In my next tutorial, I am going to explain building mobile apps by using meteor.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.pointerunits.com/feeds/3414427328529839882/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1569789499442484210/3414427328529839882' title='14 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/3414427328529839882'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/3414427328529839882'/><link rel='alternate' type='text/html' href='http://www.pointerunits.com/2015/06/meteor-tutorial-part-i.html' title='Meteor tutorial - Part I'/><author><name>Gnanasuriyan</name><uri>http://www.blogger.com/profile/00525742121019222480</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjL7B6Ihy-xFMB19J-LEHU17qD7kpYY5iUfvlkSSOLR05wDJog8MuQDxNjJTrxAl3duQVgP9Fm4pwYHqA7aMlWMswcUyeTtax-3KogXfLJqN7Uk7sX7N2iEXVKNB54lplQ/s220/IMG_0826.JPG'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYa1zezF1hTLtipMzJkxnLRfMfoQo5wOLeMmwdyQht8voeXzHz36fgtYmeyDZ2NZBOE_w-8EwTdB9v_54I1KR8ZfDldST-1_Gq4FrqtCNCf2vQCzUXJCBd7zUWFvLfSzJNFVIod5MLrrMX/s72-c/Screen+Shot+2015-06-21+at+10.03.40+pm.png" height="72" width="72"/><thr:total>14</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1569789499442484210.post-2952812554656640518</id><published>2014-08-11T06:49:00.001-07:00</published><updated>2014-08-11T09:52:55.485-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="GRUNT"/><category scheme="http://www.blogger.com/atom/ns#" term="Javascript"/><category scheme="http://www.blogger.com/atom/ns#" term="NodeJs"/><title type='text'>GRUNT – Cleaning and Minifying JavaScript Files</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
In this tutorial, we are going to create a NodeJS/Grunt project which has basically used for minifying many JavaScript files into one. The steps are,&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;Step 1.&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Install NodeJS latest version and refer “http://nodejs.org/download/” link for more information.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;Step 2.&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
If you are having any existing NodeJS instance then just update by using “npm update –g npm” command. I am having existing NodeJS instance and updated by invoking above command.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgkbDFT36P__tcTw0anmGP4kL04XNAkYUDj07qRYJzytVmgz7D06Z_1zX-CzEyGwxJ0LEW7d_3uwRVyiUl5hUuBZa90BKaMx0jpvRezVhESVxk-uzall8QWQW0lCZjg5uJN8Rqq9vDzUjgD/s1600/Step1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgkbDFT36P__tcTw0anmGP4kL04XNAkYUDj07qRYJzytVmgz7D06Z_1zX-CzEyGwxJ0LEW7d_3uwRVyiUl5hUuBZa90BKaMx0jpvRezVhESVxk-uzall8QWQW0lCZjg5uJN8Rqq9vDzUjgD/s1600/Step1.png&quot; height=&quot;164&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;Step: 3.&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Next, we need a Grunt command line interface (CLI) tools globally. It is a node.js module and needs to install by using a command called “npm install –g grunt-cli”.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicGsJBshLek-vGFmLrXQFAPTK3xrx5ZBtA2Pd8DbbibfSTBlp4yb_MYafXpd-LXQq1AC0kXgul8pZ4ifJWN2Rq8mwlcqohztCsIGGkBzwlJTRIEfny1P2ZE1qlCtWn3L35aNR5G7sdJvGv/s1600/Step3.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicGsJBshLek-vGFmLrXQFAPTK3xrx5ZBtA2Pd8DbbibfSTBlp4yb_MYafXpd-LXQq1AC0kXgul8pZ4ifJWN2Rq8mwlcqohztCsIGGkBzwlJTRIEfny1P2ZE1qlCtWn3L35aNR5G7sdJvGv/s1600/Step3.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;Step 4.&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
We need another component called grunt-init globally. It is also a node.js module and we can install it globally by invoking a command “npm install –g grunt-init”.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi748wEHwHOzOBK_c8NB-AO_byMHo1I06WpmB4-QkUKKrCSMUxq8mbsnuKOC46k3_PCkNQ0F3JcM0d_O_FbrarW5Lr5qU4CtimfSfPNlEM468bc1Cvu-usTTrzULUxTZy0wCPM9Tazr6U9-/s1600/Step4.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi748wEHwHOzOBK_c8NB-AO_byMHo1I06WpmB4-QkUKKrCSMUxq8mbsnuKOC46k3_PCkNQ0F3JcM0d_O_FbrarW5Lr5qU4CtimfSfPNlEM468bc1Cvu-usTTrzULUxTZy0wCPM9Tazr6U9-/s1600/Step4.png&quot; height=&quot;100&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;Step 5.&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Next, we need to create a new grunt project. I have created new folder called “Grunt-MinifyDemo” in “D“ directory and this is my project.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;Step 6.&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
In windows command prompt, Just move to that particular directory and check the screen shot which help you to understand what I mean here.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEitslYxa6S7o2iu1KGnIKrK4NB_k9sLIpHJ_6E-EvHBFUyPsISrki59CkMfY72UmPcHt9Lbo2NLpZOFjYhyc-uSOqFfyxQOphwiUsX7WUgLXidQi7jCuub5lC32ThtoVO8uPK92jHEIZRWC/s1600/Step6.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEitslYxa6S7o2iu1KGnIKrK4NB_k9sLIpHJ_6E-EvHBFUyPsISrki59CkMfY72UmPcHt9Lbo2NLpZOFjYhyc-uSOqFfyxQOphwiUsX7WUgLXidQi7jCuub5lC32ThtoVO8uPK92jHEIZRWC/s1600/Step6.png&quot; height=&quot;59&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;Step 7.&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Now we need to initiate a Node.js project by invoking a command called “npm init”. While invoking this command will ask you to enter application name, description, version, and other details. For more information please check my screen shot. The above command finally will create package.json file which basically used for defining our application specific dependencies and other details. We can edit this file at any point of time and if you define any new dependencies then will have to invoke “npm install” command for installing those new dependencies.&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4XsIIvXc956cF1yDpn33qgDUO0d54Zw_bZJU6D24TjNjI9PmfLLYlwN6owb-cnQAFyAFIWRNr6sOJLdNg3U2Ci0T2NgwDDjMLrWduhW3U9HVC-hGPNQDekJ7pT7kyX5Nmfql6bQJ_fPMp/s1600/Step7.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4XsIIvXc956cF1yDpn33qgDUO0d54Zw_bZJU6D24TjNjI9PmfLLYlwN6owb-cnQAFyAFIWRNr6sOJLdNg3U2Ci0T2NgwDDjMLrWduhW3U9HVC-hGPNQDekJ7pT7kyX5Nmfql6bQJ_fPMp/s1600/Step7.png&quot; height=&quot;241&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;Step 8.&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Now we need to edit the package.json file for defining our grunt dependencies. The modified package.json file contents are given below.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;{
  &quot;name&quot;: &quot;grunt-minify-demo&quot;,
  &quot;version&quot;: &quot;0.0.1&quot;,
  &quot;description&quot;: &quot;Simple demo application for minifying javascript files using GRUNT tool&quot;,
  &quot;main&quot;: &quot;Gruntfile.js&quot;,
  &quot;scripts&quot;: {
    &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;amp;&amp;amp; exit 1&quot;
  },
  &quot;author&quot;: &quot;Gnanasuriyan A&quot;,
  &quot;license&quot;: &quot;MIT&quot;,
  &quot;devDependencies&quot;: {
   &quot;grunt&quot;: &quot;~0.4.5&quot;,
    &quot;grunt-contrib-jshint&quot;: &quot;~0.10.0&quot;,
    &quot;grunt-contrib-nodeunit&quot;: &quot;~0.4.1&quot;,
    &quot;grunt-contrib-uglify&quot;: &quot;~0.5.0&quot;
  }
}
&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
I have included grunt specific dependencies and changed main value as “Gruntfile.js”. This is an entry point of the application.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;Step 9.&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Now just invoke a command called “npm install” for downloading those specified dependencies as we discussed in step number 7.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-joIKwdGgROmTze0jbQDj7FUd_U-hf6SWHK0e5-SGdUN3R04AGOPRfAlmch8Ygb4ZY_mvZp6wK6CBTU9k_r65ijHUGMbYasdy862XUX18jAohUtchIytn7KNzVMQ34xVEv5r9NFZ2g9gB/s1600/Step9.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-joIKwdGgROmTze0jbQDj7FUd_U-hf6SWHK0e5-SGdUN3R04AGOPRfAlmch8Ygb4ZY_mvZp6wK6CBTU9k_r65ijHUGMbYasdy862XUX18jAohUtchIytn7KNzVMQ34xVEv5r9NFZ2g9gB/s1600/Step9.png&quot; height=&quot;263&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The above command will download all the dependencies and for verification just check node_modules folder present in out application folder “D:\Grunt-MinifyDemo”.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJfpu7CZfdNBVuLltIjGUIhh_bbsP3z77Qx1aZmY9Dhi-ZJwB5wiYhtfLWrzZmJ71kP9qgn7UZNaIvQWGiq9yTVamtEKdxuJ4BTfPjezC-5z3L1Os1HITGunpsgrVKDi4XGs0JDbUBUtG6/s1600/Step9_1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJfpu7CZfdNBVuLltIjGUIhh_bbsP3z77Qx1aZmY9Dhi-ZJwB5wiYhtfLWrzZmJ71kP9qgn7UZNaIvQWGiq9yTVamtEKdxuJ4BTfPjezC-5z3L1Os1HITGunpsgrVKDi4XGs0JDbUBUtG6/s1600/Step9_1.png&quot; height=&quot;82&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;Step 10.&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Currently we have developed only node.js project and downloaded all GRUNT dependencies. Now we need to define our grunt task for combining and converting JavaScript source files into single minified file. For that we need a help from one more grunt module called “grunt-contrib-uglify”. We have already included in dependency list and that module is already available in node_modules folder.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;Step 11.&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
For defining our grunt task, we need to create a JavaScript file called “Gruntfile.js” and this name is based on &quot;main&quot; key value in package.json file. Note: the above file should be created in root folder of the application and here the root folder is “D:\Grunt-MinifyDemo”.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEirSEoByPCFCf5G8P5MO7qTvCurVnuSWZN-nMvNOJiv7Ko-WtMOb6ezommjOmfweLhNlK3BQSZG-N_gHFCRlzvxvBtQPVU6JuAJdlrTnQh6GflTZqi1TA2zWDQSGV9jQ-E3aq5B7KhzA3aB/s1600/Step11.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEirSEoByPCFCf5G8P5MO7qTvCurVnuSWZN-nMvNOJiv7Ko-WtMOb6ezommjOmfweLhNlK3BQSZG-N_gHFCRlzvxvBtQPVU6JuAJdlrTnQh6GflTZqi1TA2zWDQSGV9jQ-E3aq5B7KhzA3aB/s1600/Step11.png&quot; height=&quot;63&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;Step 12.&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Before writing a grunt task, I am going to create some test JavaScript source files for minification. Nothing fancy in the JavaScript files and I have just included some test functions with console messages.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKD71Rvo3jpTkkxaqrEgtKDcVERrbbPhkNhyphenhyphentVY5-faOAluLXiEOX3rA3kQYFTvgpFr4cj3EvVutb5bvAyU5BqS8FrovBHNw1g3BzJa8s-SRZi_0g1MuHQDVpF7b0UGXpgAHHjy0CvY33B/s1600/Step12.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKD71Rvo3jpTkkxaqrEgtKDcVERrbbPhkNhyphenhyphentVY5-faOAluLXiEOX3rA3kQYFTvgpFr4cj3EvVutb5bvAyU5BqS8FrovBHNw1g3BzJa8s-SRZi_0g1MuHQDVpF7b0UGXpgAHHjy0CvY33B/s1600/Step12.png&quot; height=&quot;113&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;Step 13.&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Now I am going to write a grunt task for combining/minifying my File1.js and File2.js file present in src folder. The source code which I have written in Gruntfile.js for minification is given below.&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;module.exports = function(grunt) {
  // Project configuration.
  grunt.initConfig({
    pkg: grunt.file.readJSON(&#39;package.json&#39;),
    uglify: {
      options : {
          compress : {
            drop_console : false
          },
          beautify : true
      },
      dev: {
        files: {
          &#39;build/output.js&#39;: [&#39;src/File1.js&#39;, &#39;src/File2.js&#39;]  
        },
        options: {
          preserveComments: false
        }
      }
    }
  });
  // Load the plugin that provides the &quot;uglify&quot; task.
  grunt.loadNpmTasks(&#39;grunt-contrib-uglify&#39;);
  // Default task(s).
  grunt.registerTask(&#39;default&#39;, [&#39;uglify:dev&#39;]);
};
&lt;/pre&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;Step 14.&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The grunt.initConfig({}) function is basically used for defining our grunt configuration. For understanding more about grunt configuration, please refer &quot;https://github.com/gruntjs/grunt-contrib-uglify&quot;. Here I have created only one environment called dev which contains my output file path “build/dev/output.js” and array of JavaScript source file names.&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;Step 15.&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The line grunt.loadNpmTasks function is basically used for loading grunt modules and grunt.registertask is basically used for registering grunt tasks. In single project we can register more then one grunt tasks. For more information about registering grunt tasks, please refer &quot;http://gruntjs.com/creating-tasks&quot;.&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;Step 16.&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Now If you run a “grunt” command that will trigger the default task i.e. uglify:dev and will create a new combined JavaScript file called “output.js” in &quot;build/dev&quot; folder. The grunt will run default task always when we don&#39;t specify any registered task name.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgpcttQzAGr3oR5Fh72flvNyAgKNOlkhOzEmtsFaCc7z2-BOVw-5SVRw5PFXxgJgDWrkjxSL1s2kEOhZmmYj2Fpa7p2JEWHrH5j-6y0ZR40iz7m50vYNvKGnT_RCSiiJT2xPrQA8LBV_V5D/s1600/Step16.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgpcttQzAGr3oR5Fh72flvNyAgKNOlkhOzEmtsFaCc7z2-BOVw-5SVRw5PFXxgJgDWrkjxSL1s2kEOhZmmYj2Fpa7p2JEWHrH5j-6y0ZR40iz7m50vYNvKGnT_RCSiiJT2xPrQA8LBV_V5D/s1600/Step16.png&quot; height=&quot;77&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Instead of you can run the above task by triggering a command “grunt uglify:dev”.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;Step 17.&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
This is my output.js file content. Here I am not minifying my JavaScript code and instead just combining all &amp;nbsp;my different JS files into single one.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;function moduleOne() {
    console.log(&quot;Module one&quot;);
}

function moduleTwo() {
    console.log(&quot;Module two&quot;);
}
&lt;/pre&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;Step 18.&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Now I am going to define one task called “prod” which will combine and minify the JavaScript file. The modified Gruntfile.js source code is given below.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;module.exports = function(grunt) {
  // Project configuration.
  grunt.initConfig({
    pkg: grunt.file.readJSON(&#39;package.json&#39;),
    uglify: {
      dev: {
        files: {
          &#39;build/dev/output.js&#39;: [&#39;src/File1.js&#39;, &#39;src/File2.js&#39;]  
        },
        options: {
          preserveComments: false,
          compress : {
            drop_console : false
          },
          beautify : true
        }
      },
      prod: {
        files: {
          &#39;build/prod/output.js&#39;: [&#39;src/File1.js&#39;, &#39;src/File2.js&#39;]  
        },
        options: {
          preserveComments: true,
          compress : {
            drop_console : false
          },
          beautify : false
        }
      }
    }
  });
  // Load the plugin that provides the &quot;uglify&quot; task.
  grunt.loadNpmTasks(&#39;grunt-contrib-uglify&#39;);
  // Default task(s).
  grunt.registerTask(&#39;default&#39;, [&#39;uglify:dev&#39;]);
  grunt.registerTask(&#39;prod&#39;, [&#39;uglify:prod&#39;]);
};
&lt;/pre&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;Step 19.&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Now just invoke a command “grunt prod” for creating production build which will combine and minify all specified JavaScript files.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOyQQYylXvzaoSTdxi24IVrU4UzgLJwM5iGi6tGJv2nHZdP0ygvP0BepCvkglpwM9GmCm_HAdPgwkFdrTz5HTss0_TGvDLnGYZ-_PelQmMgp-3WK3tx_W8JoHMELTbYxDlPCk96_y8UxpD/s1600/Step19.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOyQQYylXvzaoSTdxi24IVrU4UzgLJwM5iGi6tGJv2nHZdP0ygvP0BepCvkglpwM9GmCm_HAdPgwkFdrTz5HTss0_TGvDLnGYZ-_PelQmMgp-3WK3tx_W8JoHMELTbYxDlPCk96_y8UxpD/s1600/Step19.png&quot; height=&quot;113&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;Step 20.&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
In some situation we need to run some more tasks before running actual minification. For example normally we will have to clean the existing result before taking a new build. The grunt actually provide a way for defining more than one tasks which will run sequentially. Just check my production task which I have registered in Gruntfile.js. I am just cleaning all existing builds before taking a new production build.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;module.exports = function(grunt) {
  // Project configuration.
  grunt.initConfig({
    pkg: grunt.file.readJSON(&#39;package.json&#39;),
    uglify: {
      dev: {
        files: {
          &#39;build/dev/output.js&#39;: [&#39;src/File1.js&#39;, &#39;src/File2.js&#39;]  
        },
        options: {
          preserveComments: false,
          compress : {
            drop_console : false
          },
          beautify : true
        }
      },
      prod: {
        files: {
          &#39;build/prod/output.js&#39;: [&#39;src/File1.js&#39;, &#39;src/File2.js&#39;]  
        },
        options: {
          preserveComments: &#39;all&#39;,
          compress : {
            drop_console : false
          },
          beautify : false
        }
      }
    }
  });
  // Load the plugin that provides the &quot;uglify&quot; task.
  grunt.loadNpmTasks(&#39;grunt-contrib-uglify&#39;);
  // Default task(s).
  grunt.registerTask(&#39;default&#39;, [&#39;uglify:dev&#39;]);
  grunt.registerTask(&#39;prod&#39;, [&#39;clean&#39;, &#39;uglify:prod&#39;]);
};
&lt;/pre&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;Step 21.&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;text-align: left;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;text-align: left;&quot;&gt;Now just invoke same “grunt prod” command and see the result.&lt;/span&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;text-align: left; white-space: pre;&quot;&gt; &lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhju9RLwjZaCtUCivlQ2KNyK6Ucv5hw18yuM2HAYghMA6jzw8S6Z7BzrAxLa1A0N_A9fAuga0it-T8IwqdhjSq5h55RtzjPaHORWnAlMyjXGRNIbcCL76b0eS1NtfukTOuje5jdPfq1mZjS/s1600/Step21.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhju9RLwjZaCtUCivlQ2KNyK6Ucv5hw18yuM2HAYghMA6jzw8S6Z7BzrAxLa1A0N_A9fAuga0it-T8IwqdhjSq5h55RtzjPaHORWnAlMyjXGRNIbcCL76b0eS1NtfukTOuje5jdPfq1mZjS/s1600/Step21.png&quot; height=&quot;94&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
We are getting some warning because not loading grunt clean module properly. Just load that grunt clean module properly and test it. For loading clean module, we need to update package.json file and need to invoke “npm install” command. This is my modified package.json file.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;{
  &quot;name&quot;: &quot;grunt-minify-demo&quot;,
  &quot;version&quot;: &quot;0.0.1&quot;,
  &quot;description&quot;: &quot;Simple demo application for minifying javascript files using GRUNT tool&quot;,
  &quot;main&quot;: &quot;Gruntfile.js&quot;,
  &quot;scripts&quot;: {
    &quot;test&quot;: &quot;echo \&quot;Error: no test specified\&quot; &amp;amp;&amp;amp; exit 1&quot;
  },
  &quot;author&quot;: &quot;Gnanasuriyan A&quot;,
  &quot;license&quot;: &quot;MIT&quot;,
  &quot;devDependencies&quot;: {
   &quot;grunt&quot;: &quot;~0.4.5&quot;,
    &quot;grunt-contrib-jshint&quot;: &quot;~0.10.0&quot;,
    &quot;grunt-contrib-nodeunit&quot;: &quot;~0.4.1&quot;,
    &quot;grunt-contrib-uglify&quot;: &quot;~0.5.0&quot;,
    &quot;grunt-contrib-clean&quot;: &quot;~0.4.0&quot;
  }
}
&lt;/pre&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhh3Qvbhxn5UVj_GSD_SgjqbYOyzGZ-M0wwXzMJVV1K6oYL6wMysuZFaxE6G5wsWFGr3gfcA-38IH-775QAchRYBM9mc7ES9ZAaeyaihO0YTNPU6BHucFEqzSFgFws2dH2IyR9Qq4UtQfRr/s1600/Step22.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhh3Qvbhxn5UVj_GSD_SgjqbYOyzGZ-M0wwXzMJVV1K6oYL6wMysuZFaxE6G5wsWFGr3gfcA-38IH-775QAchRYBM9mc7ES9ZAaeyaihO0YTNPU6BHucFEqzSFgFws2dH2IyR9Qq4UtQfRr/s1600/Step22.png&quot; height=&quot;98&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;Step 22.&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Now we need to load a “grunt-contrib-clean” module by using “grunt.loadNpmTasks“ function and my modified Gruntfile.js source code is given below.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;module.exports = function(grunt) {
  // Project configuration.
  grunt.initConfig({
    pkg: grunt.file.readJSON(&#39;package.json&#39;),
    uglify: {
      dev: {
        files: {
          &#39;build/dev/output.js&#39;: [&#39;src/File1.js&#39;, &#39;src/File2.js&#39;]  
        },
        options: {
          preserveComments: false,
          compress : {
            drop_console : false
          },
          beautify : true
        }
      },
      prod: {
        files: {
          &#39;build/prod/output.js&#39;: [&#39;src/File1.js&#39;, &#39;src/File2.js&#39;]  
        },
        options: {
          preserveComments: &#39;all&#39;,
          compress : {
            drop_console : false
          },
          beautify : false
        }
      }
    },
    clean: {
      js: [&#39;build/dev/output.js&#39;, &#39;build/prod/output.js&#39;]
    }
  });
  // Load the plugin that provides the &quot;uglify&quot; task.
  grunt.loadNpmTasks(&#39;grunt-contrib-uglify&#39;);
  //Loading grunt clean module
  grunt.loadNpmTasks(&#39;grunt-contrib-clean&#39;);

  // Default task(s).
  grunt.registerTask(&#39;default&#39;, [&#39;uglify:dev&#39;]);
  grunt.registerTask(&#39;prod&#39;, [&#39;clean&#39;, &#39;uglify:prod&#39;]);
};
&lt;/pre&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;Step 23.&amp;nbsp;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
In my above code just check my clean configuration. I am just removing production and development JavaScript files from build folder. Now just take a production build by invoking “grunt prod” command.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRkAU9Yxd1yh-SMdfE_NxBbfyQZrDfBdertGzbTPd-febO-pBQEha2YM6hCn122qCBiRKYvf5bcjRbAlmKHg79bxEUrmXWzrTte4VabEfbUgkzlqB2lPHNB9N4trawME5DrAx9JV11vIRm/s1600/Step23.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRkAU9Yxd1yh-SMdfE_NxBbfyQZrDfBdertGzbTPd-febO-pBQEha2YM6hCn122qCBiRKYvf5bcjRbAlmKHg79bxEUrmXWzrTte4VabEfbUgkzlqB2lPHNB9N4trawME5DrAx9JV11vIRm/s1600/Step23.png&quot; height=&quot;132&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;Conclusion&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
1.&amp;nbsp;We have created new Node.js application for running grunt tasks.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
2.&amp;nbsp;We have included grunt minification tasks for minifying JavaScript files by using grunt uglify module.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
3.&amp;nbsp;We have included clean task for removing existing build from file system by using grunt clean module.&lt;br /&gt;
&lt;br /&gt;
The entire project is available in my github repository (https://github.com/gnanasuriyan/grunt-minification ).&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.pointerunits.com/feeds/2952812554656640518/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1569789499442484210/2952812554656640518' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/2952812554656640518'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/2952812554656640518'/><link rel='alternate' type='text/html' href='http://www.pointerunits.com/2014/08/grunt-cleaning-and-minifying-javascript.html' title='GRUNT – Cleaning and Minifying JavaScript Files'/><author><name>Gnanasuriyan</name><uri>http://www.blogger.com/profile/00525742121019222480</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjL7B6Ihy-xFMB19J-LEHU17qD7kpYY5iUfvlkSSOLR05wDJog8MuQDxNjJTrxAl3duQVgP9Fm4pwYHqA7aMlWMswcUyeTtax-3KogXfLJqN7Uk7sX7N2iEXVKNB54lplQ/s220/IMG_0826.JPG'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgkbDFT36P__tcTw0anmGP4kL04XNAkYUDj07qRYJzytVmgz7D06Z_1zX-CzEyGwxJ0LEW7d_3uwRVyiUl5hUuBZa90BKaMx0jpvRezVhESVxk-uzall8QWQW0lCZjg5uJN8Rqq9vDzUjgD/s72-c/Step1.png" height="72" width="72"/><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1569789499442484210.post-1311232589152333011</id><published>2014-02-07T09:16:00.000-08:00</published><updated>2014-02-07T09:16:43.249-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="iOS"/><title type='text'>iOS - Simple to-do application development</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
After a long time, I had some good time to study native iOS development and developed simple to-do application by following a &lt;a href=&quot;https://developer.apple.com/library/ios/referencelibrary/GettingStarted/RoadMapiOS/index.html&quot; target=&quot;_blank&quot;&gt;tutorial present in iOS developer library&lt;/a&gt;. The source code is available in&amp;nbsp;&lt;a href=&quot;https://github.com/gnanasuriyan/iPhoneToDo&quot; target=&quot;_blank&quot;&gt;githup repository&lt;/a&gt; and don&#39;t worry about modifying the source code.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjab5khKcHulXMsPCmzJvPy3xVghSWNRRKyMjmjvBYGz1Qd6cAf3jmH3moEJphZQokM9cwgHSGrMaoyt36jwQ6eixCqTRHZu7e1LNI2_PkI446fXXgc6o5iqfV2Y4R42osjt_C1-Iix43Vv/s1600/Screen+Shot+2014-02-07+at+10.36.07+pm.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjab5khKcHulXMsPCmzJvPy3xVghSWNRRKyMjmjvBYGz1Qd6cAf3jmH3moEJphZQokM9cwgHSGrMaoyt36jwQ6eixCqTRHZu7e1LNI2_PkI446fXXgc6o5iqfV2Y4R42osjt_C1-Iix43Vv/s1600/Screen+Shot+2014-02-07+at+10.36.07+pm.png&quot; height=&quot;320&quot; width=&quot;175&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkOc7r1uEoN3l4_FhlZ0CJFQkOYu9d4zNAJPH_26n6DhM8MaHCTPrsLw1krxQ3VNTT-7yDhQMb5wDjftOg7th0kmoRmdzikPZSF5HMcHuyZ20JGjmp_5qhhid4OhToE_k4Qk4c8MTeTkPL/s1600/Screen+Shot+2014-02-07+at+10.36.18+pm.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkOc7r1uEoN3l4_FhlZ0CJFQkOYu9d4zNAJPH_26n6DhM8MaHCTPrsLw1krxQ3VNTT-7yDhQMb5wDjftOg7th0kmoRmdzikPZSF5HMcHuyZ20JGjmp_5qhhid4OhToE_k4Qk4c8MTeTkPL/s1600/Screen+Shot+2014-02-07+at+10.36.18+pm.png&quot; height=&quot;320&quot; width=&quot;176&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjR0hmjkn7R143qmirZaJzztjd6UKGqSUnekGxWubIpI-ucdKdgGkekHLCmM1NqVRzaqlPhhhWqiUCumCwtf8-eU8kCBq5EPnDNGM0KnGF7TjgOhLz1EkTI4rWYRMY8dqF-nvkcYu5M2sNj/s1600/Screen+Shot+2014-02-07+at+10.37.39+pm.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjR0hmjkn7R143qmirZaJzztjd6UKGqSUnekGxWubIpI-ucdKdgGkekHLCmM1NqVRzaqlPhhhWqiUCumCwtf8-eU8kCBq5EPnDNGM0KnGF7TjgOhLz1EkTI4rWYRMY8dqF-nvkcYu5M2sNj/s1600/Screen+Shot+2014-02-07+at+10.37.39+pm.png&quot; height=&quot;320&quot; width=&quot;189&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKeMVDWLPmH5CUAN2pu27MKvAEyK0GbQSpx9vzVnIbtdReY53TaMWfESTPfLodtHDGQscuqJF1Zne0ox22-_wcPNmKns1CoAgm6dS-8rE0iI9DDU_1OMQROTS92PvhWgwOU2EFOb3F-7ij/s1600/Screen+Shot+2014-02-07+at+10.37.54+pm.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKeMVDWLPmH5CUAN2pu27MKvAEyK0GbQSpx9vzVnIbtdReY53TaMWfESTPfLodtHDGQscuqJF1Zne0ox22-_wcPNmKns1CoAgm6dS-8rE0iI9DDU_1OMQROTS92PvhWgwOU2EFOb3F-7ij/s1600/Screen+Shot+2014-02-07+at+10.37.54+pm.png&quot; height=&quot;320&quot; width=&quot;177&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Currently this application doesn&#39;t store our to-do items permanently. Probably my next change should be storing our to-do list in database. Now if you kill the application the data will be lost :)&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.pointerunits.com/feeds/1311232589152333011/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1569789499442484210/1311232589152333011' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/1311232589152333011'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/1311232589152333011'/><link rel='alternate' type='text/html' href='http://www.pointerunits.com/2014/02/ios-simple-to-do-application-development.html' title='iOS - Simple to-do application development'/><author><name>Gnanasuriyan</name><uri>http://www.blogger.com/profile/00525742121019222480</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjL7B6Ihy-xFMB19J-LEHU17qD7kpYY5iUfvlkSSOLR05wDJog8MuQDxNjJTrxAl3duQVgP9Fm4pwYHqA7aMlWMswcUyeTtax-3KogXfLJqN7Uk7sX7N2iEXVKNB54lplQ/s220/IMG_0826.JPG'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjab5khKcHulXMsPCmzJvPy3xVghSWNRRKyMjmjvBYGz1Qd6cAf3jmH3moEJphZQokM9cwgHSGrMaoyt36jwQ6eixCqTRHZu7e1LNI2_PkI446fXXgc6o5iqfV2Y4R42osjt_C1-Iix43Vv/s72-c/Screen+Shot+2014-02-07+at+10.36.07+pm.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1569789499442484210.post-1144832408097448173</id><published>2013-10-19T12:12:00.003-07:00</published><updated>2014-02-23T10:04:06.780-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Javascript"/><title type='text'>JavaScript - An Example for Inheritance</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Everyone of us know, Inheritance is a way to acquire properties and methods of another object. In other words it is a way to establish is-a relationship between two objects. The static languages by default provide some easier ways to achieve this. For an example, we have &quot;extend&quot; keyword in Java for extending other object.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
JavaScript is protypal inheritance language (class-free) means that objects can inherit properties from other objects. Let&#39;s see an example.&lt;br /&gt;
&lt;br /&gt;
Let&#39;s create a parent class for Animal&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;/**
 * Animal - Constructor and parent class for all animals.
 * @param {Object} aType - Type of the animal
 * @param {Object} aName - Name of the animal 
 */

function Animal(aType, aName) {
 this.type = aType;
 this.name = aName;
}

Animal.prototype.eat = function() {
 console.log(&#39;All animal will eat&#39;);
};
&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
We have to do following steps for extending animal class.&lt;br /&gt;
&lt;br /&gt;
1. Calling super class constructor from child class constructor.&lt;br /&gt;
2. Setting up prototype chain.&lt;br /&gt;
3. Adding methods to child class.&lt;br /&gt;
&lt;br /&gt;
Let&#39;s create child class and extending Animal class by following above steps.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;/**
 * Bird - Constructor and child class of Animal.
 * @param {Object} aType - Type of the animal
 * @param {Object} aName - Name of the animal 
 */

function Bird(aType, aName, bType) {
 //Calling super class constructor
 Animal.call(this, aType, aName);
 this.birdType = bType;
}
//Setup the protype chain
Bird.prototype = new Animal();
//Set the constructor attribute to Bird
Bird.prototype.constructor = Bird;

//Add methods to Bird class.
Bird.prototype.fly = function() {
 console.log(&#39;I am flying&#39;);
};
&lt;/pre&gt;
&lt;br /&gt;
Let&#39;s create an object for Bird and try to access methods and properties of the parent class.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:java&quot;&gt;bird = new Bird(&#39;Ducks&#39;, &#39;Tundra Swan&#39;, &#39;Ducks&#39;);
bird.eat(); //Calling super class method
bird.fly(); //Calling child class method
&lt;/pre&gt;
&lt;br /&gt;
Final result of the application is given below.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikxfHF4uu_JEOe3lh05y9O1rMCbFgISKsSYTRljmKrMXQ3cE_Rjt11rmQZwWsrHPbtDl7c5OxvVHtc-nlbG2ZIUvKczXA7le4ljEFW3qAbpOKtIXbmqNdZwPPUvdLFVEbNEggkB8NJkeu3/s1600/Screen+Shot+2013-10-20+at+12.35.22+AM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikxfHF4uu_JEOe3lh05y9O1rMCbFgISKsSYTRljmKrMXQ3cE_Rjt11rmQZwWsrHPbtDl7c5OxvVHtc-nlbG2ZIUvKczXA7le4ljEFW3qAbpOKtIXbmqNdZwPPUvdLFVEbNEggkB8NJkeu3/s320/Screen+Shot+2013-10-20+at+12.35.22+AM.png&quot; height=&quot;147&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
All modern library like jQuery and Ext JS has provided simple utility function for extending other class something like that.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;var Pointer = Pointer || {};
/**
 * Simple utility function for extend.
 */
Pointer.extend = function(subClass, superClass) {
 var F = function() {};
 F.prototype = superClass.prototype;
 subClass.prototype = new F(); 
 subClass.prototype.constructor = subClass;
 
 subClass.superclass = superClass.prototype;
 /**
  * The below condition is important for handling
  * extend(Person, Object); //Person - Sample class extending JavaScript Object class.
  */
 if(superClass.prototype.constructor === Object.prototype.constructor) {
  superClass.prototype.constructor = superClass;
 }
};
&lt;/pre&gt;
&lt;br /&gt;
Simple another example using above extend function.&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;/**
 * This is parent class constructor
 * @param {Object} name
 */
var Person = function(name) {
 Person.superclass.constructor.call(this, name);
 this.name = name;
};

Pointer.extend(Person, Object); //Person is extending Object class.

Person.prototype.getName = function() {
 return this.name;
};

/**
 * This is child class of the Person.
 * 
 * @param {Object} name
 * @param {Object} profession
 */
var Author = function(name, profession) {
 //Person.call(this, name);
 Author.superclass.constructor.call(this, name);
 this.profession = profession;
};

Pointer.extend(Author, Person);

Author.prototype.getProfession = function() {
 return this.profession;
};
&lt;/pre&gt;
&lt;br /&gt;
For testing, let&#39;s create some objects.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;person1 = new Author(&#39;Suriya&#39;, &#39;Solution Developer&#39;);
person2 = new Person(&#39;Hilar&#39;);
&lt;/pre&gt;
&lt;br /&gt;
The result of the above example is should be something like this.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0n-9pz3TdpsVOpF2OwP0KHBHHxQOxvkIMWg7waM9OJ18cl7iFW8GjpkZ8tgC2RNm2V0AMWz6Lx59zMIKQ3p6qU_2UyIEy-Onnut9rRu8tMq7pAvi4yC6ycB8KLkD0Iwb_0mK1uFYcC9Xp/s1600/Screen+Shot+2013-10-20+at+1.13.36+AM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh0n-9pz3TdpsVOpF2OwP0KHBHHxQOxvkIMWg7waM9OJ18cl7iFW8GjpkZ8tgC2RNm2V0AMWz6Lx59zMIKQ3p6qU_2UyIEy-Onnut9rRu8tMq7pAvi4yC6ycB8KLkD0Iwb_0mK1uFYcC9Xp/s320/Screen+Shot+2013-10-20+at+1.13.36+AM.png&quot; height=&quot;181&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.pointerunits.com/feeds/1144832408097448173/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1569789499442484210/1144832408097448173' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/1144832408097448173'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/1144832408097448173'/><link rel='alternate' type='text/html' href='http://www.pointerunits.com/2013/10/javascript-example-for-inheritance.html' title='JavaScript - An Example for Inheritance'/><author><name>Gnanasuriyan</name><uri>http://www.blogger.com/profile/00525742121019222480</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjL7B6Ihy-xFMB19J-LEHU17qD7kpYY5iUfvlkSSOLR05wDJog8MuQDxNjJTrxAl3duQVgP9Fm4pwYHqA7aMlWMswcUyeTtax-3KogXfLJqN7Uk7sX7N2iEXVKNB54lplQ/s220/IMG_0826.JPG'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikxfHF4uu_JEOe3lh05y9O1rMCbFgISKsSYTRljmKrMXQ3cE_Rjt11rmQZwWsrHPbtDl7c5OxvVHtc-nlbG2ZIUvKczXA7le4ljEFW3qAbpOKtIXbmqNdZwPPUvdLFVEbNEggkB8NJkeu3/s72-c/Screen+Shot+2013-10-20+at+12.35.22+AM.png" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1569789499442484210.post-4624100747234427035</id><published>2013-10-19T09:25:00.000-07:00</published><updated>2013-10-21T06:38:42.585-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Design Pattern"/><category scheme="http://www.blogger.com/atom/ns#" term="Javascript"/><title type='text'>JavaScript - An example for Singleton pattern</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
The singleton pattern is a design pattern that restricts instantiation of the class to one object. This pattern is very handy when one object is enough for doing some operation across the entire system. Let&#39;s see an example.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;/**
 * Single global namespace for an entire application with lazy loading.
 * @Singleton pattern
 */

var PUS = PUS || {};

PUS = (function(){
 //Private variables and methods
 var appVersion = 0.1,
  instance = null;
 function constructor() {
  console.log(&#39;Object has created&#39;);
   return {
    getAppVersion : function() {
    return appVersion;
   }
   };
 };
 return {
  getInstance : function() {
   if(!instance) {
    instance = constructor();
   }
   return instance;
  }
 };
})();
&lt;/pre&gt;
&lt;div&gt;
&lt;br /&gt;
Here PUS object contains one public method called &quot;getInstance&quot;. If we call PUS. getInstance() method, that will first check whether an object is already created or not. The object is already exists then will return the reference of an existing object, otherwise it will create a new instance and return that instance (Lazy initialization). Sample usage is given below.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJGQy7kfdEWjh3TnWwDhs7Ct_Udlnnmt35jwzA5YOzZV4RDvOuhC2t-jJ-q0P0U9L0ivvnp3CebBZhxQoTmELAXNbtaw2wRG30wZKzz8OPWUyUCKa5Ua7X8FiK8xhpIdnc98yXTfk78vrl/s1600/Screen+Shot+2013-10-19+at+9.52.47+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;72&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJGQy7kfdEWjh3TnWwDhs7Ct_Udlnnmt35jwzA5YOzZV4RDvOuhC2t-jJ-q0P0U9L0ivvnp3CebBZhxQoTmELAXNbtaw2wRG30wZKzz8OPWUyUCKa5Ua7X8FiK8xhpIdnc98yXTfk78vrl/s320/Screen+Shot+2013-10-19+at+9.52.47+PM.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.pointerunits.com/feeds/4624100747234427035/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1569789499442484210/4624100747234427035' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/4624100747234427035'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/4624100747234427035'/><link rel='alternate' type='text/html' href='http://www.pointerunits.com/2013/10/javascript-singleton-pattern-example.html' title='JavaScript - An example for Singleton pattern'/><author><name>Gnanasuriyan</name><uri>http://www.blogger.com/profile/00525742121019222480</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjL7B6Ihy-xFMB19J-LEHU17qD7kpYY5iUfvlkSSOLR05wDJog8MuQDxNjJTrxAl3duQVgP9Fm4pwYHqA7aMlWMswcUyeTtax-3KogXfLJqN7Uk7sX7N2iEXVKNB54lplQ/s220/IMG_0826.JPG'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJGQy7kfdEWjh3TnWwDhs7Ct_Udlnnmt35jwzA5YOzZV4RDvOuhC2t-jJ-q0P0U9L0ivvnp3CebBZhxQoTmELAXNbtaw2wRG30wZKzz8OPWUyUCKa5Ua7X8FiK8xhpIdnc98yXTfk78vrl/s72-c/Screen+Shot+2013-10-19+at+9.52.47+PM.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1569789499442484210.post-2502819600910187483</id><published>2013-10-19T08:32:00.002-07:00</published><updated>2013-10-21T06:11:03.523-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Javascript"/><title type='text'>Static members in JavaScript</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
JavaScript static variables and methods are associated with the class, rather than with any object(similar to Java). Every instance of the same class has access to static members and rights to modify the values and method behavior at run-time. Let&#39;s see an example.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;var Person = function(fName, lName) {
 this.firstName = fName;
 this.lastName = lName;
 Person.objectCounts++;
};
//Static variable.
Person.objectCounts = 0;
//Static method.
Person.getObjectInformation = function() {
 return Person.objectCounts;
};
&lt;/pre&gt;
&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Here the variable objectCounts is a static variable and getObjectInformation is a static method. If we create any object for Person class, the static variable &quot;objectCounts&quot; value is incremented by one. The method getObjectInformation is used for getting &quot;objectCounts&quot; value.&lt;/div&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;var person1 = new Person(&#39;Suriya&#39;, &#39;A&#39;);
var person2 = new Person(&#39;John&#39;, &#39;H&#39;);&lt;/pre&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Here there are two objects created for Person class. Let&#39;s try to access static members of Person class by using class name.
&lt;/div&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;//Accessing static variable.
console.log(&#39;Accessing static variable by using class name : &#39; + Person.objectCounts);
//Accessing static method.
console.log(&#39;Calling static method by using class name : &#39; + Person.getObjectInformation());
&lt;/pre&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
JavaScript allows to modify value of the static variable and method behavior at run time. The changes in static members are immediately reflect to other objects. For an example, here I have modified getObjectInformation behavior and it&#39;s reflect to other object immediately.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;//modifying static method
Person.getObjectInformation = function() {
 return &quot;Bahaviour has modified : &quot; + Person.objectCounts;
};
console.log(Person.getObjectInformation()); 
&lt;/pre&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;
The final result of the above example is given below.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBDh7wMp_EgCkHU1PCazZeaFTRfGto7HOmfLO9GvBlwrfUNHQvSMSzD3UPUk8uhvMiS6na3niuetkcnrRlG8w92K-22AZ6sLsJuI4oTLHFkt1PazfOareBMy2xWmU8mwKa8FDAsVbezkR0/s1600/Screen+Shot+2013-10-19+at+9.00.37+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;52&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBDh7wMp_EgCkHU1PCazZeaFTRfGto7HOmfLO9GvBlwrfUNHQvSMSzD3UPUk8uhvMiS6na3niuetkcnrRlG8w92K-22AZ6sLsJuI4oTLHFkt1PazfOareBMy2xWmU8mwKa8FDAsVbezkR0/s320/Screen+Shot+2013-10-19+at+9.00.37+PM.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.pointerunits.com/feeds/2502819600910187483/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1569789499442484210/2502819600910187483' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/2502819600910187483'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/2502819600910187483'/><link rel='alternate' type='text/html' href='http://www.pointerunits.com/2013/10/static-members-in-javascript.html' title='Static members in JavaScript'/><author><name>Gnanasuriyan</name><uri>http://www.blogger.com/profile/00525742121019222480</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjL7B6Ihy-xFMB19J-LEHU17qD7kpYY5iUfvlkSSOLR05wDJog8MuQDxNjJTrxAl3duQVgP9Fm4pwYHqA7aMlWMswcUyeTtax-3KogXfLJqN7Uk7sX7N2iEXVKNB54lplQ/s220/IMG_0826.JPG'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBDh7wMp_EgCkHU1PCazZeaFTRfGto7HOmfLO9GvBlwrfUNHQvSMSzD3UPUk8uhvMiS6na3niuetkcnrRlG8w92K-22AZ6sLsJuI4oTLHFkt1PazfOareBMy2xWmU8mwKa8FDAsVbezkR0/s72-c/Screen+Shot+2013-10-19+at+9.00.37+PM.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1569789499442484210.post-7899597469939038714</id><published>2013-09-01T21:09:00.000-07:00</published><updated>2013-09-07T10:09:16.117-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Javascript"/><title type='text'>Object Oriented JavaScript - Part I</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h4 style=&quot;color: #222222; font-size: 16px; text-align: justify;&quot;&gt;
What is JavaScript?&lt;/h4&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
JavaScript is a prototype based scripting language with dynamic typing and has first-class functions. Previously it is mostly used in web and mobile browser application development. These days it is used for performing server side operation. The best example is Node JS.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h4 style=&quot;color: #222222; font-size: 16px; text-align: justify;&quot;&gt;
What is static and dynamic languages?&lt;/h4&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
In static languages, the process of verifying &amp;amp; enforcing constraints of type and identifying the behaviour of the code can happens at compile time itself. Some of the static languages are Java, C#, etc.,&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
In dynamic languages the above process is can happens only at run time. This feature will helps to include new code, modifying type systems, and extending objects at run time.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h4 style=&quot;color: #222222; font-size: 16px; text-align: justify;&quot;&gt;
What is first-class functions?&lt;/h4&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
In many languages like Java and C# have some options for defining class. For an example, this is my Person class in Java.
&lt;/div&gt;
&lt;pre class=&quot;brush:java&quot;&gt;class Person {
  String firstName;
  String lastName;
}
&lt;/pre&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
In JavaScript we don&#39;t have any keyword like &quot;class&quot; for defining classes. In JavaScript all functions are considered as a class. So we can define a class by using function in JavaScript and this is called as first-class functions. The equivalent Person class in JavaScript is written by something like this.&lt;/div&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;function Person() {
  this.firstName;
  this.lastName;
}
&lt;/pre&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Object oriented programming has lot of features like Encapsulation, Polymorphism, and Inheritance. It is possible in JavaScript for achieving all the OOP features and for becoming a better JavaScript programmer, we should know that.&lt;/div&gt;
&lt;br /&gt;
&lt;h4 style=&quot;color: #222222; font-size: 16px;&quot;&gt;
Public, Privileged and Private members in JavaScript.&lt;/h4&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The public members are always visible to public means any functions can read, modify and delete members, or add new members of the object. There are two ways for putting members in a new object.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
By using constructor - This way commonly used for initializing public member variables. For an example,&lt;/div&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;function Person(fname, lname) {
  this.firstName = fname;
  this.lastName = lname;
}
&lt;/pre&gt;
By using prototype - This way commonly used for adding public member to an object. For an example,&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;Person.prototype.getFirstName = function() {
  return this.firstName;
}
Person.prototype.getLastName = function() {
  return this.lastName;
}
Person.prototype.setFirstName = function(fname) {
  this.firstName = fname;
}
Person.prototype.setLastName = function(lname) {
  this.lastName = lname;
}
&lt;/pre&gt;
&lt;br /&gt;
Lets see how to create an object &amp;nbsp;and invoke member function.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;var person1 = new Person(&#39;Suriya&#39;, &#39;A&#39;);
person1.getFirstName(); //Result = Suriya
person1.setFirstName(&#39;Gnana&#39;);
person1.getFirstName(); //Result = Gnana
&lt;/pre&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
We have created public members in javaScript. Lets discuss a way for creating private members in JavaScript and this is a way for encapsulating data from outside.&lt;/div&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;function Person(fname, lname) {
 var firstName = fname; //Private variable 1

 var lastName = lname; //Private variable 2

        var fullName = function() { //Private function 1
  return firstName + &#39;, &#39; + lastName;
 }

 this.setFirstName = function(fname) { //Privileged method 1
  firstName = fname;
 }

 this.setLastName = function(lname) { //Privileged method 2
  lastName = lname;
 }

 this.getFirstName = function() {//Privileged method 3 
  return firstName;
 }

 this.getLastName = function() { //Privileged method 4 
  return lastName;
 }

 this.getFullName = function() { //Privileged method 5
  return fullName();
 }
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Privileged methods can have access for private variables and methods. It is possible to delete or replace a privileged method but we can&#39;t alter this method or we can&#39;t force this method for displaying internal information of an object. Lets test the Person class by creating new object and invoking its methods.&lt;/div&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;var person1 = new Person(&#39;Suriya&#39;, &#39;A&#39;);
person1.getFullName(); // Result - Suriya , A
&lt;/pre&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The private members are defined by without using &quot;this&quot; and they are declared like a normal variable declaration in JavaScript. Here the variables firstName and lastName are private variables and that are not accessible from outside of an object. For an example, we can&#39;t access the firstName and lastName property directly by executing below code.&lt;/div&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;person1.firstName; // Result - undefined
&lt;/pre&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
We know JavaScript is a dynamic language that allows to modify the object at run time. What I am going to do is, after creating an object for a Person class, going to override some of the privileged member functions of an object and trying to get access of the private variables. The pure object oriented programming won&#39;t allow to access private variables, but it is a time to test JavaScript.&lt;/div&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;var person1 = new Person(&#39;Suriya&#39;, &#39;A&#39;);
person1.getFullName(); // Result - Suriya , A
person1.setFirstName = function(fname) { //
  firstName = fname;
}
person1.setFirstName(&#39;Gnana&#39;);
person1.getFirstName() //Result should be &#39;Suriya&#39; not &#39;Gnana&#39;. 
&lt;/pre&gt;
&lt;br /&gt;
Check the below screen.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipBQYOlASYrPH5fa5AXjOZ1UagsHgOpNzBTrwe1VcHde6sn1cS_F5MDPKvInvMJ9gBt_2KNHWxbCc_ujpCuJNHPbn3FehEpU24avE5RxGuFVRnAchv_P4L9aIIahAt2gy5B0TmLO51kRa7/s1600/Screen+Shot+2013-09-02+at+9.33.45+AM.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;114&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipBQYOlASYrPH5fa5AXjOZ1UagsHgOpNzBTrwe1VcHde6sn1cS_F5MDPKvInvMJ9gBt_2KNHWxbCc_ujpCuJNHPbn3FehEpU24avE5RxGuFVRnAchv_P4L9aIIahAt2gy5B0TmLO51kRa7/s320/Screen+Shot+2013-09-02+at+9.33.45+AM.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
So in JavaScript we can&#39;t access private members from outside world without getting help from privileged or public methods.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Now we have created Public, Private and Privileged variables and methods in JavaScript. In my next part will explain about Inheritance and other object oriented implementations in JavaScript.&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.pointerunits.com/feeds/7899597469939038714/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1569789499442484210/7899597469939038714' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/7899597469939038714'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/7899597469939038714'/><link rel='alternate' type='text/html' href='http://www.pointerunits.com/2013/09/object-oriented-javascript-part-i.html' title='Object Oriented JavaScript - Part I'/><author><name>Gnanasuriyan</name><uri>http://www.blogger.com/profile/00525742121019222480</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjL7B6Ihy-xFMB19J-LEHU17qD7kpYY5iUfvlkSSOLR05wDJog8MuQDxNjJTrxAl3duQVgP9Fm4pwYHqA7aMlWMswcUyeTtax-3KogXfLJqN7Uk7sX7N2iEXVKNB54lplQ/s220/IMG_0826.JPG'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipBQYOlASYrPH5fa5AXjOZ1UagsHgOpNzBTrwe1VcHde6sn1cS_F5MDPKvInvMJ9gBt_2KNHWxbCc_ujpCuJNHPbn3FehEpU24avE5RxGuFVRnAchv_P4L9aIIahAt2gy5B0TmLO51kRa7/s72-c/Screen+Shot+2013-09-02+at+9.33.45+AM.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1569789499442484210.post-3580504950962272574</id><published>2013-05-29T12:02:00.001-07:00</published><updated>2013-05-29T13:40:09.039-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Grails"/><title type='text'>Developing First Grails Application</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: #660000;&quot;&gt;Grails - Introduction&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Grails is a modern web development framework that mixes the features of some important frameworks like Spring (IoC, MVC, AOP) and Hibernate. The Grails uses a Groovy as a programming language that runs on JVM and seamlessly integrates with Java language. The goal of Grails is simplifying Java enterprise web application development.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The important feature of Grails is convention over configuration (Rails developers knows very well), means that your application auto-wires itself based on some common-sense naming schemes, instead of using XML configuration files.&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The scaffolding is an another important feature of Grails, that will automatically creates a basic CURD interface for your domain class.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: #660000;&quot;&gt;Grails - Architecture&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJRI3yyqiqFa74ZRibYL3EWpu2WLspQcnGx4WSAIMEQTthW9v5nGD7sM1wkiDL3wAyh55g7zRQE6cfhtf_mHftbIzm3GYyZHYG_CrBhqBO4tjuuDNQ-SWM5pfD-I9iAsr_20SDgUgMU7Nc/s1600/IMG_0309.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;189&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJRI3yyqiqFa74ZRibYL3EWpu2WLspQcnGx4WSAIMEQTthW9v5nGD7sM1wkiDL3wAyh55g7zRQE6cfhtf_mHftbIzm3GYyZHYG_CrBhqBO4tjuuDNQ-SWM5pfD-I9iAsr_20SDgUgMU7Nc/s320/IMG_0309.JPG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: #660000;&quot;&gt;Installing and configuring Grails&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
1. &lt;a href=&quot;http://grails.org/download&quot; target=&quot;_blank&quot;&gt;Here&lt;/a&gt; you can download the binary distribution of the Grails. After downloading just unzip it.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
2. Create the GRAILS_HOME environment variable.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
3. Add $GRAILS_HOME/bin to the path.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: #660000;&quot;&gt;Creating a new Grails application&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The command &quot;&lt;b&gt;grails create-app app-name&lt;/b&gt;&quot; is used for creating new Grails application. Once you execute this command, the grails automatically creates necessary files and folder structure for you. It will be more easy, If you are using any IDE like GGTS, STS, Eclipse, and&amp;nbsp;IntelliJ.&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The general folder structure of the application is given below. Here I have given application name as &quot;&lt;b&gt;Grails-HelloWorld&lt;/b&gt;&quot;.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi79BcEMfW0SS4xxvruFfNJFGULMMZ8GR2VJbZkobHxYnPrrKgyfPdJT8A7Drxn8G9zydfHWSpZQXZwyQWLj_g1k5PFHHvWQAvYhcwjS1URXPyy_PkeOC_OYxpZH-uod9cnumaHnIMUi9Qj/s1600/package_str.jpeg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi79BcEMfW0SS4xxvruFfNJFGULMMZ8GR2VJbZkobHxYnPrrKgyfPdJT8A7Drxn8G9zydfHWSpZQXZwyQWLj_g1k5PFHHvWQAvYhcwjS1URXPyy_PkeOC_OYxpZH-uod9cnumaHnIMUi9Qj/s320/package_str.jpeg&quot; width=&quot;142&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #660000;&quot;&gt;Creating a controller&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The command “&lt;b&gt;grails create-controller controller-name&lt;/b&gt;” is used for creating a new controller in Grails application.&amp;nbsp;Let us create a controller called &quot;&lt;b&gt;User&lt;/b&gt;&quot; by executing a command called &quot;&lt;b&gt;grails create-controller com.pointerunits.User&lt;/b&gt;&quot;.&lt;br /&gt;
&lt;br /&gt;
Now we can see one new controller class in controllers directory and initial source code of the controller is given below.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;pre class=&quot;brush:java&quot;&gt;package com.pointerunits

class UserController {
    def index() { }
}
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
During controller creation, the grails automatically creates a new folder in views directory. The name of the folder is same as controller name. By default, Grails include the &quot;index&quot; action in every controller and by convention it is a default action for all controllers. So if you access a controller without any action, the controller automatically executes the index action.&lt;br /&gt;
&lt;br /&gt;
The Grails automatically creates the unit test class for all controllers, services and domain classes. So we can find a new unit test class for user controller in &lt;b&gt;test/unit&lt;/b&gt; directory.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDRB-fm4C0k0_LMrugUigIuRlV_YXhjdSxwdsJH4iUmkKR6nOFtkPh97pL91wZjYy5XEt3soghqaKu-p9qhUWUeAaRjxekUhootGpm1iGfKtvsElOmdjFSscG3noEoK-cZeU6zcPcGHxAl/s1600/view_folder_and_unit_test_controller.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgDRB-fm4C0k0_LMrugUigIuRlV_YXhjdSxwdsJH4iUmkKR6nOFtkPh97pL91wZjYy5XEt3soghqaKu-p9qhUWUeAaRjxekUhootGpm1iGfKtvsElOmdjFSscG3noEoK-cZeU6zcPcGHxAl/s320/view_folder_and_unit_test_controller.png&quot; width=&quot;173&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Now let us render some static html message to the browser.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:java&quot;&gt;package com.pointerunits

class UserController {

    def index() { 
		render &#39;&lt;h3&gt;
Welcome to Grails application development&lt;/h3&gt;
&#39;
	}
}
&lt;/pre&gt;
&lt;br /&gt;
Now just run the application by executing a command &quot;&lt;b&gt;grails run-app&lt;/b&gt;&quot;. If you want to change the port number of the server just include a -Dserver.port attribute like &quot;&lt;b&gt;grails -Dserver.port=8090 run-app&lt;/b&gt;&quot;.&lt;br /&gt;
&lt;br /&gt;
Now you can access your application by using a url &quot;&lt;b&gt;http://localhost:8080/Grails-HelloWorld&lt;/b&gt;&quot;. Here &quot;&lt;b&gt;8080&lt;/b&gt;&quot; indicate my server port number and &quot;&lt;b&gt;Grails-HelloWorld&lt;/b&gt;&quot; indicate my application name.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgW6anyuAiYCtZRfWOMgqruk8QQ3e6l6UH-gJJMbEMkF6rT08FdL6qZTkA1s6MqOQK9o7oZnWbyVTGUOE4IGGWjb7Wg1TMtUOznVZDp1NOHRYhtZSI7gugTXFnRz7Ul1R-WRT9FAtjAPI3z/s1600/Home.jpeg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;179&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgW6anyuAiYCtZRfWOMgqruk8QQ3e6l6UH-gJJMbEMkF6rT08FdL6qZTkA1s6MqOQK9o7oZnWbyVTGUOE4IGGWjb7Wg1TMtUOznVZDp1NOHRYhtZSI7gugTXFnRz7Ul1R-WRT9FAtjAPI3z/s320/Home.jpeg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
The above one is default home page of the grails application. We can modify this one according our needs. Now we can access our controller by using a URL &quot;&lt;b&gt;http://localhost:8080/Grails-HelloWorld/user/index&lt;/b&gt;&quot;. In this URL, the &lt;b&gt;user&lt;/b&gt; indicate the controller name and &lt;b&gt;index&lt;/b&gt; indicate the action name of the controller that you want to execute. Here index action is not required, because by convention the default action for controller is index.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLXcwztKFkGiZ3iumZ5YmfVJ7fgUo_oE6KxN6CwoOcqo5uBhnoh5HMKbf0353jsnPSPIt4vld9R6zHXc1GoutOoNOamGRT3PVS3Zrg4sVD-d1rwHpa5tHmgMy07DqlEtn3JDS_RJuwmFpJ/s1600/controller_index.jpeg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;78&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLXcwztKFkGiZ3iumZ5YmfVJ7fgUo_oE6KxN6CwoOcqo5uBhnoh5HMKbf0353jsnPSPIt4vld9R6zHXc1GoutOoNOamGRT3PVS3Zrg4sVD-d1rwHpa5tHmgMy07DqlEtn3JDS_RJuwmFpJ/s320/controller_index.jpeg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #660000;&quot;&gt;Creating a view&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Instead of rendering some static html from controller, let us rendering some GSP (Groovy Server Page) view. In grails, you have to create a GSP page based on action name. As of now we have only one action called &quot;Index&quot;, but now I am going to create one more action called &quot;&lt;b&gt;create&lt;/b&gt;&quot;. This is my modified user controller.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:java&quot;&gt;package com.pointerunits

class UserController {

    def index() { 
		render &#39;&lt;h3&gt;
Welcome to Grails application development&lt;/h3&gt;
&#39;
	}
	
	def create() {
		
	}
}
&lt;/pre&gt;
&lt;br /&gt;
Now just use the URL &quot;http://localhost:8080/Grails-HelloWorld/user/create&quot; for accessing create action of the user controller.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxpUbTyy-UwO7gv7hl_hbiIlIIdF0XRi_IFMI4X8SccWqfOfAKBZ8st203keMTfwf0ujFXo67kQ5VBdLi_p9Tg1ADsnhYpN0qMkZHXbOtDfoH3Yrft9ckUlcBRHSgImb5cpWruH85VILDL/s1600/404_gsp.jpeg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;103&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxpUbTyy-UwO7gv7hl_hbiIlIIdF0XRi_IFMI4X8SccWqfOfAKBZ8st203keMTfwf0ujFXo67kQ5VBdLi_p9Tg1ADsnhYpN0qMkZHXbOtDfoH3Yrft9ckUlcBRHSgImb5cpWruH85VILDL/s320/404_gsp.jpeg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
By default, the above URL is trying to load a &quot;create.gsp&quot; page from &quot;views/user&quot; directory, but as of now we don&#39;t create any page like that. Here the name of the GSP page should be the name of the controller action. Let us create a &quot;create.gsp&quot; under &quot;views/user&quot; folder.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEih2PM4EZ_md624TrIcEv76d7iKVGCPbAGGtWcTGQCD64Bo02-IXQl_4elKnFX8bTuJI3XT8Deo6S66gwBZxoxMdj0ZKndXXZkVWy6M2tLR4GW0C8mdSAHRRU4jgi9X4dCKKmbMk2fgXpXL/s1600/create_gsp.jpeg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;209&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEih2PM4EZ_md624TrIcEv76d7iKVGCPbAGGtWcTGQCD64Bo02-IXQl_4elKnFX8bTuJI3XT8Deo6S66gwBZxoxMdj0ZKndXXZkVWy6M2tLR4GW0C8mdSAHRRU4jgi9X4dCKKmbMk2fgXpXL/s320/create_gsp.jpeg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Now just access the same URL, you can see the result like this.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUqwfGS0Z77kh_vjjitZirfwOJss0jVnvCm063ACYUxnrwthiANw-W3ktp-qKweC3OYwj8k-HZVlVubGsarA9Kv_YIlSY8vetlxtwoH3b-IR5UZxDXAef-LdaEMwsopZpU29kBnxdPK4my/s1600/create_gsp.jpeg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;113&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUqwfGS0Z77kh_vjjitZirfwOJss0jVnvCm063ACYUxnrwthiANw-W3ktp-qKweC3OYwj8k-HZVlVubGsarA9Kv_YIlSY8vetlxtwoH3b-IR5UZxDXAef-LdaEMwsopZpU29kBnxdPK4my/s320/create_gsp.jpeg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #660000;&quot;&gt;Creating a domain class&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The command &quot;&lt;b&gt;grails create-domain-class class-name&lt;/b&gt;&quot; is used for creating a new domain class in grails application. Let us create a &quot;&lt;b&gt;Person&lt;/b&gt;&quot; domain class by executing a command &quot;g&lt;b&gt;rails create-domain-class com.pointerunits.Person&lt;/b&gt;&quot;.&lt;br /&gt;
&lt;pre class=&quot;brush:java&quot;&gt;package com.pointerunits

class Person {
	String firstName
	String lastName
	String email
	String phoneNumber
	Integer age
	
    static constraints = {
    }
}
&lt;/pre&gt;
&lt;br /&gt;
By default, Grails comes with HSQLDB and when new application created, by default three databases(devDb, testDB, prodDb) are configured in Datasource.groovy for three different environments (development, testing and production). In above domain class, we have included only some basic variables. Now the Grails automatically maps this domain class into Person table and every variables are mapped into corresponding column of the table. No more XML file needed like Hibernate. No worry, the Grails gives full freedom for customizing those behaviours. &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #660000;&quot;&gt;Scaffolding&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
We know, scffolding is a feature that will create a basic CURD interface for your domain class automatically. Let us see how to do that.&lt;br /&gt;
&lt;br /&gt;
First of all we need to create one more controller for Person domain class and need to include one line of code like &quot;&lt;b&gt;def scaffold = Person&lt;/b&gt;&quot;. The Grails will takes care other works for you. This is my source code of my Person controller.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:java&quot;&gt;package com.pointerunits

class PersonController {
	
	def scaffold = Person
	
    def index() { }
}
&lt;/pre&gt;
&lt;br /&gt;
Now just load the URL &quot;&lt;b&gt;http://localhost:8080/Grails-HelloWorld/person/list&lt;/b&gt;&quot;, you will see basic CURD interface for your Person table.&lt;br /&gt;
&lt;br /&gt;
1. List action - Displays the all person details as a table.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggEYhwIfCmi3mc-7vGOiswqLFOT4kSoNA-IScJDJzHffdApC1wMnwqV1SByaQk81wMZ4h78qfXnfmFB145MXhYU3AJOfhIBcJduvmAeWyUmgeLN2B5W3GdifrYl0yC8G81azwAfcCo1Qda/s1600/404_gsp.jpeg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;107&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggEYhwIfCmi3mc-7vGOiswqLFOT4kSoNA-IScJDJzHffdApC1wMnwqV1SByaQk81wMZ4h78qfXnfmFB145MXhYU3AJOfhIBcJduvmAeWyUmgeLN2B5W3GdifrYl0yC8G81azwAfcCo1Qda/s320/404_gsp.jpeg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
2. Create action - All us to create a new Person. Example &quot;&lt;b&gt;http://localhost:8080/Grails-HelloWorld/create&lt;/b&gt;&quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjR1WKsL1aKycsnFNVFzCqFVuUfCLpIRsPGc7yWkzgZHmrgVFEp8zmidQLnBQNQPrZKOLxA8om33EP1Vr2GZXZoraZqnzOV94ZuDULRV4T8WPT5XAhig3SeDgB3RirkN_gr7A0Xl9obDnoH/s1600/New_Person.jpeg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;172&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjR1WKsL1aKycsnFNVFzCqFVuUfCLpIRsPGc7yWkzgZHmrgVFEp8zmidQLnBQNQPrZKOLxA8om33EP1Vr2GZXZoraZqnzOV94ZuDULRV4T8WPT5XAhig3SeDgB3RirkN_gr7A0Xl9obDnoH/s320/New_Person.jpeg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
3. Show action - Allow us view the information of particular record. Here we need to give index of the record as input through query string. Example &quot;&lt;b&gt;http://localhost:8080/Grails-HelloWorld/show/1&lt;/b&gt;&quot;. Here 1 indicates index of the record.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjj9xbaKElvvp4BQl_Ig7egqS9awJhvp_k8y4mAjVmPtuSoNNRQ2oTHs3z28oq-0dGifWaVDsjr3CqK_TV_lsgi4LA066iIm4WFliJ7luJ94jJ1g7maHhD7QANrLkc44A5y77A7D03h-773/s1600/show_1.jpeg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;183&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjj9xbaKElvvp4BQl_Ig7egqS9awJhvp_k8y4mAjVmPtuSoNNRQ2oTHs3z28oq-0dGifWaVDsjr3CqK_TV_lsgi4LA066iIm4WFliJ7luJ94jJ1g7maHhD7QANrLkc44A5y77A7D03h-773/s320/show_1.jpeg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
4. Delete action - Allow us to delete a particular record from database. It also require an index value of the record. Example &quot;&lt;b&gt;http://localhost:8080/Grails-HelloWorld/delete/1&lt;/b&gt;&quot;.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #660000;&quot;&gt;Conclusion&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
In this tutorial, we have created new grails application and created controllers, views, and domain classes. The scaffolding feature of grails is also demonstrated.&amp;nbsp;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.pointerunits.com/feeds/3580504950962272574/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1569789499442484210/3580504950962272574' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/3580504950962272574'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/3580504950962272574'/><link rel='alternate' type='text/html' href='http://www.pointerunits.com/2013/05/developing-first-grails-application.html' title='Developing First Grails Application'/><author><name>Gnanasuriyan</name><uri>http://www.blogger.com/profile/00525742121019222480</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjL7B6Ihy-xFMB19J-LEHU17qD7kpYY5iUfvlkSSOLR05wDJog8MuQDxNjJTrxAl3duQVgP9Fm4pwYHqA7aMlWMswcUyeTtax-3KogXfLJqN7Uk7sX7N2iEXVKNB54lplQ/s220/IMG_0826.JPG'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJRI3yyqiqFa74ZRibYL3EWpu2WLspQcnGx4WSAIMEQTthW9v5nGD7sM1wkiDL3wAyh55g7zRQE6cfhtf_mHftbIzm3GYyZHYG_CrBhqBO4tjuuDNQ-SWM5pfD-I9iAsr_20SDgUgMU7Nc/s72-c/IMG_0309.JPG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1569789499442484210.post-4783338770465463069</id><published>2013-02-12T20:18:00.001-08:00</published><updated>2013-03-19T21:10:11.280-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Ext JS"/><title type='text'>Ext JS 4 - Ajax Proxy</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Ajax proxy in Ext JS is most widely used one for reading and writing information from/to web server. The configuration of ajax proxy is applied either in store or model class and it is based on the following&amp;nbsp;criteria.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp; 1. We need to define our proxy configuration in model class whenever we need to reuse the same model in various stores with same proxy configuration.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp; 2. We need to define our proxy configuration in store class whenever we need to reuse the same model class in various stores with various proxy configuration.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Let&#39;s see an example for Ajax proxy. Here I am getting JSON data from web server and displaying those data by using grid component.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
User.js - Model&lt;/h3&gt;
&lt;div&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;Ext.define(&#39;MyApp.model.User&#39;,{
 extend : &#39;Ext.data.Model&#39;,
 
 fields : [{
  name : &#39;id&#39;, type : &#39;int&#39;
 }, {
  name : &#39;userName&#39;, type : &#39;String&#39;
 }, {
  name : &#39;email&#39;, type : &#39;String&#39;
 }]
 
});
  &lt;/pre&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3&gt;
User.js - Store&lt;/h3&gt;
&lt;div&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;Ext.define(&#39;MyApp.store.User&#39;,{
 extend : &#39;Ext.data.Store&#39;,
 storeId : &#39;users&#39;,
 //autoLoad : true,
 model : &#39;MyApp.model.User&#39;,
 proxy : {
  type : &#39;ajax&#39;,
  url : &#39;data/users.json&#39;,
  reader : {
   type : &#39;json&#39;,
   root : &#39;users&#39;,
   successProperty : &#39;success&#39;
  }
 }
});
  &lt;/pre&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;
Here, the important thing is proxy configuration. I have set the proxy type as &#39;ajax&#39; and specified the server URL for loading and updating data. We can use different URL for performing read and update operation.&lt;br /&gt;
&lt;br /&gt;
The &lt;a href=&quot;http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.reader.Reader&quot; target=&quot;_blank&quot;&gt;reader &lt;/a&gt;is another configuration is used for decoding server response and it updates the store based on the decoded information. Here I have used JSON reader, apart form JSON reader Ext JS provide some more readers like Array and XML. The reader is very handy if you are loading nested data from server.&lt;br /&gt;
&lt;br /&gt;
For performing read operation, ajax proxy send a GET request and for performing create, delete and update operations it send a POST request to server.&lt;br /&gt;
&lt;br /&gt;
We can&#39;t use ajax for reading information from other domains because it&#39;s&amp;nbsp;violating DOM security&amp;nbsp;principles&amp;nbsp;. For talking to other domains, we need to use JSONP proxy.&lt;br /&gt;
&lt;br /&gt;
In real application, we have to send some extra parameters to server. In this situation we need to use ajax proxy&amp;nbsp;&lt;b&gt;extraParams&lt;/b&gt; configuration.&lt;a href=&quot;http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.proxy.Ajax&quot; target=&quot;_blank&quot;&gt;&amp;nbsp;Check the Ext JS sencha documentation for getting more information about AJAX proxy&lt;/a&gt;.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3&gt;
UserList.js - View&lt;/h3&gt;
&lt;div&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;Ext.define(&#39;MyApp.view.UserList&#39;,{
 extend : &#39;Ext.panel.Panel&#39;,
 alias : &#39;widget.userlist&#39;,
 title : &#39;Users Information&#39;,
 width : 400,
 height : 300,
 items : [{
  xtype : &#39;gridpanel&#39;,
  store : &#39;User&#39;,
  columns : [{
   text : &#39;User Identity&#39;, dataIndex : &#39;id&#39;, flex : 1
  }, {
   text : &#39;User Name&#39;, dataIndex : &#39;userName&#39; , flex : 1
  }, {
   text : &#39;Email&#39;, dataIndex : &#39;email&#39;, flex : 1
  }]
 }]
});
&lt;/pre&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;
Here, I have used the grid component for displaying store data.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3&gt;
UserList.js - Controller&lt;/h3&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;Ext.define(&#39;MyApp.controller.UserList&#39;,{
 extend : &#39;Ext.app.Controller&#39;,
 models : [&#39;User&#39;],
 stores : [&#39;User&#39;],
 views : [&#39;UserList&#39;],
 
 init : function() {
  this.getStore(&#39;User&#39;).load();
  this.callParent();
 }
});
&lt;/pre&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
In controller init function, I have taken the User store handle and called the load function. In this situation, the ajax request is send to server for loading data.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;h3&gt;
app.js&lt;/h3&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;Ext.Loader.setConfig({
 enabled : true
});

Ext.application({
 name : &#39;MyApp&#39;,
 appFolder : &#39;app&#39;,
 controllers : [&#39;UserList&#39;],
 launch : function() {
  Ext.create(&#39;MyApp.view.UserList&#39;,{
   renderTo : Ext.getBody()
  });
 }
});
&lt;/pre&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;h3&gt;
Result&lt;/h3&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPZ0KPzoCnRenfMOVG5DDDK3FVgNlGSKP_WdHyN1391e7RMfQ_OVN3C6yflRtjstcs0hoHvWC4omB1Dt0JOBiaH-sT1mf_yfFxOk9LMv1oUf7nexebNfnyzvTRuSeisR5Rm9FFmg_Jo2b6/s1600/result.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;238&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPZ0KPzoCnRenfMOVG5DDDK3FVgNlGSKP_WdHyN1391e7RMfQ_OVN3C6yflRtjstcs0hoHvWC4omB1Dt0JOBiaH-sT1mf_yfFxOk9LMv1oUf7nexebNfnyzvTRuSeisR5Rm9FFmg_Jo2b6/s320/result.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;a href=&quot;https://github.com/gnanasuriyan/ExtJS4-Ajax-Proxy&quot; target=&quot;_blank&quot;&gt;The application source code is available in github repository.&amp;nbsp;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.pointerunits.com/feeds/4783338770465463069/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1569789499442484210/4783338770465463069' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/4783338770465463069'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/4783338770465463069'/><link rel='alternate' type='text/html' href='http://www.pointerunits.com/2013/02/ext-js4-ajax-proxy.html' title='Ext JS 4 - Ajax Proxy'/><author><name>Gnanasuriyan</name><uri>http://www.blogger.com/profile/00525742121019222480</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjL7B6Ihy-xFMB19J-LEHU17qD7kpYY5iUfvlkSSOLR05wDJog8MuQDxNjJTrxAl3duQVgP9Fm4pwYHqA7aMlWMswcUyeTtax-3KogXfLJqN7Uk7sX7N2iEXVKNB54lplQ/s220/IMG_0826.JPG'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPZ0KPzoCnRenfMOVG5DDDK3FVgNlGSKP_WdHyN1391e7RMfQ_OVN3C6yflRtjstcs0hoHvWC4omB1Dt0JOBiaH-sT1mf_yfFxOk9LMv1oUf7nexebNfnyzvTRuSeisR5Rm9FFmg_Jo2b6/s72-c/result.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1569789499442484210.post-2727566087257894594</id><published>2013-01-30T20:20:00.001-08:00</published><updated>2013-03-19T21:10:23.186-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Ext JS"/><title type='text'>Ext JS 4 - Form Panel With Menubar</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The form panel (&lt;b&gt;Ext.form.Panel&lt;/b&gt;) class in Ext JS is used for creating form. The default layout of the form panel is anchor. It has lot options for customization, in that one of the feature is menu bar. The following properties are used for including menu into form panel.&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp; 1. tbar - Top Bar&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp; 2. bbar - Bottom Bar&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp; 3. lbar - Left Bar&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp; 4. rbar - Right Bar&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Let&#39;s see an example for creating form panel with menu bar.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;Ext.define(&#39;MyApp.view.PanelWithMenuBar&#39;, {
 extend : &#39;Ext.form.Panel&#39;,
 alias : &#39;widget.panelwithtoolbar&#39;,
 layout : &#39;anchor&#39;,
 height : 400,
 width : 400,
 title : &#39;Form Panel with Menubar&#39;,
 url : &#39;/saveform&#39;,
 tbar : [{
  text : &#39;Top-Left Menu&#39;,
  menu : [{
   text : &#39;User&#39;,
   menuKey : &#39;top-left-create-user&#39;
  }, {
   text : &#39;Document&#39;,
   menuKey : &#39;top-left-create-document&#39;
  }, {
   text : &#39;Profile&#39;,
   menuKey : &#39;top-left-create-profile&#39;
  }]
 }, &#39;-&amp;gt;&#39;, {
  text : &#39;Top-Right Menu&#39;,
  menu : [{
   text : &#39;User&#39;,
   menuKey : &#39;top-right-create-user&#39;
  }, {
   text : &#39;Document&#39;,
   menuKey : &#39;top-right-create-document&#39;
  }, {
   text : &#39;Profile&#39;,
   menuKey : &#39;top-right-create-profile&#39;
  }]
 }],
 bbar : [{
  text : &#39;Bottom-Left Menu&#39;,
  menu : [{
   text : &#39;User&#39;,
   menuKey : &#39;bottom-left-create-user&#39;
  }, {
   text : &#39;Document&#39;,
   menuKey : &#39;bottom-left-create-document&#39;
  }, {
   text : &#39;Profile&#39;,
   menuKey : &#39;bottom-left-create-profile&#39;
  }]
 }, &#39;-&amp;gt;&#39;, {
  text : &#39;Bottom-Right Menu&#39;,
  menu : [{
   text : &#39;User&#39;,
   menuKey : &#39;bottom-right-create-user&#39;
  }, {
   text : &#39;Document&#39;,
   menuKey : &#39;bottom-right-create-document&#39;
  }, {
   text : &#39;Profile&#39;,
   menuKey : &#39;bottom-right-create-profile&#39;
  }]
 }],
 items : [{
  xtype : &#39;textfield&#39;,
  fieldLabel : &#39;First Name&#39;,
  name : &#39;firstName&#39;,
  allowBlank : false
 }, {
  xtype : &#39;textfield&#39;,
  fieldLabel : &#39;Last Name&#39;,
  name : &#39;lastName&#39;,
  allowBlank : false
 }],
 renderTo : Ext.getBody()
}); 
&lt;/pre&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Here the symbol &#39;&lt;b&gt;→&lt;/b&gt;&#39; &amp;nbsp;is used for moving our menu from left to right side.&lt;br /&gt;
&lt;br /&gt;
Here I have included &lt;b&gt;menuKey &lt;/b&gt;attribute, this is custom attribute included for taking handle of the menu actions in controller side. Let&#39;s see, how to take a control of form panel and corresponding form menu actions in controller. This is very tricky part when you are in&amp;nbsp;beginning stage and this is my controller code for above view.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;Ext.define(&#39;MyApp.controller.PanelWithMenuBar&#39;, {
 extend : &#39;Ext.app.Controller&#39;,
 init : function() {
  this.control({
   &#39;menuitem[menuKey]&#39; : {
    click : function(menuItem, e, eOpts) {
     switch(menuItem.menuKey) {
      case &#39;top-left-create-user&#39; :
       console.log(&#39;Event related to top-left-create-user&#39;);
       break;
      case &#39;top-left-create-document&#39; :
       console.log(&#39;Event related to top-left-create-document&#39;);
       break;
      case &#39;top-left-create-profile&#39; :
       console.log(&#39;Event related to top-left-create-profile&#39;);
       break;
      case &#39;bottom-right-create-user&#39; :
       console.log(&#39;Event related to bottom-right-create-user&#39;);
       break;
      case &#39;bottom-right-create-document&#39; :
       console.log(&#39;Event related to bottom-right-create-document&#39;);
       break;
      case &#39;bottom-right-create-profile&#39; :
       console.log(&#39;Event related to bottom-right-create-profile&#39;);
       break;
      //Other menukey actions will goes here.....
     }
    }
   }
  });
  this.callParent(arguments);
 }
});

&lt;/pre&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;
During rendering of an application, the Ext JS will create an object of &#39;&lt;b&gt;Ext.menu.Item&lt;/b&gt;&#39; for tbar, lbar, bbar, and rbar based on its configuration. So I can take a control of all menu items by using xtype and menuKey.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;menuitem[menuKey]&lt;/b&gt; - Here menuitem refer the xtype of &lt;b&gt;&#39;Ext.menu.Item&#39;&lt;/b&gt; and menuKey is our &lt;b&gt;custom attribute&lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;
The result of above example is given below.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0vykMyGz6br0TLGtVj58dVaRC7cPhecMqxUQ5WAtCc7EREqg6XAe6LglAGkgmZsyQjl4IONEBwzvdqK31IY-NvX8y7bf2fnLpveqIAfT1l6GDcxg_VfLyk0hgOxbLVKU1a7rUp6Pdhq53/s1600/FormPanelWithMenu.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;234&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0vykMyGz6br0TLGtVj58dVaRC7cPhecMqxUQ5WAtCc7EREqg6XAe6LglAGkgmZsyQjl4IONEBwzvdqK31IY-NvX8y7bf2fnLpveqIAfT1l6GDcxg_VfLyk0hgOxbLVKU1a7rUp6Pdhq53/s320/FormPanelWithMenu.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.pointerunits.com/feeds/2727566087257894594/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1569789499442484210/2727566087257894594' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/2727566087257894594'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/2727566087257894594'/><link rel='alternate' type='text/html' href='http://www.pointerunits.com/2013/01/ext-js4-form-panel-with-menubar.html' title='Ext JS 4 - Form Panel With Menubar'/><author><name>Gnanasuriyan</name><uri>http://www.blogger.com/profile/00525742121019222480</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjL7B6Ihy-xFMB19J-LEHU17qD7kpYY5iUfvlkSSOLR05wDJog8MuQDxNjJTrxAl3duQVgP9Fm4pwYHqA7aMlWMswcUyeTtax-3KogXfLJqN7Uk7sX7N2iEXVKNB54lplQ/s220/IMG_0826.JPG'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0vykMyGz6br0TLGtVj58dVaRC7cPhecMqxUQ5WAtCc7EREqg6XAe6LglAGkgmZsyQjl4IONEBwzvdqK31IY-NvX8y7bf2fnLpveqIAfT1l6GDcxg_VfLyk0hgOxbLVKU1a7rUp6Pdhq53/s72-c/FormPanelWithMenu.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1569789499442484210.post-7234017566269164674</id><published>2013-01-17T12:07:00.002-08:00</published><updated>2013-03-19T21:11:32.268-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Ext JS"/><title type='text'>Ext JS 4 - Client Proxies</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The web storage concepts in HTML5 are really cool and used for store/read data to/from browser memory. There are two types of web storage concepts available in HTML5.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp; &amp;nbsp; 1. Session storage - The data only availble for particular session.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp; &amp;nbsp; 2. Local storage - Long term storage and data is shared by various browser and tabs&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The Ext JS gives lot of&amp;nbsp;flexibility&amp;nbsp;for using web storage concepts and it do lot of operations internally and reduced the developer works. The most well known issues is, the HTML5 web storage concepts only allow to store a value like string, int, float and boolean&amp;nbsp;and it don&#39;t allow to store a complex objects like JSON. But Ext JS directly allows to store/read JSON data to/from web storage. Internally it performs serialize&amp;nbsp;and deserialize operation for store/read JSON data to/from web storage.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The proxies in Ext JS are used for performing above operation. There are three kind of client side proxies &amp;nbsp;available in Ext JS.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp; &amp;nbsp; 1. Session storage proxy&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp; &amp;nbsp; 2. Local storage proxy&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp; &amp;nbsp; 3. Memory proxy&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
These proxies are directly used by either in models or stores. Let&#39;s see an example for above proxies.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
1. Session storage proxy.&lt;/h4&gt;
&lt;div&gt;
&lt;span style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;text-align: justify;&quot;&gt;The session storage data is only available for particular session. Once the browser has closed, the data will be lost. I am going to store/read some basic information of the user like user name and display name by using session storage.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Let&#39;s create a simple model for user and we can reuse this model in various stores.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;Ext.define(&#39;MyApp.model.User&#39;,{
 extend : &#39;Ext.data.Model&#39;,
 fields : [
  {name : &#39;userId&#39;,type : &#39;int&#39;},
  {name : &#39;userName&#39;, type : &#39;string&#39;},
  {name : &#39;displayName&#39;, type : &#39;string&#39;}
 ]
});
&lt;/pre&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Let&#39;s create a session storage store. Here the proxy type &quot;sessionstorage&quot; indicates, the data is storing into session storage. The id property is a key for storing/reading values to/from session storage.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;Ext.define(&#39;MyApp.store.SessionStorageUser&#39;,{
 extend : &#39;Ext.data.Store&#39;,
 model : &#39;MyApp.model.User&#39;,
 proxy : {
  type : &#39;sessionstorage&#39;,
  id : &#39;userPreferences&#39;
 }
})
&lt;/pre&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;
Let&#39;s create a session storage controller and will see how to store a value and read a value by using session storage.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;Ext.define(&#39;MyApp.controller.SessionStorageController&#39;,{
 extend : &#39;Ext.app.Controller&#39;,
 models : [&#39;User&#39;],
 stores : [&#39;SessionStorageUser&#39;],
 init : function() {
  //Storing information to session storage
  var sessionStore = this.getStore(&#39;SessionStorageUser&#39;);
  sessionStore.load();
  sessionStore.add({userId:1,userName : &#39;suriyan&#39;,displayName : &#39;Suriya&#39;});
  sessionStore.sync();
  
  //Reading information from session storage
  sessionStore.load(function(records,operation,success) {
   //Here records is a array type. For testing purpose, I took first record.
   console.log(&#39;User name : &#39; + records[0].get(&#39;userName&#39;) + &#39;, display name : &#39; + records[0].get(&#39;displayName&#39;));
  });
  
  console.log(&#39;Session storage operation has completed&#39;);
 }
});
&lt;/pre&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;
The result of the above code is as shown below.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJDID2A503NypPnboP1r82mylI0ONI07309ZeUOfAbtZOqQ0-gT-UBf-EC42LcLJg_Phvz9CfvKrgmQ8BV4qQS05N9uLtq2bkdELZWxkceFossMpR7hDUq5jJZxlNp0ClC_TPY5g6ei5yn/s1600/SessionStorage.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;68&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJDID2A503NypPnboP1r82mylI0ONI07309ZeUOfAbtZOqQ0-gT-UBf-EC42LcLJg_Phvz9CfvKrgmQ8BV4qQS05N9uLtq2bkdELZWxkceFossMpR7hDUq5jJZxlNp0ClC_TPY5g6ei5yn/s320/SessionStorage.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhr8qfgONv_Shl5z7qePuw-h-Kh8BcHE5riabcqq-0_vM7tSH56ZEUaTgQj-VAFCGOKYzgqS-AoKx9yZvhTjHm0XRQcXmO5sMOU7hEolYDsgG5TBjZ1HuTjDyj-I7Ntra-KViiD6LoDga-3/s1600/SessionStorage1.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;104&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhr8qfgONv_Shl5z7qePuw-h-Kh8BcHE5riabcqq-0_vM7tSH56ZEUaTgQj-VAFCGOKYzgqS-AoKx9yZvhTjHm0XRQcXmO5sMOU7hEolYDsgG5TBjZ1HuTjDyj-I7Ntra-KViiD6LoDga-3/s320/SessionStorage1.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
2. Local storage proxy.&lt;/h4&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The local storage data is available for long time (until&amp;nbsp;removing data from local storage memory) and we can share the data between various browser/tabs.&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Let&#39;s create a local storage store. &lt;b&gt;Note : the proxy type of the store&lt;/b&gt;.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;Ext.define(&#39;MyApp.store.LocalStorageUser&#39;,{
 extend : &#39;Ext.data.Store&#39;,
 model : &#39;MyApp.model.User&#39;,
 proxy : {
  type : &#39;localstorage&#39;,
  id : &#39;userPreferences&#39;
 }
})
&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Let&#39;s create a local storage controller for testing above store.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;Ext.define(&#39;MyApp.controller.LocalStorageController&#39;,{
 extend : &#39;Ext.app.Controller&#39;,
 model : [&#39;User&#39;],
 stores : [&#39;LocalStorageUser&#39;],
 init : function() {
  //Getting handle of local storage store.
  var localStore = this.getStore(&#39;LocalStorageUser&#39;);
  
  //Adding information to local storage
  localStore.add({userId:1,userName : &#39;suriyan&#39;,displayName : &#39;suriya&#39;});
  localStore.sync();
  
  //Reading information from local storage
  localStore.load(function(records,operation,success){
   console.log(&#39;User name : &#39; + records[0].get(&#39;userName&#39;) + &#39;, display name : &#39; + records[0].get(&#39;displayName&#39;));
  });
  console.log(&#39;Local storage operation has completed&#39;);
 }
})
&lt;/pre&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The result of the above code is as shown below.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1chV6xTmn-sBdCGBD-rOyk-oQaHFW55psLKD59MSpIXuVC7508NpkgQQprWkd-jhmqG2meJXhmtaHv5khOxNfgECWoLplLSCXOpp_i-ilsDdkuIaSYc6ndpFRrNCn6IistEsDXtY16NdK/s1600/LocalStorage2.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;107&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1chV6xTmn-sBdCGBD-rOyk-oQaHFW55psLKD59MSpIXuVC7508NpkgQQprWkd-jhmqG2meJXhmtaHv5khOxNfgECWoLplLSCXOpp_i-ilsDdkuIaSYc6ndpFRrNCn6IistEsDXtY16NdK/s320/LocalStorage2.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgs7-OKkB8LQMftm5a0B8rHyYJgF-AnpFoXmMot4mNtUM9ipTE6RbvW63Zzd5WKryUqp6nJ9is2bD0LvuL3VUGQTi0wfsgiMLLLaeH51-QvHezE5yqJNw0svzCRwYvEuLQCG2ek0mm060I8/s1600/LocalStorage.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;67&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgs7-OKkB8LQMftm5a0B8rHyYJgF-AnpFoXmMot4mNtUM9ipTE6RbvW63Zzd5WKryUqp6nJ9is2bD0LvuL3VUGQTi0wfsgiMLLLaeH51-QvHezE5yqJNw0svzCRwYvEuLQCG2ek0mm060I8/s320/LocalStorage.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h4&gt;
3. Memory proxy.&lt;/h4&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Memory proxy is very useful whenever you want to store the data&amp;nbsp;temporally. The data will be lost on every page refresh. For an example, in my application I need to display list of countries to users for selection purpose. In this situation we can use our memory proxy concept for displaying country list. In future we want to add some more countries than, there is no need for modifying our existing code.&lt;/div&gt;
&lt;br /&gt;
Le&#39;s create a model for country.&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;Ext.define(&#39;MyApp.model.Country&#39;,{
 extend : &#39;Ext.data.Model&#39;,
 fields : [
  {name : &#39;id&#39;, type : &#39;int&#39;},
  {name : &#39;country&#39;, type : &#39;string&#39;}
 ]
});
&lt;/pre&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;
Let&#39;s create a store for country model, here check the proxy type.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;Ext.define(&#39;MyApp.store.CountryStore&#39;,{
 extend : &#39;Ext.data.Store&#39;,
 model : &#39;MyApp.model.Country&#39;,
 data : countryData,
 proxy : {
  type : &#39;memory&#39;,
  reader : {
   type : &#39;json&#39;,
   root : &#39;countryList&#39;
  }
 }
});
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Let&#39;s create a combobox for testing above store. Note: I am following MVC pattern and this is my country view.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;Ext.define(&#39;MyApp.view.Country&#39;,{
 extend : &#39;Ext.panel.Panel&#39;,
 alias : &#39;widget.country&#39;,
 title : &#39;Memory proxy testing&#39;,
 layout : {
  type : &#39;vbox&#39;
 },
 height : 400,
 width : 400,
 items : [
  {
   xtype : &#39;combobox&#39;,
   store : &#39;CountryStore&#39;,
   fieldLabel : &#39;Select a country&#39;,
   displayField : &#39;country&#39;,
   valueField : &#39;country&#39;,
   queryMode : &#39;local&#39;,
   typeAhed : false
  }
 ]
});
&lt;/pre&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;
Let&#39;s create a controller for memory proxy and in controller init function, render our view into HTML body. 
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;Ext.define(&#39;MyApp.controller.MemoryController&#39;,{
 extend : &#39;Ext.app.Controller&#39;,
 models : [&#39;Country&#39;],
 stores : [&#39;CountryStore&#39;],
 views : [&#39;Country&#39;],
 init : function() {
  Ext.create(&quot;MyApp.view.Country&quot;,{
   renderTo : Ext.getBody()
  })
 }
});
&lt;/pre&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;
Finally, this is my app.js code.
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;Ext.Loader.setConfig({
 enabled : true
});

var countryData = {
 countryList : [
  {id : 1, country : &#39;India&#39;},
  {id : 2, country : &#39;Canada&#39;},
  {id : 3, country : &#39;Germany&#39;},
  {id : 4, country : &#39;US&#39;},
  {id : 5, country : &#39;UK&#39;}
 ]
};

Ext.application({
 name : &#39;MyApp&#39;,
 appFolder : &#39;app&#39;,
 //controllers : [&#39;SessionStorageController&#39;],
 //controllers : [&#39;LocalStorageController&#39;],
 controllers : [&#39;MemoryController&#39;],
 launch : function() {
  console.log(&#39;Application launch function...!&#39;);
 }
});
&lt;/pre&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;
The result of the above code is as shown in figure.
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyml3pkAkPNLQZRbY9aPpO1VXmfYde33324R7l5pYv1kTwc0eiKWAi5MresMhw5FbRTOtyu85RbPW96Yr0rUqAYuO803jmZ_qxhLpzHqY8Z1NTXKmpjGwbg4lmuzQMmJe7ZVn4gQy35Pgh/s1600/Memory+Proxy.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;285&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyml3pkAkPNLQZRbY9aPpO1VXmfYde33324R7l5pYv1kTwc0eiKWAi5MresMhw5FbRTOtyu85RbPW96Yr0rUqAYuO803jmZ_qxhLpzHqY8Z1NTXKmpjGwbg4lmuzQMmJe7ZVn4gQy35Pgh/s320/Memory+Proxy.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;a href=&quot;https://github.com/gnanasuriyan/ExtJS4-Clientproxy-Demo&quot; target=&quot;_blank&quot;&gt;&lt;b&gt;The application source code is uploaded into my github repository.&lt;/b&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Hope this help.....!&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.pointerunits.com/feeds/7234017566269164674/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1569789499442484210/7234017566269164674' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/7234017566269164674'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/7234017566269164674'/><link rel='alternate' type='text/html' href='http://www.pointerunits.com/2013/01/ext-js4-client-proxies.html' title='Ext JS 4 - Client Proxies'/><author><name>Gnanasuriyan</name><uri>http://www.blogger.com/profile/00525742121019222480</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjL7B6Ihy-xFMB19J-LEHU17qD7kpYY5iUfvlkSSOLR05wDJog8MuQDxNjJTrxAl3duQVgP9Fm4pwYHqA7aMlWMswcUyeTtax-3KogXfLJqN7Uk7sX7N2iEXVKNB54lplQ/s220/IMG_0826.JPG'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJDID2A503NypPnboP1r82mylI0ONI07309ZeUOfAbtZOqQ0-gT-UBf-EC42LcLJg_Phvz9CfvKrgmQ8BV4qQS05N9uLtq2bkdELZWxkceFossMpR7hDUq5jJZxlNp0ClC_TPY5g6ei5yn/s72-c/SessionStorage.jpg" height="72" width="72"/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1569789499442484210.post-7314591761301731299</id><published>2013-01-09T09:02:00.000-08:00</published><updated>2013-03-19T21:11:55.899-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Ext JS"/><title type='text'>Ext JS 4 – Creating web page using Ext.container.Viewport class and region propery</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
The &lt;b&gt;Ext.container.Viewport&lt;/b&gt; is used for creating general web page and &lt;b&gt;region&lt;/b&gt; property is used for splitting web page into different parts.&lt;br /&gt;
&lt;br /&gt;
Ext.container.Viewport is a specialized container represents the viewable area of the application (the browser area).&lt;br /&gt;
&lt;br /&gt;
It render itself to the document body, there is no need for providing &lt;b&gt;renderTo&lt;/b&gt; property and it automatically sizes itself to size of the browser viewport. The viewport also re-size the child elements based on view area(based on browser width and height).&lt;br /&gt;
&lt;br /&gt;
The default layout of the viewport is &lt;b&gt;border layout&lt;/b&gt; and we can customize this property according to our requirements.&lt;br /&gt;
&lt;br /&gt;
The viewport does not provide any scrolling. If necessary, the child elements(generally panels) within viewport needs to provide a scroll feature by using &lt;b&gt;autoScroll&lt;/b&gt; property.&lt;br /&gt;
&lt;br /&gt;
See the below example for better understanding. This is Home.js file placed into app/view folder.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;Ext.define(&#39;MyApp.view.Home&#39;, {
 extend : &#39;Ext.container.Viewport&#39;,
 layout : &#39;border&#39;,
 items : [{
  region : &#39;north&#39;,
  xtype : &#39;panel&#39;,
  html : &#39;&lt;h1 class=&quot;x-panel-header&quot;&gt;
North Region - Application Header&lt;/h1&gt;
&#39;,
  border : false,
  height : 50,
  margins : &#39;0 0 5 0&#39;
 }, {
  region : &#39;west&#39;,
  xtype : &#39;panel&#39;,
  collapsible : true,
  title : &#39;West Region&#39;,
  html : &#39;Navigation Links&#39;,
  width : 150
 }, {
  region : &#39;south&#39;,
  xtype : &#39;panel&#39;,
  title : &#39;South Region&#39;,
  collapsible : true,
  html : &#39;Footer contents&#39;,
  split : true,
  height : 100,
  minHeight : 100
 }, {
  region : &#39;east&#39;,
  xtype : &#39;panel&#39;,
  title : &#39;East Region&#39;,
  collapsible : true,
  split : true,
  width : 150
 }, {
  region : &#39;center&#39;,
  xtype : &#39;panel&#39;,
  title : &#39;Center Region&#39;,
  html : &#39;Application contents&#39;
 }]
});
&lt;/pre&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
I have followed MVC pattern, above code is my view and in application launch function I have created the object for Home.js. This is my app.js code for your understanding.&lt;/div&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;Ext.Loader.setConfig({
 enabled : true
});


Ext.application({
 name : &#39;MyApp&#39;,
 appFolder : &#39;app&#39;,
 launch : function() {
  Ext.create(&#39;MyApp.view.Home&#39;,{
   
  })
 }
});
&lt;/pre&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
The result of the above application is given below. &lt;a href=&quot;https://github.com/gnanasuriyan/ExtJS4-Viewport-Region-Demo&quot; target=&quot;_blank&quot;&gt;The application source code is uploaded into my github repository for your reference.&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnM1_2zZLsRWHRht0YExE4LoxL-vM1G3gPIBHELV8zCk7rvx-Cmz2p7sTY93bU754Yo5scT4p5OyKV5NOUSWnT0fgPyGv6IIkJo4zgTcXWiYEVmBHeVu4kQAv5isWVhcimjVEPzL2H8qp9/s1600/home.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;156&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnM1_2zZLsRWHRht0YExE4LoxL-vM1G3gPIBHELV8zCk7rvx-Cmz2p7sTY93bU754Yo5scT4p5OyKV5NOUSWnT0fgPyGv6IIkJo4zgTcXWiYEVmBHeVu4kQAv5isWVhcimjVEPzL2H8qp9/s320/home.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.pointerunits.com/feeds/7314591761301731299/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1569789499442484210/7314591761301731299' title='14 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/7314591761301731299'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/7314591761301731299'/><link rel='alternate' type='text/html' href='http://www.pointerunits.com/2013/01/ext-js4-creating-web-page-using.html' title='Ext JS 4 – Creating web page using Ext.container.Viewport class and region propery'/><author><name>Gnanasuriyan</name><uri>http://www.blogger.com/profile/00525742121019222480</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjL7B6Ihy-xFMB19J-LEHU17qD7kpYY5iUfvlkSSOLR05wDJog8MuQDxNjJTrxAl3duQVgP9Fm4pwYHqA7aMlWMswcUyeTtax-3KogXfLJqN7Uk7sX7N2iEXVKNB54lplQ/s220/IMG_0826.JPG'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnM1_2zZLsRWHRht0YExE4LoxL-vM1G3gPIBHELV8zCk7rvx-Cmz2p7sTY93bU754Yo5scT4p5OyKV5NOUSWnT0fgPyGv6IIkJo4zgTcXWiYEVmBHeVu4kQAv5isWVhcimjVEPzL2H8qp9/s72-c/home.jpg" height="72" width="72"/><thr:total>14</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1569789499442484210.post-3229499091784828659</id><published>2012-12-04T09:42:00.001-08:00</published><updated>2012-12-10T09:03:45.680-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Sencha Touch"/><title type='text'>Sencha Touch - Flow Of Application Launch Function</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;In Sencha Touch, we can include our application start up logic into following places, this is depending on our application situation.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;1. Application default launch function. This launch function is triggered when all the dependencies are loaded successfully.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;2. Controller init function.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;3. Controller launch function.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;4. Profile launch function.&lt;/div&gt;
&lt;br /&gt;
&amp;nbsp;Now I am going to include some code into all the places. Let&#39;s see what will happen.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;I have created simple controller called &quot;TestController&quot; as shown in figure and I simply printed different message in both init and launch function.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoFBOVbfPqTy4KYQEbolm1ISF9AywyVFB9mJvl9N9oEUm96R3OHLDBfDFIv0P-QxPGBfWT540WkxIwfMRvKOcK1k210GzvxdkbQ1kB4oK2yLr4T8fkwi8YdM2xV4KCSDmDdqak-SprzN50/s1600/TestController.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;173&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoFBOVbfPqTy4KYQEbolm1ISF9AywyVFB9mJvl9N9oEUm96R3OHLDBfDFIv0P-QxPGBfWT540WkxIwfMRvKOcK1k210GzvxdkbQ1kB4oK2yLr4T8fkwi8YdM2xV4KCSDmDdqak-SprzN50/s320/TestController.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&amp;nbsp;I have created the simple profile called &quot;TestProfile&quot; and I simply printed message in launch function. By default this profile is active.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfBpQJiiIQMdRBbNPt6ZZUO8icqUnRdNGqg9vnZ_08PMuDoh7hz-vlpSVotLQhX4V3QK3O3QZHpG-ps-SPtiHXJeZschnibllOaUo2TiS_xvYC8DQMDLvBz66Z9lLjV2ryrbND5SQ3axO6/s1600/TestProfile.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;154&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfBpQJiiIQMdRBbNPt6ZZUO8icqUnRdNGqg9vnZ_08PMuDoh7hz-vlpSVotLQhX4V3QK3O3QZHpG-ps-SPtiHXJeZschnibllOaUo2TiS_xvYC8DQMDLvBz66Z9lLjV2ryrbND5SQ3axO6/s320/TestProfile.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&amp;nbsp;Now I am going to include my controller and profile into app.js and I am going to simply print different message in application launch function. This is my app.js code.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXtUhp-gkidEn4-ybFnw7i3gRGq4NhHQG-VFQlfyt-xoE4U2YdQMoI6R4nEqmi5EswJUCw1zQogCoSo-nHZZqNVq9pTYlGSjnZNLhcpuDDCKEdkAGAY6fcw4eNp9uQmmkzmHfCcZMNwTgB/s1600/App.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;109&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXtUhp-gkidEn4-ybFnw7i3gRGq4NhHQG-VFQlfyt-xoE4U2YdQMoI6R4nEqmi5EswJUCw1zQogCoSo-nHZZqNVq9pTYlGSjnZNLhcpuDDCKEdkAGAY6fcw4eNp9uQmmkzmHfCcZMNwTgB/s320/App.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&amp;nbsp;Ok let&#39;s create an index.html file and run our application. This is my index.html code.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgh1xdEvu4OCCqgxCbNVqLU1QjyEFHa25VukbrOkXt4GHryefoup1JDWQGiTfBgYGeV1_lzSxJDbIZb5m5TqzzaKl7W2AjmlbE3DeGV6a4Z3gKvAWjxTia0N_Crtyx63TBj2Ef46Ixpb2ul/s1600/index.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;108&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgh1xdEvu4OCCqgxCbNVqLU1QjyEFHa25VukbrOkXt4GHryefoup1JDWQGiTfBgYGeV1_lzSxJDbIZb5m5TqzzaKl7W2AjmlbE3DeGV6a4Z3gKvAWjxTia0N_Crtyx63TBj2Ef46Ixpb2ul/s320/index.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&amp;nbsp;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&amp;nbsp;The final result of the application is very interesting. This is my application final result.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbgFU_TfMEYx6-hGjL_NJ_-hG3kMkZu4hRTjwevYQNmefuP_hRIRItDdl5mUbI9t0eJSPsBZx24k4NHuxulVp_ukkIOYLQfO5bU1wa_rXSzmlHxdpjZVUwwyvj7VOhfAOuuWVqNu7Kcymo/s1600/result.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;55&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbgFU_TfMEYx6-hGjL_NJ_-hG3kMkZu4hRTjwevYQNmefuP_hRIRItDdl5mUbI9t0eJSPsBZx24k4NHuxulVp_ukkIOYLQfO5bU1wa_rXSzmlHxdpjZVUwwyvj7VOhfAOuuWVqNu7Kcymo/s320/result.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&amp;nbsp;Ok.. This is the flow of application launch function.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; 1. Controller init is triggered first.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&amp;nbsp; &amp;nbsp; 2. Profile launch function is triggered next.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; 2. Application launch function is triggered next&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; 3. Finally controller launch function is triggered.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;a href=&quot;https://github.com/gnanasuriyan/Senchatouch-Application-Launch-Demo&quot; target=&quot;_blank&quot;&gt;&amp;nbsp;The application source code is uploaded into my GitHub repository.&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.pointerunits.com/feeds/3229499091784828659/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1569789499442484210/3229499091784828659' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/3229499091784828659'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/3229499091784828659'/><link rel='alternate' type='text/html' href='http://www.pointerunits.com/2012/12/sencha-touch-flow-of-application-launch.html' title='Sencha Touch - Flow Of Application Launch Function'/><author><name>Gnanasuriyan</name><uri>http://www.blogger.com/profile/00525742121019222480</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjL7B6Ihy-xFMB19J-LEHU17qD7kpYY5iUfvlkSSOLR05wDJog8MuQDxNjJTrxAl3duQVgP9Fm4pwYHqA7aMlWMswcUyeTtax-3KogXfLJqN7Uk7sX7N2iEXVKNB54lplQ/s220/IMG_0826.JPG'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoFBOVbfPqTy4KYQEbolm1ISF9AywyVFB9mJvl9N9oEUm96R3OHLDBfDFIv0P-QxPGBfWT540WkxIwfMRvKOcK1k210GzvxdkbQ1kB4oK2yLr4T8fkwi8YdM2xV4KCSDmDdqak-SprzN50/s72-c/TestController.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1569789499442484210.post-6140195971899447038</id><published>2012-11-12T21:15:00.002-08:00</published><updated>2012-12-10T08:26:48.672-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Hibernate"/><category scheme="http://www.blogger.com/atom/ns#" term="Spring"/><title type='text'>Simple Login Application Using Spring MVC and Hibernate – Part 2</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;I hope you have visited my &lt;a href=&quot;http://www.pointerunits.com/2012/11/simple-login-application-using-spring.html&quot; target=&quot;_blank&quot;&gt;part1 of my tutorial&lt;/a&gt;. Let’s see the steps for integrating hibernate framework into Spring MVC. Here I have used MySQL database. I have created one database called “&lt;b&gt;springmvc&lt;/b&gt;” and created one table called “&lt;b&gt;user&lt;/b&gt;” with userid, username, password fields.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDWNZA2kmaqhdAB3Dl6dB7SUTmwuu6GpfF4hbkjoA_PHGQSuPcU4CbKHLngKzL4fpxdXn3V5Tna4Y6SbdhqQ4o_DRLWeRF0d03NIbmMWVVovK4yvQkQU1N89kDzJkznGFoyk3GpzNFt5Ke/s1600/database1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;161&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDWNZA2kmaqhdAB3Dl6dB7SUTmwuu6GpfF4hbkjoA_PHGQSuPcU4CbKHLngKzL4fpxdXn3V5Tna4Y6SbdhqQ4o_DRLWeRF0d03NIbmMWVVovK4yvQkQU1N89kDzJkznGFoyk3GpzNFt5Ke/s320/database1.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;
&amp;nbsp;I have inserted some&amp;nbsp;records into table like this.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpN0hFUtpLAu3wPsOegTNd8iaI1steBBSby6ITjnG5RoxqG6P-6Ktgzx3pTkA5T5l5Jyv_ZbTPSbUOhtavsyVs3JinyGAs8eqeROxSpSMDLOjm6zH4_bkLbhXspD2vcH7iJPCVU66SQ97E/s1600/database2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;161&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpN0hFUtpLAu3wPsOegTNd8iaI1steBBSby6ITjnG5RoxqG6P-6Ktgzx3pTkA5T5l5Jyv_ZbTPSbUOhtavsyVs3JinyGAs8eqeROxSpSMDLOjm6zH4_bkLbhXspD2vcH7iJPCVU66SQ97E/s320/database2.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;h4 style=&quot;text-align: justify;&quot;&gt;
Step 1: Creating User POJO class.&lt;/h4&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;We need to create a User POJO class for mapping user table. Ok let’s create it.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxe6xe3WsrA3VaQ61ik5mPSUDodCSv1cS8akpf5vMM-eiazybK_8rhO9NmqfemEJOWryEWAexd5JF2qS8AWrJkuIqYOuz38L9HlY0LaHT1dehaDOSz_ONAhTGpFChCSmzoEhsujpXGnpNe/s1600/userpojo.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxe6xe3WsrA3VaQ61ik5mPSUDodCSv1cS8akpf5vMM-eiazybK_8rhO9NmqfemEJOWryEWAexd5JF2qS8AWrJkuIqYOuz38L9HlY0LaHT1dehaDOSz_ONAhTGpFChCSmzoEhsujpXGnpNe/s320/userpojo.png&quot; width=&quot;261&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;h4 style=&quot;text-align: justify;&quot;&gt;
Step 2: Creating hibernate mapping xml file for user class.&lt;/h4&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;In hibernate we need to create hibernate mapping xml file for all domain class for mapping into corresponding database table. Instead of creating xml file you can use annotation for mapping domain class into database table. This is my mapping xml document created for mapping our user domain class into user database table.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhP_N5oUFigPt6ePXEID4RTrt-EtvuGFUJitMuHbrFxxNCKLVz-SQTdWCEJGRlWCxTSXidX8xcm2I-kMovioXv_PkxeItvEUmlAc_ZbKIXp7mNRr6jjI3Iy7F9_RIr1XBM2sF0LN4ISyqrk/s1600/hibernatemapping.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;159&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhP_N5oUFigPt6ePXEID4RTrt-EtvuGFUJitMuHbrFxxNCKLVz-SQTdWCEJGRlWCxTSXidX8xcm2I-kMovioXv_PkxeItvEUmlAc_ZbKIXp7mNRr6jjI3Iy7F9_RIr1XBM2sF0LN4ISyqrk/s320/hibernatemapping.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;h4 style=&quot;text-align: justify;&quot;&gt;
Step 3: Creating authenticate service class.&lt;/h4&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJzsXea4H03wvL0JDmH9bQu9r7n_sOZK0KO12Acn8YpokMG3MtHO4pJiG5H4S2n_4OJq5ni09xjQ3d4hgDHg2WD_bvjwv9-rYdWJdjy7yLqCNiB2hVN5zHYv1Z9OYPs3XcngyPvsA6GXd4/s1600/authenticateservice.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;170&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJzsXea4H03wvL0JDmH9bQu9r7n_sOZK0KO12Acn8YpokMG3MtHO4pJiG5H4S2n_4OJq5ni09xjQ3d4hgDHg2WD_bvjwv9-rYdWJdjy7yLqCNiB2hVN5zHYv1Z9OYPs3XcngyPvsA6GXd4/s320/authenticateservice.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;The method “verifyUserNameAndPassword” present in “AuthenticateService” class is used for&amp;nbsp; verifying the user name and password details against database table. It simply returns the boolean value.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp; Very important one is, I am injecting object for “HibernateTemplate” via setter method. So It’s time for defining data source bean, hibernate properties bean, session factory bean , hibernate template bean and our service beans into applicationContext.xml file.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;h4 style=&quot;text-align: justify;&quot;&gt;
Step 4: Modifying applicationContext.xml.&lt;/h4&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhuKkl1qwvsrOZRDqlq9lzE9thFH7H9oxBXyzDj1tm57wrk1hKF_FqXRVeM1xj191vL0ZoURaTviofnBFGGmIQGBrnt-t0YxiifhKbPPgcEs-LSn_SpSreesaErr5w995xqqnAEL_WNUta/s1600/applicationcontext.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;166&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhuKkl1qwvsrOZRDqlq9lzE9thFH7H9oxBXyzDj1tm57wrk1hKF_FqXRVeM1xj191vL0ZoURaTviofnBFGGmIQGBrnt-t0YxiifhKbPPgcEs-LSn_SpSreesaErr5w995xqqnAEL_WNUta/s320/applicationcontext.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;Here I have configured the beans that are related to hibernate as well as for our service class. Now we need to inject our service class into our controller and we need to call the “&lt;b&gt;verifyUserNameAndPassword&lt;/b&gt;” method for verifying user credentials. So let’s see the steps for injecting our authenticate service class into login controller.&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;h4 style=&quot;text-align: justify;&quot;&gt;
Step 5: Modifying Login Controller.&lt;/h4&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh371Z_i7wXcod4LdeKta9wU9vPnfTg8TLWtAKH2LSyTq3fws-Razyn7m8BlPqFeMg5RDSIgQL5KuoUuzdYH2s4DSYFGzwgTC5iqA7Z2AH_wWx99VHWmikma-2j46jX6q-RmBMZON6a-Io0/s1600/logincontroller.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;103&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh371Z_i7wXcod4LdeKta9wU9vPnfTg8TLWtAKH2LSyTq3fws-Razyn7m8BlPqFeMg5RDSIgQL5KuoUuzdYH2s4DSYFGzwgTC5iqA7Z2AH_wWx99VHWmikma-2j46jX6q-RmBMZON6a-Io0/s320/logincontroller.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;Here @Autowird annotation is used for injecting our service class into our controller.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;That’s all. We have completed our development. Let’s do testing. I have deployed this application into apache server. The result of the application is,&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEji3PwSZJ2bmTbjx8ZFgGjjjOHwE9uPLpEz6SBZUuppIJjdlML_Zu_IuwyrblkPp6MmyxQr5K0qLDnqLJQbpxGg1kQOnOR2jSkV27Vc4qOUgilq7pItczjX8MHc9P_k5i_WTZjIEnvQ440a/s1600/result1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;112&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEji3PwSZJ2bmTbjx8ZFgGjjjOHwE9uPLpEz6SBZUuppIJjdlML_Zu_IuwyrblkPp6MmyxQr5K0qLDnqLJQbpxGg1kQOnOR2jSkV27Vc4qOUgilq7pItczjX8MHc9P_k5i_WTZjIEnvQ440a/s320/result1.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKXGlBhbtE8FfL3Yyj2KhZTq-PCwms6WHRgRCJnoBhQn8hW-zjwNiwwMUxDQ96Ai5kqR47NFy1e0FK3Rr-GaKXS5kK7VvQxMCMNKlc0RorB1vWq_lC-nVL7z1hEUm31nja3ZRZW3HVOUxG/s1600/result2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;130&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKXGlBhbtE8FfL3Yyj2KhZTq-PCwms6WHRgRCJnoBhQn8hW-zjwNiwwMUxDQ96Ai5kqR47NFy1e0FK3Rr-GaKXS5kK7VvQxMCMNKlc0RorB1vWq_lC-nVL7z1hEUm31nja3ZRZW3HVOUxG/s320/result2.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpLoXeD_LFUokQlFi_Tv9Z5Ak5RqXT8xKGYzYPHm1HsXfPrCDWtDc8lom0rggetW7OG1xMCdSJLFE_Y74wQG8TviLlauhIa_otSkhaOZDwmoAbuwwThyphenhyphenQPHxZyPxqh0UYZuyUE-Z0WE-e1/s1600/result3.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;139&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpLoXeD_LFUokQlFi_Tv9Z5Ak5RqXT8xKGYzYPHm1HsXfPrCDWtDc8lom0rggetW7OG1xMCdSJLFE_Y74wQG8TviLlauhIa_otSkhaOZDwmoAbuwwThyphenhyphenQPHxZyPxqh0UYZuyUE-Z0WE-e1/s320/result3.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQ2kDcSCJun6ial7qG8BgdRdKQxUN4MgpfvjItYvWK63Ks1poJsCwUyITnsXUzG26cih5_aJHZOkXeZtQ3BjmY67E_HcKYWq0wgpUWQjj2cMX7kc9wfIUROwVEIvGC4cl3bLHrPyQ35PYf/s1600/result4.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;137&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQ2kDcSCJun6ial7qG8BgdRdKQxUN4MgpfvjItYvWK63Ks1poJsCwUyITnsXUzG26cih5_aJHZOkXeZtQ3BjmY67E_HcKYWq0wgpUWQjj2cMX7kc9wfIUROwVEIvGC4cl3bLHrPyQ35PYf/s320/result4.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;&lt;a href=&quot;https://github.com/gnanasuriyan/Spring-Hibernate-MVC-Part2&quot; target=&quot;_blank&quot;&gt;The part2 of the application is hosted into my github repository.&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.pointerunits.com/feeds/6140195971899447038/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1569789499442484210/6140195971899447038' title='44 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/6140195971899447038'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/6140195971899447038'/><link rel='alternate' type='text/html' href='http://www.pointerunits.com/2012/11/simple-login-application-using-spring_12.html' title='Simple Login Application Using Spring MVC and Hibernate – Part 2'/><author><name>Gnanasuriyan</name><uri>http://www.blogger.com/profile/00525742121019222480</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjL7B6Ihy-xFMB19J-LEHU17qD7kpYY5iUfvlkSSOLR05wDJog8MuQDxNjJTrxAl3duQVgP9Fm4pwYHqA7aMlWMswcUyeTtax-3KogXfLJqN7Uk7sX7N2iEXVKNB54lplQ/s220/IMG_0826.JPG'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDWNZA2kmaqhdAB3Dl6dB7SUTmwuu6GpfF4hbkjoA_PHGQSuPcU4CbKHLngKzL4fpxdXn3V5Tna4Y6SbdhqQ4o_DRLWeRF0d03NIbmMWVVovK4yvQkQU1N89kDzJkznGFoyk3GpzNFt5Ke/s72-c/database1.png" height="72" width="72"/><thr:total>44</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1569789499442484210.post-8785325402734079132</id><published>2012-11-12T00:06:00.003-08:00</published><updated>2013-05-03T11:36:36.219-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Hibernate"/><category scheme="http://www.blogger.com/atom/ns#" term="Spring"/><title type='text'>Simple Login Application Using Spring MVC and Hibernate – Part 1</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;I hope developers working in web application development might hear about MVC architecture. Almost all technologies provide support for MVC based web application development, but the success is based on many factors like reusable of the code, maintenance of the code, future adaption of the code, etc..,&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;The success of the Spring MVC is “&lt;b&gt;Open for extension and closed for modification&lt;/b&gt;” principle. Using Spring MVC the developers can easily develop MVC based web application. We don’t need any steep learning curve at the same time we need to know the basics of spring framework and MVC architecture. The Spring MVC consists of following important components.&lt;/div&gt;
&lt;div style=&quot;margin-left: 10%; margin-top: 10px; text-align: justify;&quot;&gt;
1. Dispatcher servlet&lt;br /&gt;
2. Controller&lt;br /&gt;
3. View Resolver&lt;br /&gt;
4. Model
&lt;/div&gt;
&lt;h4 style=&quot;margin-top: 10px; text-align: justify;&quot;&gt;
Spring MVC - Overview
&lt;/h4&gt;
&lt;div style=&quot;margin-top: 10px; text-align: justify;&quot;&gt;
&amp;nbsp;The overall architecture of Spring MVC is shown here.
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhimPQV3hHD2FFUfQ557B7KXuED666wy1RuLyxy817bE1z-ZLKnkThwBk7vKjV25Dcdh5I35srQQegWjS7UMH9J7qEaGKKztwAUgufMvTHMhBPRGvLsHnHF2Ayee0sNIuuCamENxTgQd8R/s1600/Spring-MVC.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;185&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhimPQV3hHD2FFUfQ557B7KXuED666wy1RuLyxy817bE1z-ZLKnkThwBk7vKjV25Dcdh5I35srQQegWjS7UMH9J7qEaGKKztwAUgufMvTHMhBPRGvLsHnHF2Ayee0sNIuuCamENxTgQd8R/s320/Spring-MVC.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;margin-top: 10px; text-align: justify;&quot;&gt;
&amp;nbsp;1. When “Dispatcher Servlet” gets any request from client, it finds the corresponding mapped controller for the request and just dispatches the request to the corresponding controller. The requests and corresponding controller information are loaded into the context when application starts based on xml configuration or Meta data. We have many way for loading this information, we will discuss at this one at later point of time.
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;2. We know, the controllers are used for connecting business and service layer. The controller get inputs from request, process the inputs, finally it returns the view and model information.
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;3. The view resolver gets those information, find the corresponding view, it updates the view with model data and finally it send the response back to the “Dispatcher Servlet”.
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;4. Finally the “Dispatcher Servlet” sends this response back to the client. 
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;Ok, let’s start developing our application. I have created the dynamic web project using STS and included all necessary jar files into class path of the application. 
&lt;/div&gt;
&lt;h4 style=&quot;margin-top: 10px; text-align: justify;&quot;&gt;
Step 1: Defining Dispatcher Servlet into web.xml file.
&lt;/h4&gt;
&lt;div style=&quot;margin-top: 10px; text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVkdyHG79fpCWz8RqKmJxG7z4xHUscJYwWLreQ6tTjhJ5vj-Fl8ACRYYOK5lGKSqUeTJXXIf7fS60Xish7Zf21UTD53lEgaO-TU-uIuh5y-pcAIeA7341HcGQZw3koThJ5U3KIL88HCrQO/s1600/Dispatcher-Servlet.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;179&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVkdyHG79fpCWz8RqKmJxG7z4xHUscJYwWLreQ6tTjhJ5vj-Fl8ACRYYOK5lGKSqUeTJXXIf7fS60Xish7Zf21UTD53lEgaO-TU-uIuh5y-pcAIeA7341HcGQZw3koThJ5U3KIL88HCrQO/s320/Dispatcher-Servlet.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;margin-top: 10px; text-align: justify;&quot;&gt;
&amp;nbsp;Here “&lt;b&gt;DispatcherServlet&lt;/b&gt;” class is configured with name as “&lt;b&gt;dispatcher&lt;/b&gt;” and the url pattern as “&lt;b&gt;*.spring&lt;/b&gt;”. 
&lt;/div&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
Step 2: Creating login.html page.&lt;/h4&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhosqtW2rJvUgA6crw64huyP9JaitLYNzoiOlYhiuP4tYJGmRnfcrHbIfAS3SC22OPOIX2X-U806smuIgC83bVvJ0ubKFc3pOvxI48w87qx_6hzRzQJ5Nz2oUC9voAPKR_WQbVcetrPkMG1/s1600/Login-page.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;160&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhosqtW2rJvUgA6crw64huyP9JaitLYNzoiOlYhiuP4tYJGmRnfcrHbIfAS3SC22OPOIX2X-U806smuIgC83bVvJ0ubKFc3pOvxI48w87qx_6hzRzQJ5Nz2oUC9voAPKR_WQbVcetrPkMG1/s320/Login-page.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;Here I have created the html form with action as “&lt;b&gt;Login.spring&lt;/b&gt;”. If user submits the page, the request is send to Login controller. Let’s create a login controller for handling the request. 
&lt;/div&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
Step 3: Creating Login Controller.&lt;/h4&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiH9ILTdDGFEI6XxuguRX8tY7WncDKAwU0JfBg4DS-NkbGjaaSfvcGY8T0yjTRQSl4nxfBPvBgm2U9Cp88gZqjb5RHf6dFj6EzSL5zjs_iffAfnc_I5LMlVlqK3WtCMUbPZTgO6C1JnC-ie/s1600/LoginController.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;121&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiH9ILTdDGFEI6XxuguRX8tY7WncDKAwU0JfBg4DS-NkbGjaaSfvcGY8T0yjTRQSl4nxfBPvBgm2U9Cp88gZqjb5RHf6dFj6EzSL5zjs_iffAfnc_I5LMlVlqK3WtCMUbPZTgO6C1JnC-ie/s320/LoginController.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;&lt;b&gt;@Controller&lt;/b&gt; annotation is very important because when context loads, the spring will find all controller class using this annotation and it&#39;s maps to the corresponding view (URL). &lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&lt;b&gt;@RequestMapping&lt;/b&gt; annotation is used for specifying action of the request.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;So now the dispatcher servlet gets any request from “&lt;b&gt;Login.spring&lt;/b&gt;” that automatically redirects the request to “&lt;b&gt;LoginController&lt;/b&gt;”. &lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&lt;b&gt;@RequestParam&lt;/b&gt; annotation is used for getting value from request parameters. It’s equivalent to request.getParameter() method in servlet. &lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; In my login controller, the &lt;b&gt;processCredentials&lt;/b&gt; method just gets the username, password details from parameters and check whether both are equal. If it’s equal, it just returns the object of “&lt;b&gt;ModelAndView&lt;/b&gt;” class with next redirecting page as a parameter. &lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;Hey In my login form, I have given action as “&lt;b&gt;Login.spring&lt;/b&gt;” only. &lt;b&gt;How that action automatically trigger my processCredentials method?&lt;/b&gt; 
&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrp38nmasSPdwaInBboQ6WC4caDl4kacE91Yk1MthJ8jF9R6C41EACub94U4FGO6_eo5AK8vcRtum47HS9_5LBNAZ_iO65y7LkQs6L_OpdvUyANtsNBewhEGezJiXWvSe7zPvsMPdDDoO5/s1600/LoginController2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;105&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrp38nmasSPdwaInBboQ6WC4caDl4kacE91Yk1MthJ8jF9R6C41EACub94U4FGO6_eo5AK8vcRtum47HS9_5LBNAZ_iO65y7LkQs6L_OpdvUyANtsNBewhEGezJiXWvSe7zPvsMPdDDoO5/s320/LoginController2.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;Red indicated “&lt;b&gt;results&lt;/b&gt;” is indicates redirecting page, this is resolved by “&lt;b&gt;View resolver&lt;/b&gt;”, and another one is request attribute key and  value pair. Now we need to configure our view resolver.
&lt;/div&gt;
&lt;h4 style=&quot;text-align: left;&quot;&gt;
Step 4: Configuring view resolver.&lt;/h4&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;For configuring view resolver, we need to create one more xml file into inside the WEB-INF folder. The name of the xml file is very important, it’s is based on our dispatcher servlet name configured in web.xml file. The name should be “&lt;b&gt;dispatcher servlet name-servlet.xml&lt;/b&gt;”. In our case, the “dispatcher” is our servlet name, so the name of the file is “&lt;b&gt;dispatcher-servlet.xml&lt;/b&gt;”. 
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxo-dFbI9s92icGFqgp7PCLuKV9Cs3hB0o3gEfxi4af_Bc7oK6KK0yi0X6HV6x4QX-B03SRb8vHU_H8kUC0XGbP_xCniKcxnMA5Fc9pOKLlR-_O7Xv6gn2P3nv9y8p6B5TFUY1J3hsiG2_/s1600/ConfigDisSer.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;86&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxo-dFbI9s92icGFqgp7PCLuKV9Cs3hB0o3gEfxi4af_Bc7oK6KK0yi0X6HV6x4QX-B03SRb8vHU_H8kUC0XGbP_xCniKcxnMA5Fc9pOKLlR-_O7Xv6gn2P3nv9y8p6B5TFUY1J3hsiG2_/s320/ConfigDisSer.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;Spring have lot of view resolver classes, for example ResourceBundleViewResolver, InternalResourceViewResolver, XsltViewResaolver, etc.., but by default spring use InternalResourceViewResolver class. &lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;In this XML file I have configured InternalResoureViewResolver class properties. Here I have given prefix value as “/” and suffix value as “.jsp”. In this situation, the view resolver get the view name from ModelAndView object (“results”) and append the prefix and suffix value (/results.jsp). So in our login controller we have verified user name, password values and redirected our request to results.jsp page. So we need to create results.jsp page.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;Before going to create results.jsp, I have to explain about the &lt;b&gt;purpose of context:component-scan&lt;/b&gt; tag. This tag automatically scans all the controller class presents in&lt;b&gt; base-package&lt;/b&gt; and registered into context. In other words, it’s just looks what are all the classes have @Controller annotation and map the controller into corresponding view. This information is maintained in context of the application. &lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;Ok let’s create a results.jsp page.
&lt;/div&gt;
&lt;br /&gt;
&lt;h4 style=&quot;text-align: justify;&quot;&gt;
Step 5: Creating result.jsp file.&lt;/h4&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;This is my result.jsp page; here I have just get the message value from request attributes and displayed the message.
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgC8RS98VSz52AHdD2WliJZdE2Kqz4WZ0269x2jsqqSvbz6zs4R7eFqhw8uBCkNlOaOMX6c5k8c0mAsuzbUVNxua_Jb_urFe470KFFAqoqZoGJUVY-1sKcbImWgwu9tYblz4Ik3aDdcdWeF/s1600/resultjsp.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;79&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgC8RS98VSz52AHdD2WliJZdE2Kqz4WZ0269x2jsqqSvbz6zs4R7eFqhw8uBCkNlOaOMX6c5k8c0mAsuzbUVNxua_Jb_urFe470KFFAqoqZoGJUVY-1sKcbImWgwu9tYblz4Ik3aDdcdWeF/s320/resultjsp.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h4 style=&quot;margin-top: 10px; text-align: justify;&quot;&gt;
Step 5: Creating applicationContext.xml file.&lt;/h4&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;Spring MVC application needs applicationContext.xml file. Using this file we can configure our web related beans. As of now we don’t use any beans, so this file don’t have any bean definition.
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrUJ8PItNfFG4Oba_QSxDgqhbGUw04bqiSrwmDyY1s8wkInwDQ2yMFkUSYA43lm8e5gl19dVuXUf1Fa3WHRprLyRxD7-qy66MpMNES2VJj6J4DzBe0ocPY1uLNGzC-PpwSZ40njA8VX2TJ/s1600/applicationContext.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;43&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrUJ8PItNfFG4Oba_QSxDgqhbGUw04bqiSrwmDyY1s8wkInwDQ2yMFkUSYA43lm8e5gl19dVuXUf1Fa3WHRprLyRxD7-qy66MpMNES2VJj6J4DzBe0ocPY1uLNGzC-PpwSZ40njA8VX2TJ/s320/applicationContext.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;Ok. Let’s deploy our application into web server and will check the result.
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3coauGN85PLPJgQKHtnMNX7xXZ7uVCAOQm5pIMqm-WzEiFJSesywOlQa7e-9L2tDGVhM-r9id4jMk2wCnLtoAPx7pbdlySwuYszNj_jTwfu1ntHNT4bTVDWmhsdtCN4dgxH_TAMzRhSVO/s1600/result1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;100&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3coauGN85PLPJgQKHtnMNX7xXZ7uVCAOQm5pIMqm-WzEiFJSesywOlQa7e-9L2tDGVhM-r9id4jMk2wCnLtoAPx7pbdlySwuYszNj_jTwfu1ntHNT4bTVDWmhsdtCN4dgxH_TAMzRhSVO/s320/result1.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrUJ8PItNfFG4Oba_QSxDgqhbGUw04bqiSrwmDyY1s8wkInwDQ2yMFkUSYA43lm8e5gl19dVuXUf1Fa3WHRprLyRxD7-qy66MpMNES2VJj6J4DzBe0ocPY1uLNGzC-PpwSZ40njA8VX2TJ/s1600/applicationContext.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;43&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhrUJ8PItNfFG4Oba_QSxDgqhbGUw04bqiSrwmDyY1s8wkInwDQ2yMFkUSYA43lm8e5gl19dVuXUf1Fa3WHRprLyRxD7-qy66MpMNES2VJj6J4DzBe0ocPY1uLNGzC-PpwSZ40njA8VX2TJ/s320/applicationContext.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiiIsLUcBOm5GnVixSmD17E1cvzndTVV4GdZpiGpaHW8IJq1tpvFhhy7lf6-m2Q02Q8t4ku7A4vYg-Wo5ujkbX1xzkt8Pb9Kn00sew3V0SIikCEFrPrQbAQd8GuiZCGXr1fN9TGjRrKf08p/s1600/result2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;89&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiiIsLUcBOm5GnVixSmD17E1cvzndTVV4GdZpiGpaHW8IJq1tpvFhhy7lf6-m2Q02Q8t4ku7A4vYg-Wo5ujkbX1xzkt8Pb9Kn00sew3V0SIikCEFrPrQbAQd8GuiZCGXr1fN9TGjRrKf08p/s320/result2.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;As of now, we didn’t integrate hibernate. In my next part, I will explain the stpes for integrating Hibernate ORM framework into our application. &lt;strong&gt;&lt;a href=&quot;https://github.com/gnanasuriyan/Spring-Hibernate-MVC-Part1&quot; target=&quot;_blank&quot;&gt;The part1&amp;nbsp;application source code is uploaded into my  GitHub repository for your  reference&lt;/a&gt;&lt;/strong&gt;.
&lt;br /&gt;
&lt;br /&gt;
For integrating into hibernate, refer the below link.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.pointerunits.com/2012/11/simple-login-application-using-spring_12.html&quot;&gt;http://www.pointerunits.com/2012/11/simple-login-application-using-spring_12.html&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.pointerunits.com/feeds/8785325402734079132/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1569789499442484210/8785325402734079132' title='53 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/8785325402734079132'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/8785325402734079132'/><link rel='alternate' type='text/html' href='http://www.pointerunits.com/2012/11/simple-login-application-using-spring.html' title='Simple Login Application Using Spring MVC and Hibernate – Part 1'/><author><name>Gnanasuriyan</name><uri>http://www.blogger.com/profile/00525742121019222480</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjL7B6Ihy-xFMB19J-LEHU17qD7kpYY5iUfvlkSSOLR05wDJog8MuQDxNjJTrxAl3duQVgP9Fm4pwYHqA7aMlWMswcUyeTtax-3KogXfLJqN7Uk7sX7N2iEXVKNB54lplQ/s220/IMG_0826.JPG'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhimPQV3hHD2FFUfQ557B7KXuED666wy1RuLyxy817bE1z-ZLKnkThwBk7vKjV25Dcdh5I35srQQegWjS7UMH9J7qEaGKKztwAUgufMvTHMhBPRGvLsHnHF2Ayee0sNIuuCamENxTgQd8R/s72-c/Spring-MVC.png" height="72" width="72"/><thr:total>53</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1569789499442484210.post-1022802015313895678</id><published>2012-10-11T11:53:00.002-07:00</published><updated>2012-10-11T11:55:01.259-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="JSF"/><title type='text'>JSF2 - h:dataTable Demo using HashMap</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;The data table component in JSF2 is used for displaying database table, array list, hash map, etc.., into tabular format. In JSP, if you want to display a table record in tabular format, we need to create a html table template after that we need to iterate the result set object. Here that is not necessary, because the h:dataTable automatically create a table template based on your inputs as well it have lot of useful attributes for specifying style class for HTML tags like table, th, tr and td.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;This is very simple use case of h:dataTable. Here I am using HashMap, Inside the hash map I have all country name as key and corresponding capital name as value. Now I am going to display that hash map into tabular format using h:dataTable component.&amp;nbsp;&lt;/div&gt;
&lt;pre class=&quot;brush:xhtml&quot;&gt;&lt;h:datatable id=&quot;countryCapitalList&quot; value=&quot;#{countryCapitalList.getCountryKeyAsList()}&quot; var=&quot;country&quot;&gt;
			&lt;f:facet name=&quot;header&quot;&gt;
				&lt;h:outputtext value=&quot;Country and Capital Details&quot;&gt;&lt;/h:outputtext&gt;
			&lt;/f:facet&gt;
			&lt;h:column&gt;
				&lt;f:facet name=&quot;header&quot;&gt;
					&lt;h:outputtext value=&quot;Country&quot;&gt;&lt;/h:outputtext&gt;
				&lt;/f:facet&gt;
				&lt;h:outputtext value=&quot;#{country}&quot;&gt;&lt;/h:outputtext&gt;
			&lt;/h:column&gt;
			&lt;h:column&gt;
				&lt;f:facet name=&quot;header&quot;&gt;
					&lt;h:outputtext value=&quot;Capital&quot;&gt;&lt;/h:outputtext&gt;
				&lt;/f:facet&gt;
				&lt;h:outputtext value=&quot;#{countryCapitalList.countryAndCapital[country]}&quot;&gt;&lt;/h:outputtext&gt;
			&lt;/h:column&gt;
			&lt;f:facet name=&quot;footer&quot;&gt;
				&lt;h:outputtext value=&quot;This is footer of the table...!&quot;&gt;&lt;/h:outputtext&gt;
			&lt;/f:facet&gt;
		&lt;/h:datatable&gt;
&lt;/pre&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;The rowClasses, columnClasses, header and footer classes are very useful attributes used for define your own css classes into table attributes. Download my entire application from &lt;a href=&quot;https://github.com/gnanasuriyan/JSF2-DataTableDemoUsingHashMap&quot; target=&quot;_blank&quot;&gt;github &lt;/a&gt;and see my managed bean, xhtml and css code. The result of application is like this.&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRh0Q4Oj1b-NkFwMC6x1ydZVu-aQwPLbnC7Vs00dzK2SKhOfQ9XnxFokL8tNrXyUmzM8tSTzhNQxXo8qPOtUbwGNIUK6VvK0dei6sOSQr8-aVjHgjImE35X7WqUwT0la-HpuIs85sVH_nq/s1600/sam.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;192&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRh0Q4Oj1b-NkFwMC6x1ydZVu-aQwPLbnC7Vs00dzK2SKhOfQ9XnxFokL8tNrXyUmzM8tSTzhNQxXo8qPOtUbwGNIUK6VvK0dei6sOSQr8-aVjHgjImE35X7WqUwT0la-HpuIs85sVH_nq/s320/sam.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.pointerunits.com/feeds/1022802015313895678/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1569789499442484210/1022802015313895678' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/1022802015313895678'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/1022802015313895678'/><link rel='alternate' type='text/html' href='http://www.pointerunits.com/2012/10/jsf2-hdatatable-demo-using-hashmap.html' title='JSF2 - h:dataTable Demo using HashMap'/><author><name>Gnanasuriyan</name><uri>http://www.blogger.com/profile/00525742121019222480</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjL7B6Ihy-xFMB19J-LEHU17qD7kpYY5iUfvlkSSOLR05wDJog8MuQDxNjJTrxAl3duQVgP9Fm4pwYHqA7aMlWMswcUyeTtax-3KogXfLJqN7Uk7sX7N2iEXVKNB54lplQ/s220/IMG_0826.JPG'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRh0Q4Oj1b-NkFwMC6x1ydZVu-aQwPLbnC7Vs00dzK2SKhOfQ9XnxFokL8tNrXyUmzM8tSTzhNQxXo8qPOtUbwGNIUK6VvK0dei6sOSQr8-aVjHgjImE35X7WqUwT0la-HpuIs85sVH_nq/s72-c/sam.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1569789499442484210.post-2142397083980706462</id><published>2012-10-10T23:45:00.004-07:00</published><updated>2012-10-11T00:16:49.692-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="JSF"/><title type='text'>JSF2 - Number Converter Demo</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;The number converter in JSF2 is used to convert a component data into java.lang.Number format. Additionally it have lot of attributes for customizing number format. The sample usage is given here.&lt;/div&gt;
&lt;pre class=&quot;brush:xhtml&quot;&gt;	&lt;h:inputtext id=&quot;inputNumber&quot; required=&quot;true&quot; requiredmessage=&quot;Please enter a number&quot; value=&quot;#{numberBean.number}&quot;&gt;
			&lt;f:convertnumber for=&quot;inputNumber&quot; maxfractiondigits=&quot;4&quot; minfractiondigits=&quot;2&quot;&gt;&lt;/f:convertnumber&gt;
		&lt;/h:inputtext&gt;
		

		&lt;h:commandbutton action=&quot;success&quot; value=&quot;Submit&quot;&gt;&lt;/h:commandbutton&gt;
	&lt;/pre&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;The important one is, the numberConverter binding component managed bean property should be a primitive type or has a type of java.lang.Number only. Here the &quot;number&quot; type is java.lang.Number. This is another usage of number converter.&lt;/div&gt;
&lt;pre class=&quot;brush:xhtml&quot;&gt;&lt;h:form&gt;
		&lt;h:outputtext id=&quot;inputNumber&quot; value=&quot;#{numberBean.number}&quot;&gt;
			&lt;f:convertnumber currencysymbol=&quot;$&quot; type=&quot;currency&quot;&gt;&lt;/f:convertnumber&gt;
		&lt;/h:outputtext&gt;
	&lt;/h:form&gt;
&lt;/pre&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;THe result of the above code is something like $22.50. The sample application is available in &lt;a href=&quot;https://github.com/gnanasuriyan/JSF2-NumberConverterDemo&quot; target=&quot;_blank&quot;&gt;Github&lt;/a&gt;.
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.pointerunits.com/feeds/2142397083980706462/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1569789499442484210/2142397083980706462' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/2142397083980706462'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/2142397083980706462'/><link rel='alternate' type='text/html' href='http://www.pointerunits.com/2012/10/jsf2-number-converter-demo.html' title='JSF2 - Number Converter Demo'/><author><name>Gnanasuriyan</name><uri>http://www.blogger.com/profile/00525742121019222480</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjL7B6Ihy-xFMB19J-LEHU17qD7kpYY5iUfvlkSSOLR05wDJog8MuQDxNjJTrxAl3duQVgP9Fm4pwYHqA7aMlWMswcUyeTtax-3KogXfLJqN7Uk7sX7N2iEXVKNB54lplQ/s220/IMG_0826.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1569789499442484210.post-5985365261281194660</id><published>2012-10-09T10:30:00.000-07:00</published><updated>2012-10-26T11:34:33.255-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="JSF"/><title type='text'>JSF2 - Date Time Converter Demo</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;The date time converter in JSF2 is used to convert a text value into java.util.Date value. The date time converter has&amp;nbsp;several attributes, that is used to specify the format and type of data. The most used formats are locale, timeStyle, for, timeZone etc..,&amp;nbsp;The example usage is given here.&lt;/div&gt;
&lt;pre class=&quot;brush:html&quot;&gt;&lt;h:form&gt;
  &lt;h6&gt;
Please enter a date in dd/mm/yyyy format&lt;/h6&gt;
&lt;h:inputtext id=&quot;dateTimeField&quot; required=&quot;true&quot; requiredmessage=&quot;Please enter a date !!!&quot; value=&quot;#{dateTimeBean.todayDate}&quot;&gt;
   &lt;f:convertdatetime pattern=&quot;dd/MM/yyyy&quot; type=&quot;date&quot;&gt;
  &lt;/f:convertdatetime&gt;
&lt;/h:inputtext&gt;
  &lt;h:message for=&quot;dateTimeField&quot; style=&quot;color: red; font-weight: bold;&quot;&gt;&lt;/h:message&gt;
  &lt;h:commandbutton action=&quot;success&quot; value=&quot;Submit&quot;&gt;
 &lt;/h:commandbutton&gt;
&lt;/h:form&gt;
&lt;/pre&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;The sample application is available in &lt;a href=&quot;https://github.com/gnanasuriyan/JSFDateTimeConverterDemo&quot; target=&quot;_blank&quot;&gt;Github&lt;/a&gt;.&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.pointerunits.com/feeds/5985365261281194660/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1569789499442484210/5985365261281194660' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/5985365261281194660'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/5985365261281194660'/><link rel='alternate' type='text/html' href='http://www.pointerunits.com/2012/10/jsf2-date-time-converter-demo.html' title='JSF2 - Date Time Converter Demo'/><author><name>Gnanasuriyan</name><uri>http://www.blogger.com/profile/00525742121019222480</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjL7B6Ihy-xFMB19J-LEHU17qD7kpYY5iUfvlkSSOLR05wDJog8MuQDxNjJTrxAl3duQVgP9Fm4pwYHqA7aMlWMswcUyeTtax-3KogXfLJqN7Uk7sX7N2iEXVKNB54lplQ/s220/IMG_0826.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1569789499442484210.post-2126908681475797749</id><published>2012-10-01T10:37:00.001-07:00</published><updated>2012-10-01T11:15:37.469-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="JSF"/><title type='text'>JSF2-Integer Converter Demo</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;The Integer converter in JSF2 is used to convert a text value into integer value. This is my managed bean, here I have declared one Integer variable and I have created&amp;nbsp;accessor&amp;nbsp;method for that variable.&lt;/div&gt;
&lt;pre class=&quot;brush:java&quot;&gt;package com.pointerunits;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean
@SessionScoped

public class Converter {
 private Integer intNumber;
 public Converter() {
  
 }
 public Integer getIntNumber() {
  return intNumber;
 }
 public void setIntNumber(Integer intNumber) {
  this.intNumber = intNumber;
 } 
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;This is my xhtml page, Here I have created one input text filed and converted that field value into integer using integer converter. If converter can&#39;t able to convert then it&#39;t will display the error message.&lt;/div&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:html&quot;&gt;&lt;h:form&gt;&lt;h:inputtext id=&quot;intNumber&quot; name=&quot;Number Field&quot; required=&quot;true&quot; requiredmessage=&quot;Value Required!!!&quot; value=&quot;#{converter.intNumber}&quot;&gt;   &lt;f:converter converterid=&quot;Integer&quot;&gt;
  &lt;/f:converter&gt;&lt;/h:inputtext&gt;
  

  &lt;h:message for=&quot;intNumber&quot; style=&quot;color: red;&quot;&gt;
  

  &lt;h:commandbutton action=&quot;IntConverterSucess&quot; value=&quot;Submit&quot;&gt;
 &lt;/h:commandbutton&gt;&lt;/h:message&gt;&lt;/h:form&gt;
&lt;/pre&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;You can download an entire application from &lt;a href=&quot;https://github.com/gnanasuriyan/JSF2-IntegerConverterDemo&quot; target=&quot;_blank&quot;&gt;github&lt;/a&gt;.&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.pointerunits.com/feeds/2126908681475797749/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1569789499442484210/2126908681475797749' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/2126908681475797749'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/2126908681475797749'/><link rel='alternate' type='text/html' href='http://www.pointerunits.com/2012/10/jsf2-integer-converter-demo.html' title='JSF2-Integer Converter Demo'/><author><name>Gnanasuriyan</name><uri>http://www.blogger.com/profile/00525742121019222480</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjL7B6Ihy-xFMB19J-LEHU17qD7kpYY5iUfvlkSSOLR05wDJog8MuQDxNjJTrxAl3duQVgP9Fm4pwYHqA7aMlWMswcUyeTtax-3KogXfLJqN7Uk7sX7N2iEXVKNB54lplQ/s220/IMG_0826.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1569789499442484210.post-3612619375983745922</id><published>2012-09-29T09:47:00.004-07:00</published><updated>2012-10-03T19:52:42.953-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="JSF"/><title type='text'>Converters in JSF 2</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;Converters in JSF2 are used to easily convert a value from one data type to other. The following inbuilt converters are available in JSF2.&lt;/div&gt;
&lt;br /&gt;
&lt;table cellpading=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;border: 1px solid #40332C; width: 100%;&quot;&gt;
 &lt;tbody&gt;
&lt;tr&gt;
   &lt;th style=&quot;border-bottom: 1px solid #40332C;&quot;&gt;Converter Name&lt;/th&gt;
   &lt;th style=&quot;border-bottom: 1px solid #40332C;&quot;&gt;Converter Class&lt;/th&gt;
 &lt;/tr&gt;
&lt;tr&gt;
   &lt;td&gt;Byte Converter&lt;/td&gt;
   &lt;td&gt;javax.faces.convert.ByteConverter&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr&gt;
   &lt;td&gt;Short Converter&lt;/td&gt;
   &lt;td&gt;javax.faces.convert.ShortConverter&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr&gt;
   &lt;td&gt;Character Converter&lt;/td&gt;
   &lt;td&gt;javax.faces.convert.CharacterConverter&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr&gt;
   &lt;td&gt;Boolean Converter&lt;/td&gt;
   &lt;td&gt;javax.faces.convert.BooleanConverter&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr&gt;
   &lt;td&gt;Integer Converter&lt;/td&gt;
   &lt;td&gt;javax.faces.convert.IntegerConverter&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr&gt;
   &lt;td&gt;Float Converter&lt;/td&gt;
   &lt;td&gt;javax.faces.convert.FloatConverter&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr&gt;
   &lt;td&gt;Double Converter&lt;/td&gt;
   &lt;td&gt;javax.faces.convert.DoubleConverter&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr&gt;
   &lt;td&gt;Long Converter&lt;/td&gt;
   &lt;td&gt;javax.faces.convert.LongConverter&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr&gt;
   &lt;td&gt;Big Integer Converter&lt;/td&gt;
   &lt;td&gt;javax.faces.convert.BigIntegerConverter&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr&gt;
   &lt;td&gt;Big Decimal Converter&lt;/td&gt;
   &lt;td&gt;javax.faces.convert.BigDecimalConverter&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr&gt;
   &lt;td&gt;Date Time Converter&lt;/td&gt;
   &lt;td&gt;javax.faces.convert.DateTimeConverter&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr&gt;
   &lt;td&gt;Number Converter&lt;/td&gt;
   &lt;td&gt;javax.faces.convert.NumberConverter&lt;/td&gt;
 &lt;/tr&gt;
&lt;tr&gt;
   &lt;td&gt;Enum Converter&lt;/td&gt;
   &lt;td&gt;javax.faces.convert.EnumConverter&lt;/td&gt;
 &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;The JSF2 also allow developers to create a custom converter for their own purpose. The following rules are very important because almost all the developers are makes lot of mistake here.&lt;br /&gt;
&amp;nbsp;1. Before going to use any converter, we need to register that converter into faces-config.xml file (If you are going to create custom converter, this is important). Se the below example, Here I have registered Integer converter into facex-config.xml file.&lt;/div&gt;
&lt;pre class=&quot;brush:xml&quot;&gt;&lt;converter&gt;
  &lt;converter -id=&quot;-id&quot;&gt;Integer&lt;/converter&gt;
  &lt;converter -class=&quot;-class&quot;&gt;javax.faces.convert.IntegerConverter&lt;/converter&gt;
&lt;/converter&gt;
&lt;/pre&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;2. By default all converter have error message. If converter can&#39;t able to convert the value, then it will display error message. So we need to register error message component for corresponding converter component.&lt;br /&gt;
&amp;nbsp;3. We need to bind a value of the component to managed bean property as the same type as the converter.&lt;br /&gt;
&amp;nbsp;4. We have two ways for registering converter component. The first one is using converter attribute directly on the component tag and another one is, we can nest a converter tag within the component tag and use converter tag&#39;s converterId attribute or binding attribute to reference the converter. Examples are here.&lt;br /&gt;
&lt;pre class=&quot;brush:html&quot;&gt;&lt;h:inputtext converter=&quot;javax.faces.convert.IntegerConverter&quot;&gt;
&lt;/h:inputtext&gt;&lt;/pre&gt;
&lt;pre class=&quot;brush:html&quot;&gt;&lt;h:inputtext&gt;
 &lt;f:converter converterid=&quot;Integer&quot;&gt;
&lt;/f:converter&gt;&lt;/h:inputtext&gt;&lt;/pre&gt;
&lt;/div&gt;
&amp;nbsp;In my upcoming post, I am going to give a small example for above converters.
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.pointerunits.com/feeds/3612619375983745922/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1569789499442484210/3612619375983745922' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/3612619375983745922'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/3612619375983745922'/><link rel='alternate' type='text/html' href='http://www.pointerunits.com/2012/09/converters-in-jsf-2.html' title='Converters in JSF 2'/><author><name>Gnanasuriyan</name><uri>http://www.blogger.com/profile/00525742121019222480</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjL7B6Ihy-xFMB19J-LEHU17qD7kpYY5iUfvlkSSOLR05wDJog8MuQDxNjJTrxAl3duQVgP9Fm4pwYHqA7aMlWMswcUyeTtax-3KogXfLJqN7Uk7sX7N2iEXVKNB54lplQ/s220/IMG_0826.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1569789499442484210.post-7932347295917437460</id><published>2012-08-31T12:42:00.001-07:00</published><updated>2012-09-08T00:24:59.822-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="JSF"/><title type='text'>Guessing Game Implementation using JSF</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;In a typical Java Server Faces application each page connect to a managed bean, that have properties and methods that are associated with the components. This Guessing Game application consists of one managed bean and two views. All views are using same bean.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;The following are requirements for this application.
&lt;/div&gt;
&lt;div style=&quot;margin-left: 20px; text-align: justify;&quot;&gt;
1. User must enter a number from 0 to 10.
&lt;br /&gt;
2. Maximum number of attempt is 5.
&lt;br /&gt;
3. If user guess a correct number with in 5 attempts, the success message is displayed to the user otherwise the failure message is displayed.
&lt;/div&gt;
&lt;div&gt;
&amp;nbsp;Ok let&#39;s create a managed bean for implementing above requirements.
&lt;/div&gt;
&lt;pre class=&quot;brush:java&quot;&gt;package com.pointerunits;

import java.io.IOException;
import java.util.Random;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

@ManagedBean
@SessionScoped

public class GuessingGame {
 private int randomNumber;
 private int userNumber;
 private int minimum;
 private int maximum;
 private int allowableAttempts;
 private int userAttempts;
 private String message;
 public GuessingGame() {
  this.minimum = 0;
  this.maximum =10;
  this.allowableAttempts = 5; 
  this.initializeGame();
 }
 private void initializeGame() {
  Random randomGR = new Random();
  this.randomNumber = new Integer(randomGR.nextInt(this.maximum));
  System.out.println(&quot;Random number : &quot; + this.randomNumber);
  this.userAttempts = 0;
  this.userNumber = 0;
  this.message = &quot;&quot;;
 }
 public int getRandomNumber() {
  return randomNumber;
 }
 public void setRandomNumber(int randomNumber) {
  this.randomNumber = randomNumber;
 }
 public int getUserNumber() {
  return userNumber;
 }
 public void setUserNumber(int userNumber) {
  this.userNumber = userNumber;
 }
 public int getMinimum() {
  return minimum;
 }
 public void setMinimum(int minimum) {
  this.minimum = minimum;
 }
 public int getMaximum() {
  return maximum;
 }
 public void setMaximum(int maximum) {
  this.maximum = maximum;
 }
 public int getAllowableAttempts() {
  return allowableAttempts;
 }
 public void setAllowableAttempts(int allowableAttempts) {
  this.allowableAttempts = allowableAttempts;
 }
 public int getUserAttempts() {
  return userAttempts;
 }
 public void setUserAttempts(int userAttempts) {
  this.userAttempts = userAttempts;
 }
 public String getMessage() {
  return message;
 }
 public void setMessage(String message) {
  this.message = message;
 }
 public void playGame() throws IOException {
  this.userAttempts++;
  boolean isRedirect = false;
  if(this.userNumber == this.randomNumber) {
   this.message = &quot;Hey..you got it. Total attempt is &quot; + this.userAttempts ;
   isRedirect = true;
  }
  else if(this.userNumber &amp;gt; this.randomNumber){
   this.message = &quot;Hey I am lesser than your guess&quot;;
  }
  else if(this.userNumber &amp;lt; this.randomNumber) {
   this.message = &quot;Hey I am greater than your guess&quot;;
  }
  if(this.userAttempts == this.allowableAttempts) {
   this.message = &quot;Hey..you have failed to guess.&quot;;
   isRedirect = true;
  }
  if(isRedirect) {
   FacesContext.getCurrentInstance().getExternalContext().redirect(&quot;guessingGameResponse.xhtml&quot;);
  }
 }
 
 public void resetGame() throws IOException {
  initializeGame();
  FacesContext.getCurrentInstance().getExternalContext().redirect(&quot;guessingGame.xhtml&quot;);
 }
}
&lt;/pre&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;Here the redirect() method is used for redirecting to result page. Instead of you can use JSF navigation rule for redirection. The following facelet page is used for getting user input.
&lt;/div&gt;
&lt;pre class=&quot;brush:html&quot;&gt;&lt;h:head&gt;
 &lt;title&gt;Guessing Game&lt;/title&gt;
&lt;/h:head&gt;
&lt;h:body&gt;
 &lt;h:form&gt;
  &lt;h3&gt;
Hi, I am thinking of a number from #{guessingGame.minimum} to #{guessingGame.maximum}. Can you guess it?&lt;/h3&gt;
&lt;h:inputtext id=&quot;userNumber&quot; value=&quot;#{guessingGame.userNumber}&quot;&gt;
   &lt;f:validatelongrange maximum=&quot;#{guessingGame.maximum}&quot; minimum=&quot;#{guessingGame.minimum}&quot;&gt;&lt;/f:validatelongrange&gt;
   &lt;/h:inputtext&gt;
   &lt;h:message for=&quot;userNumber&quot;&gt;&lt;/h:message&gt;
   

   &lt;h:outputtext style=&quot;color: red; font-sise: 12px; font-weight: bold;&quot; value=&quot;#{guessingGame.message}&quot;&gt;&lt;/h:outputtext&gt;
   

   &lt;h:commandbutton action=&quot;#{guessingGame.playGame}&quot; value=&quot;Submit&quot;&gt;&lt;/h:commandbutton&gt;
 &lt;/h:form&gt;
&lt;/h:body&gt;


&lt;/pre&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;The following facelet page is used for displaying result.
&lt;/div&gt;
&lt;pre class=&quot;brush:html&quot;&gt;&lt;h:head&gt;
 &lt;title&gt;Guessing Game&lt;/title&gt;
&lt;/h:head&gt;
&lt;h:body&gt;
 &lt;h:form&gt;
  &lt;h:outputtext style=&quot;color: red; font-sise: 12px; font-weight: bold;&quot; value=&quot;#{guessingGame.message}&quot;&gt;&lt;/h:outputtext&gt;
  

  &lt;h3&gt;
Do you want to play a game once again?&lt;/h3&gt;
&lt;h:commandbutton action=&quot;#{guessingGame.resetGame}&quot; value=&quot;Reset&quot;&gt;&lt;/h:commandbutton&gt;
 &lt;/h:form&gt;
&lt;/h:body&gt;


&lt;/pre&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;You can download an entire application from &lt;a href=&quot;https://github.com/gnanasuriyan/Guessing-Game-Using-JSF&quot; target=&quot;_blank&quot;&gt;GitHub&lt;/a&gt;.
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://www.pointerunits.com/feeds/7932347295917437460/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1569789499442484210/7932347295917437460' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/7932347295917437460'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/7932347295917437460'/><link rel='alternate' type='text/html' href='http://www.pointerunits.com/2012/08/guessing-game-implementation-using-jsf.html' title='Guessing Game Implementation using JSF'/><author><name>Gnanasuriyan</name><uri>http://www.blogger.com/profile/00525742121019222480</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjL7B6Ihy-xFMB19J-LEHU17qD7kpYY5iUfvlkSSOLR05wDJog8MuQDxNjJTrxAl3duQVgP9Fm4pwYHqA7aMlWMswcUyeTtax-3KogXfLJqN7Uk7sX7N2iEXVKNB54lplQ/s220/IMG_0826.JPG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1569789499442484210.post-4002910682209441876</id><published>2012-07-24T00:02:00.000-07:00</published><updated>2012-07-24T00:03:05.047-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="PhoneGap"/><title type='text'>Getting current geo location details of the mobile device using PhoneGap (Cordova)</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;The PhoneGap library provide lot of useful functionalities for accessing native mobile features like Camera, Geo location, Voice recorder etc., In this tutorial I am going to collect current Geo location details of the mobile device using Geolocation methods available in PhoneGap (Cordova).&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;PhoneGap (Cordova) provides two different methods for getting geo location details. Those are,&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1. geolocation.getCurrentPosition - Returns the current position as Position object.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2. geolocation.watchPosition - It continuously watch changes of device &#39;s current position.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;
&amp;nbsp;The example for above methods are shown here.&lt;/div&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;navigator.geolocation.getCurrentPosition(geoLocationSuccess,geoLocationError,{timeout:30000});
(or)
navigator.geolocation.watchPosition(geoLocationSuccess,geoLocationError,{timeout : 30000});

function geoLocationSuccess(position) {
 var str = &#39;Latitude: &#39;          + position.coords.latitude          + &#39;\n&#39; +
           &#39;Longitude: &#39;         + position.coords.longitude         + &#39;\n&#39; +
           &#39;Altitude: &#39;          + position.coords.altitude          + &#39;\n&#39; +
           &#39;Accuracy: &#39;          + position.coords.accuracy          + &#39;\n&#39; +
           &#39;Altitude Accuracy: &#39; + position.coords.altitudeAccuracy  + &#39;\n&#39; +
           &#39;Heading: &#39;           + position.coords.heading           + &#39;\n&#39; +
           &#39;Speed: &#39;             + position.coords.speed             + &#39;\n&#39; +
           &#39;Timestamp: &#39;         + position.timestamp                + &#39;\n&#39; ;
 alert(str);

}

function geoLocationError(error) {
 alert(&#39;code: &#39;    + error.code    + &#39;\n&#39; + &#39;message: &#39; + error.message + &#39;\n&#39;);
}
&lt;/pre&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;Here the first parameter indicates your success callback function, second parameter indicates your failure callback and final parameter indicates various options that are provided by PhoneGap (Cordova), those are,
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;&amp;nbsp;1. maximumAge - Accept a cached position whose age is no longer than given timeout (in milliseconds)
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;2. timeout
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;3. enableHighAccuracy - Either true or false.
&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;There is one more method available for stopping watch position function. The example is show here.
&lt;/div&gt;
&lt;pre class=&quot;brush:javascript&quot;&gt;var watchId = navigator.geolocation.watchPosition(geoLocationSuccess,geoLocationError,{ timeout: 30000 });
navigator.geolocation.clearWatch(watchId);
&lt;/pre&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;You can find more example from PhoneGap (Cordova) &lt;a href=&quot;http://docs.phonegap.com/en/2.0.0/cordova_geolocation_geolocation.md.html#Geolocation&quot; target=&quot;_blank&quot;&gt;documentation&lt;/a&gt;. &lt;br /&gt;
Hope this help..!
&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.pointerunits.com/feeds/4002910682209441876/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1569789499442484210/4002910682209441876' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/4002910682209441876'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/4002910682209441876'/><link rel='alternate' type='text/html' href='http://www.pointerunits.com/2012/07/getting-current-geo-location-details-of.html' title='Getting current geo location details of the mobile device using PhoneGap (Cordova)'/><author><name>Gnanasuriyan</name><uri>http://www.blogger.com/profile/00525742121019222480</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjL7B6Ihy-xFMB19J-LEHU17qD7kpYY5iUfvlkSSOLR05wDJog8MuQDxNjJTrxAl3duQVgP9Fm4pwYHqA7aMlWMswcUyeTtax-3KogXfLJqN7Uk7sX7N2iEXVKNB54lplQ/s220/IMG_0826.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1569789499442484210.post-7806948583052929823</id><published>2012-07-14T11:16:00.001-07:00</published><updated>2012-07-24T21:40:11.998-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="PhoneGap"/><title type='text'>&quot;_NSURLIsExcludedFromBackupKey&quot;, referenced from: [CDVFile setMetadata:withDict:] in Cordova,  ld: symbol(s) not found for architecture i386</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;Hi, Last week I have updated my PhoneGap (Cordova) version from 1.3 to 1.9, for both IPhone as well as Android. In XCode I have installed the newer version of Cordova and I have created new project using Cordovo 1.9. When I was running my application I got the following error and also the compilation was failed. The error is,&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: arial; font-size: small; text-align: -webkit-auto;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #660000;&quot;&gt;Undefined symbols for architecture i386:&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: arial; font-size: small; text-align: -webkit-auto;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #660000;&quot;&gt;&amp;nbsp;&quot;_&lt;wbr&gt;&lt;/wbr&gt;NSURLIsExcludedFromBackupKey&quot;, referenced from:&amp;nbsp;[CDVFile setMetadata:withDict:] in Cordova,&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: arial; font-size: small; text-align: -webkit-auto;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #660000;&quot;&gt;ld: symbol(s) not found for architecture i386&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: arial; font-size: small; text-align: -webkit-auto;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: -webkit-auto;&quot;&gt;
&lt;div style=&quot;font-family: arial; font-size: small;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;For fixing this issue, I have updated my AppDelegate.h file with following code.&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div style=&quot;font-family: arial; font-size: small;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: white; font-family: arial; font-size: x-small;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: arial; font-size: x-small;&quot;&gt;#import &amp;lt;UIKit/UIKit.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: arial; font-size: x-small;&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: arial; font-size: x-small;&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;#ifdef CORDOVA_FRAMEWORK&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: arial; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp; #import &amp;lt;Cordova/CDVViewController.h&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: arial; font-size: x-small;&quot;&gt;#else&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: arial; font-size: x-small;&quot;&gt;&amp;nbsp; &amp;nbsp;#import &quot;CDVViewController.h&quot;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: arial; font-size: x-small;&quot;&gt;#endif&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: arial; font-size: x-small;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: arial; font-size: x-small;&quot;&gt;NSString * const NSURLIsExcludedFromBackupKey = @&quot;NSURLIsExcludedFromBackupKey&quot;;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: arial; font-size: x-small;&quot;&gt;@interface AppDelegate : NSObject &amp;lt; UIApplicationDelegate &amp;gt; {&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; font-family: arial; font-size: x-small;&quot;&gt;}&lt;/span&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;span style=&quot;background-color: white; font-family: arial; font-size: x-small;&quot;&gt;&lt;b&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.pointerunits.com/feeds/7806948583052929823/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/1569789499442484210/7806948583052929823' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/7806948583052929823'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1569789499442484210/posts/default/7806948583052929823'/><link rel='alternate' type='text/html' href='http://www.pointerunits.com/2012/07/nsurlisexcludedfrombackupkey-referenced.html' title='&quot;_NSURLIsExcludedFromBackupKey&quot;, referenced from: [CDVFile setMetadata:withDict:] in Cordova,  ld: symbol(s) not found for architecture i386'/><author><name>Gnanasuriyan</name><uri>http://www.blogger.com/profile/00525742121019222480</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjL7B6Ihy-xFMB19J-LEHU17qD7kpYY5iUfvlkSSOLR05wDJog8MuQDxNjJTrxAl3duQVgP9Fm4pwYHqA7aMlWMswcUyeTtax-3KogXfLJqN7Uk7sX7N2iEXVKNB54lplQ/s220/IMG_0826.JPG'/></author><thr:total>0</thr:total></entry></feed>