<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom="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" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-5223788876950011016</atom:id><lastBuildDate>Thu, 12 Sep 2024 01:36:58 +0000</lastBuildDate><category>Java</category><category>Sun CA</category><category>Web-Apps</category><category>SCJP</category><category>JavaScript</category><category>DU</category><category>Flex 3</category><category>HTML5</category><category>JBoss</category><category>Sankalan</category><category>Tomcat</category><category>Authentication</category><category>CSS3</category><category>Delhi</category><category>Generics</category><category>Google</category><category>JBossWS</category><category>Multithreading</category><category>NetBeans</category><category>OOPS</category><category>Open Source</category><category>RPC</category><category>Singleton</category><category>Threads</category><category>Web Services</category><category>jQuery</category><category>AJAX</category><category>Aadhar</category><category>Ant</category><category>Atomicity</category><category>C++</category><category>CMS</category><category>Chrome</category><category>Collections</category><category>Cygwin</category><category>Decompiler</category><category>Double-checked Locking</category><category>DragNDrop</category><category>Drupal</category><category>Exception Handling</category><category>Firefox</category><category>GWT</category><category>Garbage Collection</category><category>Hibernate</category><category>Immutable</category><category>Inner Classes</category><category>Interview Ques</category><category>JavaMail</category><category>Joomla</category><category>Media Queries</category><category>Mobile</category><category>Node.js</category><category>Overriding</category><category>Passport</category><category>Personal</category><category>RSL</category><category>SQL</category><category>SSL</category><category>STM</category><category>Servlets</category><category>Shadow DOM</category><category>Sorting</category><category>Static Imports</category><category>Strings</category><category>Tutorial</category><category>Web Components</category><category>Web Workers</category><category>XML</category><category>equals()</category><category>hashcode()</category><category>new year</category><category>pass-by-value</category><category>uCertify</category><title>Kreativity Personified</title><description>The creative side of me unleashed here....love to write about technology that excites and inspires me...</description><link>http://techno-cratic.blogspot.com/</link><managingEditor>noreply@blogger.com (Anonymous)</managingEditor><generator>Blogger</generator><openSearch:totalResults>63</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5223788876950011016.post-6322750940550492639</guid><pubDate>Fri, 07 Aug 2015 19:27:00 +0000</pubDate><atom:updated>2015-08-07T12:27:49.427-07:00</atom:updated><title>Moving to a New Home</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
This blog is moving to new Home. Yay !!&lt;br /&gt;
&lt;br /&gt;
Finally bidding goodbye to Blogger &amp;amp; moving to a more managed &lt;a href=&quot;http://agrajmangal.in/blog/&quot; target=&quot;_blank&quot;&gt;Wordpress blog&lt;/a&gt; after a good long 7 years &amp;amp; many learnings, though not all transformed into blog entries !!&lt;br /&gt;
&lt;br /&gt;
Revisiting old memories, my journey as a Blogger started with being a part of Sun Campus Ambassador program and I definitely plan to continue and keep blogging about all the new technologies that I get a chance to work with.&lt;br /&gt;
&lt;br /&gt;
So please follow me on the &lt;a href=&quot;http://agrajmangal.in/blog/&quot; target=&quot;_blank&quot;&gt;new blog&lt;/a&gt;. Also check out the &lt;a href=&quot;http://www.agrajmangal.in/&quot; target=&quot;_blank&quot;&gt;home page&lt;/a&gt; I designed &amp;amp; created for myself. Looks cool, right ? ;)&lt;br /&gt;
&lt;br /&gt;
See you there,&lt;br /&gt;
Agraj&lt;/div&gt;
</description><link>http://techno-cratic.blogspot.com/2015/08/moving-to-new-home.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5223788876950011016.post-6482033834497840176</guid><pubDate>Tue, 12 Aug 2014 07:37:00 +0000</pubDate><atom:updated>2014-08-12T00:37:17.982-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Authentication</category><category domain="http://www.blogger.com/atom/ns#">JavaScript</category><category domain="http://www.blogger.com/atom/ns#">Node.js</category><category domain="http://www.blogger.com/atom/ns#">Passport</category><title>Authenticating Node.js Applications with Passport</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Check out my recent post on authenticating Node.js applications with &lt;a href=&quot;http://passportjs.org/&quot; target=&quot;_blank&quot;&gt;Passport&lt;/a&gt;&amp;nbsp;on Tuts+ &lt;a href=&quot;http://code.tutsplus.com/tutorials/authenticating-nodejs-applications-with-passport--cms-21619&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;. It assumes a basic understanding of Node.js and Mongo but we start by building an Express application from scratch and add new routes, views &amp;amp; authenticate them via Passport.&amp;nbsp;&lt;/div&gt;
</description><link>http://techno-cratic.blogspot.com/2014/08/authenticating-nodejs-applications-with.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5223788876950011016.post-6442228884455900567</guid><pubDate>Sun, 16 Mar 2014 09:15:00 +0000</pubDate><atom:updated>2014-03-16T02:15:13.493-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">HTML5</category><category domain="http://www.blogger.com/atom/ns#">JavaScript</category><category domain="http://www.blogger.com/atom/ns#">Shadow DOM</category><category domain="http://www.blogger.com/atom/ns#">Web Components</category><title>Web Components 101 : Shadow DOM</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Unless you&#39;ve been living under a rock, you must have heard about the latest buzzword in the world of JavaScript - Encapsulation. Encapsulation or Information-hiding is one of the main pillars of object-oriented programming languages which is used to restrict access to some of the object&#39;s components. But how does that apply to a language like JavaScript - To find out check out this &lt;a href=&quot;http://code.tutsplus.com/tutorials/intro-to-shadow-dom--net-34966&quot; target=&quot;_blank&quot;&gt;article&lt;/a&gt; I recently authored about Shadow DOM, the underlying technology behind Web components.&lt;/div&gt;
</description><link>http://techno-cratic.blogspot.com/2014/03/web-components-101-shadow-dom.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5223788876950011016.post-1756223800564546819</guid><pubDate>Mon, 28 Oct 2013 06:26:00 +0000</pubDate><atom:updated>2013-10-27T23:26:44.598-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Atomicity</category><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">Multithreading</category><title>Synchronization in Java</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;b&gt;Threads&lt;/b&gt; are an integral part of the Java language and have evolved largely introducing new ways to synchronize/lock your data but the basics of &lt;b&gt;Atomicity&lt;/b&gt; &amp;amp; &lt;b&gt;Visibility&lt;/b&gt; remains same, which are essential to understand and write robust multi-threaded applications. I recently authored a &lt;a href=&quot;http://tech.pro/tutorial/1341/synchronization-in-java&quot; target=&quot;_blank&quot;&gt;post&lt;/a&gt; explaining the basics of Synchronization and introducing the various new ways to lock your data. Let me know in the comments if there is anything in that &lt;a href=&quot;http://tech.pro/tutorial/1341/synchronization-in-java&quot; target=&quot;_blank&quot;&gt;post&lt;/a&gt; that does not make sense.&lt;/div&gt;
</description><link>http://techno-cratic.blogspot.com/2013/10/synchronization-in-java.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5223788876950011016.post-4785864393226460175</guid><pubDate>Wed, 28 Aug 2013 09:14:00 +0000</pubDate><atom:updated>2013-08-28T02:14:56.597-07:00</atom:updated><title>OAuth2.0 for Dummies</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Check out &lt;a href=&quot;http://net.tutsplus.com/tutorials/oauth-2-0-the-good-the-bad-the-ugly/&quot; target=&quot;_blank&quot;&gt;my post&lt;/a&gt; on OAuth2.0 - the famous access delegation mechanism employed by many big names such as Google, Facebook, Salesforce etc. that eliminates the needs of sharing passwords between applications to exchange data. The &lt;a href=&quot;http://net.tutsplus.com/tutorials/oauth-2-0-the-good-the-bad-the-ugly/&quot; target=&quot;_blank&quot;&gt;post&lt;/a&gt; uses &lt;a href=&quot;https://developers.google.com/oauthplayground/&quot; target=&quot;_blank&quot;&gt;Google&#39;s OAuth Playground&lt;/a&gt; to detail out the communication (authentication and authorization) that occurs between the client and the server when the client is trying to authenticate on behalf of resource owner. It also draws a basic comparison with the earlier version of OAuth - 1.0 and presents a perspective on how things turned ugly when the lead author of the spec resigned !!&lt;/div&gt;
</description><link>http://techno-cratic.blogspot.com/2013/08/oauth20-for-dummies.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5223788876950011016.post-3791828870857721501</guid><pubDate>Tue, 19 Mar 2013 09:38:00 +0000</pubDate><atom:updated>2013-03-19T02:38:30.479-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">JavaScript</category><category domain="http://www.blogger.com/atom/ns#">Multithreading</category><category domain="http://www.blogger.com/atom/ns#">Web Workers</category><title>HTML5 : Web Workers </title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
There isn&#39;t much need to emphasize that HTML5 brings with itself, a new set of Javascript&amp;nbsp;armor&amp;nbsp;for the front-end developer. One of the interesting additions that has the potential to change how complex operations in Javascript are performed, is &lt;a href=&quot;http://www.w3.org/TR/workers/&quot; target=&quot;_blank&quot;&gt;Web Workers&lt;/a&gt;. It provides multi-threaded capabilities in a language which was inherently single-threaded otherwise. Check out my detailed writeup on Getting Started with Web Workers &lt;a href=&quot;http://net.tutsplus.com/tutorials/javascript-ajax/getting-started-with-web-workers/&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&amp;nbsp;&lt;/div&gt;
</description><link>http://techno-cratic.blogspot.com/2013/03/html5-web-workers.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5223788876950011016.post-2893244388688147770</guid><pubDate>Sun, 06 May 2012 18:05:00 +0000</pubDate><atom:updated>2012-05-06T11:12:56.022-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">CSS3</category><category domain="http://www.blogger.com/atom/ns#">HTML5</category><category domain="http://www.blogger.com/atom/ns#">JavaScript</category><title>Getting Started with HTML5</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Do you want your existing website to be HTML5 – compliant ? &lt;br /&gt;All you want to know if you are working on a new project that should follow HTML5 best practices ?&lt;br /&gt;
This post tries to answer some of these questions and attempts to try and get started with HTML5 in a flash, using two of the most popular bootstrap frameworks which help you to get started with a robust codebase. Why use it ? Simple, these frameworks contains &lt;em&gt;best practices&lt;/em&gt; around front-end development using &lt;em&gt;HTML/JSS/CSS&lt;/em&gt; and kick starts you to concentrate on content, rather than developing a template for your site. &lt;br /&gt;
&lt;a href=&quot;http://html5boilerplate.com/&quot;&gt;&lt;strong&gt;HTML5 Boilerplate&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt; – H5BP&lt;/strong&gt; , already at 3.0 &lt;br /&gt;
Includes  &lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Cross-browser compatible using Polyfills/Fallbacks.  &lt;/li&gt;
&lt;li&gt;HTML5 &lt;em&gt;Feature Detection&lt;/em&gt; using &lt;a href=&quot;http://modernizr.com/&quot;&gt;Modernizr&lt;/a&gt;, &lt;a href=&quot;http://yepnopejs.com/&quot;&gt;YepNode&lt;/a&gt;  &lt;/li&gt;
&lt;li&gt;CSS3 &lt;em&gt;Media Queries&lt;/em&gt;  &lt;/li&gt;
&lt;li&gt;Mobile browser optimizations  &lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://html5boilerplate.com/#builder&quot;&gt;Download&lt;/a&gt; complete, stripped &amp;amp; customized versions  &lt;/li&gt;
&lt;li&gt;CDN hosted jQuery with local failback ( shown below )&lt;/li&gt;
&lt;/ul&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRLcGQhbUqX-KSQh7C1xaEMRveni0Eb1Df2RbKbmNKF7NcV6RpS0xcK0fqkGX2vB364k31OvmKSJqsfM5Hcud8Bi2NPOrSxZmVJdjAsilEm0vRV4LNiQYKqeSuctZK__3pO_8QDkutgqo/s1600-h/image%25255B5%25255D.png&quot;&gt;&lt;img alt=&quot;image&quot; border=&quot;0&quot; height=&quot;104&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhoJwXzO7r3GgnFLVkwp4Uha3rTOyU-f_cDSI62j4uKEAy4I2ze-MF7fCi93vMQLK4CAV90xATf02At9khuiJTXJXZ7trFQyhXc5rOxdfiRir-e5UvJJtyR9_pzOeUCyaw037AhfuztWIo//?imgmax=800&quot; style=&quot;background-image: none; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; title=&quot;image&quot; width=&quot;548&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
As you can see, first we try to load jQuery using Google CDN. In the next line, we check the existence using &lt;em&gt;window.jQuery,&lt;/em&gt; which will evaluate to true if the library has been loaded successfully, else we load it statically.&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Also contains some server site configurations like .htaccess file for &lt;em&gt;caching&lt;/em&gt;, &lt;em&gt;cross-domain XHR&lt;/em&gt;, &lt;em&gt;gzipping&lt;/em&gt;, 404 error pages, robots.txt etc.  &lt;/li&gt;
&lt;li&gt;Contains ANT build scripts to integrate easily with your project build system&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&quot;wlWriterEditableSmartContent&quot; id=&quot;scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:5adba858-9a8e-49b1-aae8-73757c0107da&quot; style=&quot;display: inline; float: none; margin: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot;&gt;
&lt;div id=&quot;e183b176-af75-46e7-8219-6ce497e6e1a6&quot; style=&quot;display: inline; margin: 0px; padding: 0px;&quot;&gt;
&lt;div&gt;
&lt;a href=&quot;http://www.youtube.com/watch?v=oDlsOyPKUTM&quot; target=&quot;_new&quot;&gt;&lt;img alt=&quot;&quot; galleryimg=&quot;no&quot; onload=&quot;var downlevelDiv = document.getElementById(&#39;e183b176-af75-46e7-8219-6ce497e6e1a6&#39;); downlevelDiv.innerHTML = &amp;quot;&amp;lt;div&amp;gt;&amp;lt;object width=\&amp;quot;448\&amp;quot; height=\&amp;quot;252\&amp;quot;&amp;gt;&amp;lt;param name=\&amp;quot;movie\&amp;quot; value=\&amp;quot;http://www.youtube.com/v/oDlsOyPKUTM?hl=en&amp;amp;hd=1\&amp;quot;&amp;gt;&amp;lt;\/param&amp;gt;&amp;lt;embed src=\&amp;quot;http://www.youtube.com/v/oDlsOyPKUTM?hl=en&amp;amp;hd=1\&amp;quot; type=\&amp;quot;application/x-shockwave-flash\&amp;quot; width=\&amp;quot;448\&amp;quot; height=\&amp;quot;252\&amp;quot;&amp;gt;&amp;lt;\/embed&amp;gt;&amp;lt;\/object&amp;gt;&amp;lt;\/div&amp;gt;&amp;quot;;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi259N30ueUugfsLsDEBvifVc0Lnc-Jrd2VRZ0A2qj9A52O2_YwMLeAjfKhB500dQ2u_E4Hi8lA3kFQjyk1Hp_h-KDp9ILmp0DXNLTa9zq3p1x6NMoI-OMx93uJZtxsOuQlt89xnGn6xJI//?imgmax=800&quot; style=&quot;border-style: none;&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;clear: both; font-size: .8em; width: 448px;&quot;&gt;
Paul Irish on HTML5 Boilerplate&lt;/div&gt;
&lt;/div&gt;
&lt;a href=&quot;http://twitter.github.com/bootstrap/&quot;&gt;&lt;strong&gt;Twitter Bootstrap&lt;/strong&gt;&lt;/a&gt; – Just released 2.0&lt;br /&gt;
Includes&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Responsive&lt;/em&gt; 12-grid column  &lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://twitter.github.com/bootstrap/javascript.html&quot;&gt;Custom jQuery plugins&lt;/a&gt; for Carousel, Popovers, Accordion, Autocomplete, modals etc.  &lt;/li&gt;
&lt;li&gt;&lt;em&gt;Cross-browser compatible&lt;/em&gt; and also includes media queries for smartphones and tablets too  &lt;/li&gt;
&lt;li&gt;Includes many &lt;a href=&quot;http://twitter.github.com/bootstrap/components.html&quot;&gt;components&lt;/a&gt; like Button groups, Button Dropdowns, Navigation components, alerts and progress bars etc  &lt;/li&gt;
&lt;li&gt;Contains extensive &lt;em&gt;out of the box styling&lt;/em&gt; for your HTML markup, for elements like Forms, Tables etc. Building a bordered, shaded, alternate colored table was never so easy.  &lt;/li&gt;
&lt;li&gt;The entire framework is built on &lt;a href=&quot;http://lesscss.org/&quot;&gt;LESS&lt;/a&gt;. The codebase contains several .less files (containing different functionalities) which are then compiled into CSS.  &lt;/li&gt;
&lt;li&gt;Provides several styling as &lt;em&gt;LESS mixings&lt;/em&gt; which can be found in mixings.less which you can easily use in your code, or extend them as well.&lt;/li&gt;
&lt;/ul&gt;
&lt;strong&gt;Comparsion &amp;amp; Conclusion&lt;/strong&gt;&lt;br /&gt;
Both are superb HTML5 bootstrap frameworks, under continuous development which follow best practices developed over the years to build a fast, secure and future-proof site. But in my opinion, H5BP is something that even designers can play with using as a template, they can simply open their favourite design tool and add content. While using Twitter Bootstrap is more developer oriented and requires you to invest some time in understanding the various classes and functionalities it offers. But then, that’s the case with every good thing around you.&lt;/div&gt;</description><link>http://techno-cratic.blogspot.com/2012/05/getting-started-with-html5.html</link><author>noreply@blogger.com (Anonymous)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhoJwXzO7r3GgnFLVkwp4Uha3rTOyU-f_cDSI62j4uKEAy4I2ze-MF7fCi93vMQLK4CAV90xATf02At9khuiJTXJXZ7trFQyhXc5rOxdfiRir-e5UvJJtyR9_pzOeUCyaw037AhfuztWIo/s72-c/?imgmax=800" height="72" width="72"/><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5223788876950011016.post-6874521509634790981</guid><pubDate>Thu, 29 Mar 2012 11:25:00 +0000</pubDate><atom:updated>2012-03-29T04:39:25.466-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">JavaScript</category><category domain="http://www.blogger.com/atom/ns#">jQuery</category><title>jQuery Custom Effects</title><description>&lt;p&gt;Although &lt;a href=&quot;http://jquery.com/&quot;&gt;jQuery&lt;/a&gt; provides us with a few &lt;a href=&quot;http://api.jquery.com/category/effects/&quot;&gt;basic effects&lt;/a&gt; like slideDown/Up, fadeIn/Out etc. and a pretty powerful &lt;a href=&quot;http://api.jquery.com/animate/&quot;&gt;animate&lt;/a&gt; function to create animation/effects on any numeric CSS property, a lot of creative people have written some &lt;a href=&quot;http://www.1stwebdesigner.com/freebies/advanced-jquery-effects/&quot;&gt;amazing effects/components&lt;/a&gt; that will take your breath away. While we do not plan to reinvent the wheel here but down the road, you may also need to create your own effect and would like to access it like&lt;/p&gt; &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxzaMcSwQxL4G0x3V-qgANpNq2xUMlBK0UBwnTOyF63oZw5HcbZ2Axiwdt9LFjMbiDkQVT-72FHoG0xPuwCHFwCINuLCSOEm6-Deu_zvb8MK0oZGZtlYCGfLwT27tGYs80WOOe_XldKk4/s1600-h/image%25255B21%25255D.png&quot;&gt;&lt;img style=&quot;background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkwnOTHsjssjLq4f_sNaspAEeeDNbniYbfASpxMfq4jZ4EO2WQNEAqI5yFsfej4JrmGlWjGZj5SZeqtCkDr09CGI-uZuNMR1Uo8OgbKRXKlV4LDoc9MYu4-fxDiTpBt51ZlLuswwQoJHU//?imgmax=800&quot; width=&quot;318&quot; height=&quot;59&quot;&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Surprisingly, being able to do so is not as difficult as it might seem at first, and can be achieved by adding a new function property to &lt;strong&gt;jQuery.fn&lt;/strong&gt; object as below:&lt;/p&gt; &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbHxXY4ctcXDqbIyZf-YZWlWaCUBQC31vmlAd4V6ML-1mwBz3EM6mbpu-0q7TKcTzru6GG_2va65wh-z2Liou9Xusnc0oykJr92DyBsYgzIcoGvm4dznepC3w6YPH0b_xzxPUQBOEnM0Y/s1600-h/image%25255B4%25255D.png&quot;&gt;&lt;img style=&quot;background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi22ezOXfyzNd0rhfU3c79XViQoDfP-tUF0Cv05_luQonMEPVoCXM1_ybXGvokyFyjjHmI_8GDJ8zc_96hKEQTuBJ2E2BcQhdN8mfBZJ5uFhKwd1Era1l0y3NvkT-H6_N3s-Q-UwrYtIiE//?imgmax=800&quot; width=&quot;434&quot; height=&quot;100&quot;&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;The above function simply extends the jQuery object by adding a new method in the jQuery &lt;strong&gt;prototype&lt;/strong&gt; ( jQuery.fn object ). Before diving deep into the implementation, it is important to understand the concept of &lt;a href=&quot;http://javascript.crockford.com/prototypal.html&quot;&gt;prototypal inheritance&lt;/a&gt; in JS and reading &lt;a href=&quot;http://msdn.microsoft.com/en-us/magazine/ff852808.aspx&quot;&gt;this article&lt;/a&gt; will open your eyes for sure.&lt;/p&gt; &lt;p&gt;Coming back, a naive implementation looks like&lt;/p&gt; &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEizD9596Zqr0dzp8BzDmNHVAPNwL_Dh2pDwOmwIRGecSQgLvCL-RcDlxu6JO_LSbxlUmZjctgVuY0YuvVLcMtvbbjDDBZKWgltTBpN2FIYaTb7fQLjxekmQGbJoat0X4rgkJ-ZDUcptzGs/s1600-h/image%25255B18%25255D.png&quot;&gt;&lt;img style=&quot;background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwoZocvBzlHwTVgKYs7rvwlBn7rmCiLnEIW9oGCyBOjJPybncixlMtA3MD_qa4KmeueKp11vvW2l2zixRsnDsVrpkXyk5LPS5m-6-20WRtTwt65rxoQViPORdLfCdtXr_qDAbuB6aKTXk//?imgmax=800&quot; width=&quot;484&quot; height=&quot;215&quot;&gt;&lt;/a&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Here, we delegate the actual work to animate method and toggle the height &amp;amp; opacity of the selected DOM element for the given speed if any, else a default of 400ms is used. It also allows us to specify a callback function to be called after the animation/effect is complete. To accomplish that, we first check whether the passed variable (fn) is actually a function using &lt;a href=&quot;http://api.jquery.com/jQuery.isFunction/&quot;&gt;isFunction&lt;/a&gt; and then &lt;a href=&quot;https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/call&quot;&gt;call&lt;/a&gt; the method passing this as the context. &lt;/p&gt; &lt;p&gt;Another important thing to note is that we are returning the jQuery object back from our function so that you can take advantage of chaining like:&lt;/p&gt; &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLkfmetZAn4AQ-MOH-fg3Z8o0IiELfYRwpXFGRn2Bj2y1EFk22dkOklIZ-bbZkpkQ7fjAN9UIQlHELmwomR2cxBDdoXt2TWo6HdIoHqFzBK2-MODyeBuJVAMI86qEsnVKwLqozCJ9ag6c/s1600-h/image%25255B27%25255D.png&quot;&gt;&lt;img style=&quot;background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigvuKlivT_nMOeVzByXgkeFPV3_jY1iIhQrq-nwEnF4wyMOhh85RBvox4Z7ZZzOv_5jhSnRFl6rphCdPHN1nEPnlRSjb1hVH8ZN0bV1svNQYzecR5h8H48IAbdclGWPCF7PiSM3m3bjgU//?imgmax=800&quot; width=&quot;529&quot; height=&quot;119&quot;&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;So this wraps up a short and simple post on how to create custom effects by extending jQuery object. If you have any questions or comments, please leave them as comments.&lt;/p&gt;  </description><link>http://techno-cratic.blogspot.com/2012/03/jquery-custom-effects.html</link><author>noreply@blogger.com (Anonymous)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkwnOTHsjssjLq4f_sNaspAEeeDNbniYbfASpxMfq4jZ4EO2WQNEAqI5yFsfej4JrmGlWjGZj5SZeqtCkDr09CGI-uZuNMR1Uo8OgbKRXKlV4LDoc9MYu4-fxDiTpBt51ZlLuswwQoJHU/s72-c/?imgmax=800" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5223788876950011016.post-3501266141318318913</guid><pubDate>Wed, 15 Feb 2012 19:14:00 +0000</pubDate><atom:updated>2012-07-29T02:28:46.862-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">Servlets</category><category domain="http://www.blogger.com/atom/ns#">Web-Apps</category><title>Servlet Config, Context &amp;amp; Listeners</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Why talk about Servlets when there are JSPs…. Right ? That’s what came into mind especially when we read about how JSPs are way more easy and fun to write. But Servlet exists for a more meaningful purpose that than just churn out HTML, for instance they act as a Controller for many frameworks. But this is not about how important Servlets are, rather today we will talk about ServletConfig, ServletContext and ServletContextListeners.&lt;br /&gt;
&lt;strong&gt;ServletConfig&lt;/strong&gt;&lt;br /&gt;
&lt;a href=&quot;http://docs.oracle.com/javaee/6/api/javax/servlet/ServletConfig.html&quot;&gt;ServletConfig&lt;/a&gt; is a helper object which we can use in our servlets to get configuration of a Servlet. The configuration can include things like Servlet name, its context (described below) and init-parameters. For example, consider the following servlet declaration in a Deployment Descriptor (DD)&lt;br /&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheUh0ZdFUHXY4HpxAqB5MnIAhESCQUZVFmESvjAgaj7WHu0RVpMEDPMpBTq0KE8lGZtn2pkcgWLzur6sdoxKlvnQWJLx0f8LRa90SUb7IzU5M2c37gmRbk6pJbpRSQS2bk96sOfkP2JGc/s1600-h/image3.png&quot;&gt;&lt;img alt=&quot;image&quot; border=&quot;0&quot; height=&quot;168&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGa3HfuJSN-nrIbJ4A2Ikx3gO361LnCBiC1UhuF9qsXHko5tGcxv9CNk6UHto0T2rF1qEQ4ELIH6E859e60K1ov5l3SWjUwuiZkHRY4l_UJ6r2WnRJoGBYCglqwHACbkHk0UqYqPIVbkQ//?imgmax=800&quot; style=&quot;background-image: none; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; title=&quot;image&quot; width=&quot;491&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
So instead of hardcoding the feedback email in the servlet responsible for sending the feedback mail, we can simple configure it in the DD and the servlet can pick the value from using ServletConfig as shown below:&lt;br /&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiH4bxj7uAfp-60uPqHRxop0PDOx07jaAmUfGs8kHkqqs6t9uxovs2cv3R5MOI3f_y_W0K9AEQC8GJu1ayr-ElxclGVbN-p-R4R7ChsL27CoAFkC4fSC9X1yWYbq6KPxWm3hdBiPvOmSEA/s1600-h/image8.png&quot;&gt;&lt;img alt=&quot;image&quot; border=&quot;0&quot; height=&quot;67&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_LmRaabrRkqvK_vVW_tKYh0AtrSzJ0sEgVpexgOR_JkbM7gnH75-wc4JDkmC0lbE95Jbu9HqJFY9JJsknggKRYq5dGMuKa8LV4Y8pmvZIOvCpuQo2b_T2HhB2RZP_wqIEJXMQzZnaENg//?imgmax=800&quot; style=&quot;background-image: none; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; title=&quot;image&quot; width=&quot;496&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
The container is responsible for creating a ServletConfig object per servlet and pass to it after it has been initialized so it would be good to note that we can not use this object until the init() method i.e. we cannot access these init params inside the servlet’s constructor.&lt;br /&gt;
&lt;strong&gt;ServletContext&lt;/strong&gt;&lt;br /&gt;
ServletContext, on the other hand acts as a global helper and is not created once per servlet, rather it is created once per application (when an application is deployed) and is normally used to configure application level parameters amongst other things. A typical example would look like:&lt;br /&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgaRSN6UoT8kJI2895If4dF6nYRl-9elqqYcHy8kKr1gzZmBsgnYiwOeEJ3RChLCn1_Oh7z_5cBJpOcoc0JxIZYXpMTfRdG8ygb_1WTTnJkFRoPVWd6HxQRUuxo6cYBYSGmwukhgAmEfqM/s1600-h/image16.png&quot;&gt;&lt;img alt=&quot;image&quot; border=&quot;0&quot; height=&quot;86&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1xTMIrLU2zxlQYWEsdN5vecBTszIWhef0cGM94MlPKS8N6lmtnyaOqnXhFXzlvZMFryo4CM7KK27-Mf4AsD8lflCvdyydttQeKhwD7ybhGQZB8aDjGh1RE5G8UujD06GbO_rCeIQK7_I//?imgmax=800&quot; style=&quot;background-image: none; border-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; title=&quot;image&quot; width=&quot;300&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
and would be accessed as &lt;br /&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjesd5_k28KFEg9_8fyxQih5uWUhmAFWg_WgBOKrlvvqAxyu130qw-MygVxW0p0pd6Dn9l7Kgf5f53wRLezs-nlKClha-a1YBnPjbRACnYomPD8SxPnmusWNn2mh-vvkhw5m5a99__iLFo/s1600-h/image21.png&quot;&gt;&lt;img alt=&quot;image&quot; border=&quot;0&quot; height=&quot;59&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCUx4uMdpLqXoyn72gBkE4OaVdhyvjkOaHRIHzzOCQqg1M4f_POsJ5mDne0LvY-ux8xa21wB9SoEzlo70iFQrgcKa7MXA8sSbRYwvjtqw_sKo8OqKllqLmcnp-xeh5eVxLbW78Tkto-Ls//?imgmax=800&quot; style=&quot;background-image: none; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; title=&quot;image&quot; width=&quot;503&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
Now these params can be accessed across all the servlets and JSPs that the application deploys. There are a bunch of other useful information that you can grab from a ServletContext and all of that can be seen &lt;a href=&quot;http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContext.html&quot;&gt;here&lt;/a&gt;.&lt;br /&gt;
&lt;strong&gt;ServletContextListener&lt;/strong&gt;&lt;br /&gt;
What if I want to do some special handling when my web application is initialized (or deployed) or destroyed/removed ? The servlet spec gives you a way to hook into the lifecycle of your web application by implementing a &lt;a href=&quot;http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContextListener.html&quot;&gt;ServletContextListener&lt;/a&gt; which can listen for these events and act accordingly. Following is an example that picks up the datasource configuration from DD and creates a corresponding &lt;a href=&quot;http://docs.oracle.com/javase/6/docs/api/javax/sql/DataSource.html&quot;&gt;DataSource&lt;/a&gt; object and save it in ServletContext so that it can be easily retrieved by any servlet wishing to perform a database operation:&lt;div&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEin0jFS5WWOTfVcpBPVm_Mv78Np5CVU7nf6pmyAxNvxEAH5G2BtxVf0bZ0tlkYYWj46h9SMVNY68M1tzqMB9xTmTaIJI9dy2KWRO3Y87WYQsmy46Hm6NlSs5P6xnkN2kH1G63THEGh2cOM/s1600/init.tiff&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;264&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEin0jFS5WWOTfVcpBPVm_Mv78Np5CVU7nf6pmyAxNvxEAH5G2BtxVf0bZ0tlkYYWj46h9SMVNY68M1tzqMB9xTmTaIJI9dy2KWRO3Y87WYQsmy46Hm6NlSs5P6xnkN2kH1G63THEGh2cOM/s400/init.tiff&quot; width=&quot;420&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;The actual code of creating a &lt;/span&gt;&lt;a href=&quot;http://docs.oracle.com/javase/6/docs/api/javax/sql/DataSource.html&quot; style=&quot;background-color: white;&quot;&gt;DataSource&lt;/a&gt;&lt;span style=&quot;background-color: white;&quot;&gt; object from the string is being left out as it does not serve any purpose for this example. This listener will have to be configured in the deployment descriptor so that it can listen and respond to the lifecycle events as:&lt;/span&gt;&lt;br /&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOq8hbv8NjZXs8WrauPhck5DqKLZGgPLgMOo7rAJ7chCf4QcjEzZIyeCn_fY8PonwKTzV60dlx95Hl1izkhn7RsZUlLm5db9z-gnRBLZ8a4pa0UUmlkDjXCnRA3OJWSMeCBtvSjPSsw4Q/s1600-h/image5.png&quot;&gt;&lt;img alt=&quot;image&quot; border=&quot;0&quot; height=&quot;73&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgeenaCtPMmTRLxMi42BBx-w8FeKZ9AUtI1nZespeAwS2joG3xGkDlzRpk40ym9siZCFVfsBuDPF-wMKbMFPogaEwPNdqVkUnKsWnNhWhto3TnJ8aNGb51fZag3UTsvjw3kkemOvdPxnTw//?imgmax=800&quot; style=&quot;background-image: none; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; title=&quot;image&quot; width=&quot;528&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
There are many other types of listeners that we can write to handle different use cases viz. &lt;a href=&quot;http://docs.oracle.com/javaee/6/api/javax/servlet/ServletRequestListener.html&quot;&gt;ServletRequestListener&lt;/a&gt;, &lt;a href=&quot;http://docs.oracle.com/javaee/6/api/javax/servlet/ServletRequestAttributeListener.html&quot;&gt;ServletRequestAttributeListener&lt;/a&gt;, &lt;a href=&quot;http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContextAttributeListener.html&quot;&gt;ServletContextAttributeListener&lt;/a&gt; to name a few but we will see them in action some other day.&lt;br /&gt;
&lt;strong&gt;Disclaimer&lt;/strong&gt;&lt;br /&gt;
With Java EE Annotations, we really don’t have to configure a servlet in DD (as shown in the examples above). They are just there to make things easy to comprehend.&lt;/div&gt;</description><link>http://techno-cratic.blogspot.com/2012/02/servlet-config-context-listeners.html</link><author>noreply@blogger.com (Anonymous)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGa3HfuJSN-nrIbJ4A2Ikx3gO361LnCBiC1UhuF9qsXHko5tGcxv9CNk6UHto0T2rF1qEQ4ELIH6E859e60K1ov5l3SWjUwuiZkHRY4l_UJ6r2WnRJoGBYCglqwHACbkHk0UqYqPIVbkQ/s72-c/?imgmax=800" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5223788876950011016.post-5992948521603658292</guid><pubDate>Sat, 17 Dec 2011 18:44:00 +0000</pubDate><atom:updated>2011-12-17T10:44:13.647-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">DragNDrop</category><category domain="http://www.blogger.com/atom/ns#">HTML5</category><category domain="http://www.blogger.com/atom/ns#">JavaScript</category><title>HTML5 Native Drag ‘n’ Drop</title><description>&lt;p&gt;HTML5 does not only mean a whole new world of tags (video, audio, header, footer, article, section etc.) and revolutionary technologies like &lt;a href=&quot;http://html5demos.com/geo&quot;&gt;Geolocation&lt;/a&gt;, &lt;a href=&quot;http://www.html5rocks.com/en/tutorials/appcache/beginner/&quot;&gt;Application cache&lt;/a&gt;, &lt;a href=&quot;http://www.canvasdemos.com/&quot;&gt;Canvas&lt;/a&gt;, &lt;a href=&quot;http://dev.w3.org/html5/workers/&quot;&gt;Web Workers&lt;/a&gt; etc. but it also brings along a rich set of JavaScript API to developers. &lt;/p&gt; &lt;p&gt;Today, we witness one of the interesting feature that it provides; the capability of dragging and dropping elements natively without using any JS framework. &lt;a href=&quot;http://www.whatwg.org/specs/web-apps/current-work/multipage/dnd.html&quot;&gt;The HTML5 spec&lt;/a&gt; defines the new events that we should catch in order to handle operations like&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Start of drag operation ( &lt;strong&gt;dragstart&lt;/strong&gt; )  &lt;li&gt;Dragging content over another element ( &lt;strong&gt;dragover&lt;/strong&gt; )  &lt;li&gt;Entering the drag area of another element ( &lt;strong&gt;dragenter&lt;/strong&gt; )  &lt;li&gt;End of Drag operation ( &lt;strong&gt;drop&lt;/strong&gt; )&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;If you have worked with a &lt;strong&gt;RIA-friendly&lt;/strong&gt; language such as &lt;a href=&quot;http://www.adobe.com/devnet/actionscript.html&quot;&gt;ActionScript&lt;/a&gt;, then you will found this to be very similar. Having said that, providing this drag and drop support in the browser itself is the reason behind the fame of HTML5.&lt;/p&gt; &lt;p&gt;Coming back, lets see some code in action. We have some images in our page which we want to drag and drop in div container. These images are tagged with class “&lt;strong&gt;dragMe&lt;/strong&gt;” (so that we can attach event listeners to them). Similarly, we have a div container in which we are going to drop these images with an id of “&lt;strong&gt;dropOnMe&lt;/strong&gt;”.&lt;/p&gt; &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjJrPzz5WMj74p2eqH3vrGg3AjtG6-jTarOTitoG7f9flIUiCsZJwC4FkHJIpqbF8XxZEPs98wog2zOqLnUCfr1XpEPqlQFIt32Mo2iom2-_qP5AutHF2Rw-rofCuAz14N6Ff4n885ScI/s1600-h/htmlCode%25255B5%25255D.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;htmlCode&quot; border=&quot;0&quot; alt=&quot;htmlCode&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2T-WatsQgUmQ5FCX_1gwShyxaXtr1UKXZ7vznOiQ3buSw9iJLojaFgtdI_4M-j4BKezCNk3MVi15w2w6T8cR3uXg7knMr8w1zSD9suDs864ck1xcFg4fckJ4H_xk764NTFNbk869VKlQ//?imgmax=800&quot; width=&quot;520&quot; height=&quot;382&quot;&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Things to note &lt;/p&gt; &lt;ul&gt; &lt;li&gt;&lt;strong&gt;draggable=true&lt;/strong&gt;&amp;nbsp; -&amp;nbsp; By default, images and links are draggable in nature but I have added this attribute just to convey that any HTML5 element can be selected, dragged and dropped if you add this attribute to it. Also add following CSS to make it work across different browsers&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfi-48jpuffZ-5ItyZ6ZDfyG0xzFX9J0NM2VYPp1OdO_spGardDWQ12Cvyg74loPr6av1SHrUTAlah82WfvsIyKL7lHg0FMatLxU2ngPyLb0HrkP1AZXsjJBxhXn3yBUlXwAqb_MpRZw0/s1600-h/draggableTrueCss%25255B2%25255D.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;draggableTrueCss&quot; border=&quot;0&quot; alt=&quot;draggableTrueCss&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEid9xxW2OiT_oXfCP1ChxBayoaXWcNfNYdoj0ghYdbnS4utFV4zvMy48m00HDheSK3hOBiBOA9GNMPiyWLE5g7DoX_TRLEWXHhIFuBto1pjO93xAmPjNFXeODZjw70t668hor1ejVMUSr4//?imgmax=800&quot; width=&quot;244&quot; height=&quot;127&quot;&gt;&lt;/a&gt;&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Custom &lt;strong&gt;data-*&lt;/strong&gt; attributes&amp;nbsp; -&amp;nbsp; Again something, HTML5-blessed. It provides us the capability to define custom data-attributes on any element. Here we use it to define properties of individual images. More on custom data-attributes &lt;a href=&quot;http://html5doctor.com/html5-custom-data-attributes/&quot;&gt;here&lt;/a&gt;.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;Next, we add some event handlers to handle drag n drop related events we defined above:&lt;/p&gt; &lt;p&gt;1. &lt;strong&gt;Adding Drag Handlers&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhENNgWjSIJrDsqNJjMBJKzFErl2gwYEU2FqjJ0rjhutvk__6fxf5MTB0TKdSK8diHQLF94pSYP1AQCW3q3pvNjEho6Sy-bJjnxoIH_8z_N9tMqn9PIsZhBhBjfvOuo19fyZD9BSYKdB9c/s1600-h/dragStart%25255B8%25255D.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;dragStart&quot; border=&quot;0&quot; alt=&quot;dragStart&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhUQ3VEL-EVoQryTJGUl3xC8orMUoeoW-BsCAu5B04zL4UPJvyQJ9FsQCRS3Kq-vFYOiIuwW6E7rvcMD_TfLqIxERSl4PZ4yr7-xskUk980Dovz6CVDyQsIIuTlaf8-wHX4B3cKr_FjfNA//?imgmax=800&quot; width=&quot;426&quot; height=&quot;166&quot;&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;We took a hold of all the elements that are to be dragged and attach to each, a drag handler which will be called whenever you click and try to drag that elements. In the handler, we update the event’s&lt;a href=&quot;https://developer.mozilla.org/En/DragDrop/DataTransfer&quot;&gt; dataTransfer&lt;/a&gt; object and set custom properties in the JavaScript object, which we defined in the markup&amp;nbsp; (yes you guessed it right, we are going to use them in the drop handler)&lt;/p&gt; &lt;p&gt;2. &lt;strong&gt;Adding Drop Handlers&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhwl3saqL9O3caIjXCDT3c8U1fs9V1QD6hcGLjaxeMQOQi05BQS7H7DbtHkqFzSQlpSDrwIALMocfvRzfQmrwSh-6p8vT5QD-Z2PLug-ythuWZXJw9lnS_rUF6fVP5x39JrUjdNQ7zhHz0/s1600-h/dropHandler%25255B4%25255D.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;dropHandler&quot; border=&quot;0&quot; alt=&quot;dropHandler&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuvdtpsKjsIhPOWKPXSPls5ySM3V0ktd3gxGOyQx6cWTwnuZ1R4EWLZBKxFSDMGWVGXE0l2YKlrE3sLZgymLDnBBG7pzqOvyXOqYWZ_fS74NZ9gWNOiEm2-baBqzQ4X_XSTJjvzouRUXw//?imgmax=800&quot; width=&quot;520&quot; height=&quot;204&quot;&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Note that we use both &lt;strong&gt;e.preventDefault()&lt;/strong&gt; and &lt;strong&gt;return false&lt;/strong&gt; in the function, to make it work across different browsers; this is needed to make sure that we cancel the default action that the browser will normally take, like surfing to that location (in case of a link). Apart from that, the code just retrieves the data set in dataTransfer object and display that using &lt;strong&gt;innerHTML&lt;/strong&gt; of the div.&lt;/p&gt; &lt;p&gt;3. &lt;strong&gt;Adding handlers for dragover &amp;amp; dragenter&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9rxjEEtDLa_Iuh3SEbZnR9CjMVqCG-qrgbcMopYWYZVpazxLjn-h7yJTy3T98E7_-64G92TvD-opgCZEgeG5fERhPtFQE4RUOig2A14l2qdkUGC_WdrK9ncDq0m9CR55gJrc7P8va54E/s1600-h/dragOverEnterHandlers%25255B7%25255D.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;dragOverEnterHandlers&quot; border=&quot;0&quot; alt=&quot;dragOverEnterHandlers&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiNffmbBGQ_QD4n7IStR-Z3Q-OAhPbHeS8fH7SVSzJlwNCRvUcuc19k8ALSnc-na7x5VxggNQ_MMYUoaUjFWre7MNH50IZIP_smbnYcVcT-qqTw8bymDi82N-g8X6idls7DUdVUzWk2PaA//?imgmax=800&quot; width=&quot;333&quot; height=&quot;144&quot;&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Again for making the code work across different browsers (tested on Firefox, IE and Chrome), we need to use both preventDefault() and also return false from the handler in order to inform the browser that you can drop and release the dragged item on &lt;strong&gt;this &lt;/strong&gt;element for which the function is called.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;A Lot More…&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;..can be achieved like customizing the &lt;strong&gt;drag icon&lt;/strong&gt; and even drag and drop across different instances of same browser or even dragging from one browser and dropping in another browser. Stay tuned or check out the spec for more details.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Final Demo Looks like&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;Too bad that I don’t have a proper hosting solution, so you have to do with images, until you are passionate enough to write the above code yourself.&lt;/p&gt; &lt;p&gt;Initial Screen&lt;/p&gt; &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNeJdgrqSdOFTgndM56CwekW-XAzx12vKTFtLrhBRmYsE-MK0by9vcMkVSUVN_2jRIUyn_eudPmdkkSEJlFfxCYVjfTsB4AxzJiPnAvEm3bzB7cw8YBT1hETqz_laOL9frHD9FFta7uTM/s1600-h/image%25255B14%25255D.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6HxxCejoZpH5jsQEwYpyeFu0BO8DDRlCBP6kzJ7Jjkn4IKj4_-V8CEiJfSL6Bh7ufZe3qisLbpYcBoYnLLUrWLI2tQHKlqwuGuXCIpP3gua396YX5pj_Suh-8TzIlH9sA_6y2aq09BaE//?imgmax=800&quot; width=&quot;441&quot; height=&quot;274&quot;&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Dragging an Item&lt;/p&gt; &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtl5RirB2xYVE8PZFYm4YW-2TabnBa11kNpwVA5PcEESnCjexbuunTmoCKVaa6QnTO9WSkLFA3h95Rw_257AykW0K9ydQek03LIE1AjPAxJZcl5uraaxGQps4EhySVF4VSejOfTGXLeMM/s1600-h/image%25255B7%25255D.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0d1DdXipe4e5LjgSttXhUTS4IeW30b57Gx8ZIXwd4buZXWT4XIQ7Nwuakqrd8M4PkVWCidxjAi1Aun1fxy31-CFqQmlq5Bsq07DpvwjsCEJCTY0fILy2_twhYHAT5Jg37ZQ8aNFjwtkc//?imgmax=800&quot; width=&quot;435&quot; height=&quot;255&quot;&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Dropped it !!&lt;/p&gt; &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiv2qkQ1HwDTkuHlj1aXkJaGAU6QKXzUMDLDM7oUvvv2JkFdwS0Vjd1IH3pONGNcfwC-9onX8yxJDqpmrWdsZjyqwe5GtUhPS2KNO2jEh3Ytt9CEk4Bvz9QbtRiz2sRkSGk2jybsxQg3s4/s1600-h/image%25255B12%25255D.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;image&quot; border=&quot;0&quot; alt=&quot;image&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjM8IatEGYVllCgxiNlO7kjOEpNbomhhVVqxoxeqwUlDYdenskEfX5ztR-OUG81wRwUMyYPI2uoziNC8Qyq3BfHhFaD-onRBR9rr2__WrmpQWJjjQQ17QkZo89xwU0fQgLwyQh7nyQ8CjU//?imgmax=800&quot; width=&quot;437&quot; height=&quot;263&quot;&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;We can add more spice to the tut by adding CSS and some other effects but in the hope that it would overshadow the concept, I emphasize on the minimal code needed for it.&lt;/p&gt; &lt;p&gt;Any suggestions, improvements or bugs are welcome as comments.&lt;/p&gt;  </description><link>http://techno-cratic.blogspot.com/2011/12/html5-native-drag-n-drop.html</link><author>noreply@blogger.com (Anonymous)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2T-WatsQgUmQ5FCX_1gwShyxaXtr1UKXZ7vznOiQ3buSw9iJLojaFgtdI_4M-j4BKezCNk3MVi15w2w6T8cR3uXg7knMr8w1zSD9suDs864ck1xcFg4fckJ4H_xk764NTFNbk869VKlQ/s72-c/?imgmax=800" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5223788876950011016.post-2805654786408385353</guid><pubDate>Sat, 19 Nov 2011 16:27:00 +0000</pubDate><atom:updated>2011-11-19T08:32:53.071-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">CSS3</category><category domain="http://www.blogger.com/atom/ns#">Media Queries</category><title>CSS3 Media Queries</title><description>&lt;p&gt;&lt;strong&gt;Need of Media Queries&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;Gone were those days when designers had the liberty to design or layout a web page for fixed/minimum resolution as most people would just use their desktop for browsing the web. In this mobile/tablet era, we cannot assume that the desktop would be the only &lt;strong&gt;user agent&lt;/strong&gt;. A large number of users today use their “smartphones” or “tablets” for browsing the web and so it becomes crucial that your website looks as good when viewed from such a device.&lt;/p&gt; &lt;p&gt;Many websites today have different version of websites, one each for desktop and mobile. By detecting the user agent when the user visits the website for the first time, it can redirect them to the mobile version if he is browsing the web using his smartphone. But this solution comes with its own headache of maintaining separate presentation layers for separate mediums and fixing bugs in both !!&lt;/p&gt; &lt;p&gt;This is where Media Queries come into picture. They provide an elegant solution to the problem by providing the ability to switch the CSS based on the user agent or device’s width or orientation. In short, they make your web design adaptive and responsive to change. &lt;/p&gt; &lt;p&gt;&lt;strong&gt;Wow, that’s new !!&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;Not really !!. They were very much a part of CSS2 and HTML4 specification where they were limited to ‘print’ and ‘screen’ only (meaning using CSS2, you can only specify different style-sheets for rendering and printing a web page). But with CSS3, more media types are supported and different style-sheets can be applied based on&lt;/p&gt; &lt;ul&gt; &lt;li&gt;device-width and height  &lt;/li&gt;&lt;li&gt;viewport-width and height  &lt;/li&gt;&lt;li&gt;orientation  &lt;/li&gt;&lt;li&gt;aspect-ratio  &lt;/li&gt;&lt;li&gt;device aspect-ratio  &lt;/li&gt;&lt;li&gt;resolution etc..&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;Without wasting more time, lets see an example. We will create a layout for a widescreen (desktop layout) and using media queries, we will change the layout and color the markup when we resize the browser (to simulate tablet and mobile size) &lt;/p&gt; &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBvJSDOOk_LWfd6sDkEKDyO6lbPQ7ipd3Gwz-qxuR4hA7jVc60tT4l85oAizdqYoC67pp2RzqrfNxgAtdzLCX1FptZX4814HzXOr_u6bpheqz7GcVkrzzPc5kW_Bx1IB38shW4Tx2mYz8/s1600-h/wideLayout3.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;wideLayout&quot; border=&quot;0&quot; alt=&quot;wideLayout&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhz-P6n0L_Gn5JZsbygE4-jQf6vrUovJoqKmPVAexDr1Xu7_Ni5zCzwqbXVFGHcOLuzZMXiqZYZY4frr0BJEBv53QptT4nqdKMnMfZ9_mHM5tK-BJ7WGIoB13jgf_IA6tTd8Y8bxLnU2aI//?imgmax=800&quot; width=&quot;340&quot; height=&quot;221&quot; /&gt;&lt;/a&gt;     Layout for Wide Screen&lt;/p&gt; &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgqsoCqScFxzpKt3fwd8bDnRrd1YtPfftA5cncJ6rQ_PSi2UScAnkFIjyRrafzvHCYMqQp5zhQmMKtxi-v_uBNeGkxsFzKoUM3Ao6yz9wbv4mMVLl2dW4vUPC6p4M4Lm8YJ2ja4Pgxx9Zg/s1600-h/tabletLayout2.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;tabletLayout&quot; border=&quot;0&quot; alt=&quot;tabletLayout&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjhTDMaZOu58afF0xv3YjjOEv23BBV_cN0fbzLFPxLG69FPU1Z4QzrDoaNmAsdo31FF1mY3lqLsn-kbUSsBNzJaBDYSlxAfM-X6oBSomsKSR6oaONocgK6FpIKhaBf1MZdkqZbi0onXmk//?imgmax=800&quot; width=&quot;244&quot; height=&quot;226&quot; /&gt;&lt;/a&gt; Layout for Tablet or Not So Wide Screen&lt;/p&gt; &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjn5wu-1YTarnNoDVtrb2dQMq9VpBHqjImX0h_rGg4jIBDwQQszliLhe1CsiZ-NJtuoycxbFst7xUVdON3-fdsMZ0TmGShexNvZS63brbyp9imXWC7Xg5AmfolM4b-TPpHFK66-R7oYByI/s1600-h/phoneLayout2.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;phoneLayout&quot; border=&quot;0&quot; alt=&quot;phoneLayout&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhajB-VBbv6nEShl9E75gSg38RQNxylOcJQaKEPswn4K9LerjHKns_0UTtwhFLJsZl2PnynCgT-BCdgN2fmmmK3Ufu_X5nGUlRM38RK3n9mtdpRX5yXNyy0PnYiPF3kDcjOWQuPDKIzQ4//?imgmax=800&quot; width=&quot;244&quot; height=&quot;237&quot; /&gt;&lt;/a&gt;  Layout for a Mobile Device&lt;/p&gt; &lt;p&gt;In this &lt;strong&gt;lame-example&lt;/strong&gt;, we have simple created a &lt;strong&gt;three-column layout&lt;/strong&gt; for a widescreen or desktop, and changed it to a &lt;strong&gt;two-column&lt;/strong&gt; layout for a tablet and coloured the sidebar blue (not to show my design skills of course,  but to distinguish between the layouts) and then a &lt;strong&gt;stacked layout&lt;/strong&gt; for a mobile device with red coloured div. and All this by simply switching the CSS for the same HTML file. All the code is explained below:&lt;/p&gt; &lt;p&gt;&lt;strong&gt;index.html&lt;/strong&gt;&lt;/p&gt;&lt;pre class=&quot;csharpcode&quot;&gt;&lt;span &gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;!&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;DOCTYPE&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;HTML&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;  &lt;br /&gt;   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;meta&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;viewport&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;width=device-width, initial-scale=1&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;meta&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;charset&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;UTF-8&quot;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;link&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;media&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;only screen and (min-width: 800px)&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;rel&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;stylesheet&quot; &lt;/span&gt;&lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;css/desktop.css&quot;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;link&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;media&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;only screen and (min-width: 400px) and (max-width: 800px)&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;rel&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;stylesheet&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;css/tablet.css&quot;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;link&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;media&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;only screen and (max-width: 400px)&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;rel&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;stylesheet&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;css/phone.css&quot;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;  &lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;header&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt; Header &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;sideBar&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt; Side Bar &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;content&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt; Content &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;extra&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt; Extra &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;html&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;desktop.css&lt;/strong&gt;&lt;/p&gt;&lt;pre class=&quot;csharpcode&quot;&gt;&lt;span &gt;div&lt;br /&gt;{&lt;br /&gt;   border: 1px solid;&lt;br /&gt;}&lt;br /&gt;body&lt;br /&gt;{&lt;br /&gt;   width:1000px;&lt;br /&gt;   margin: auto;&lt;br /&gt;}&lt;br /&gt;&lt;span class=&quot;rem&quot;&gt;#sideBar&lt;/span&gt;&lt;br /&gt;{&lt;br /&gt;   float:left;&lt;br /&gt;   width:250px;&lt;br /&gt;   height:600px;&lt;br /&gt;}&lt;br /&gt;&lt;span class=&quot;rem&quot;&gt;#content&lt;/span&gt;&lt;br /&gt;{&lt;br /&gt;   float:left;&lt;br /&gt;   width:448px;&lt;br /&gt;   height:600px;&lt;br /&gt;}&lt;br /&gt;&lt;span class=&quot;rem&quot;&gt;#extra&lt;/span&gt;&lt;br /&gt;{&lt;br /&gt;   margin-left:700px;&lt;br /&gt;   width:296px;&lt;br /&gt;   height:600px;&lt;br /&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;tablet.css&lt;/strong&gt;&lt;/p&gt;&lt;pre class=&quot;csharpcode&quot;&gt;&lt;span &gt;div&lt;br /&gt;{&lt;br /&gt;   border: 1px solid;&lt;br /&gt;}&lt;br /&gt;body&lt;br /&gt;{&lt;br /&gt;   width:700px;&lt;br /&gt;   margin: auto;&lt;br /&gt;}&lt;br /&gt;&lt;span class=&quot;rem&quot;&gt;#sideBar&lt;/span&gt;&lt;br /&gt;{&lt;br /&gt;   float:left;&lt;br /&gt;   width:200px;&lt;br /&gt;   height:600px;&lt;br /&gt;   background-color:blue;&lt;br /&gt;}&lt;br /&gt;&lt;span class=&quot;rem&quot;&gt;#content&lt;/span&gt;&lt;br /&gt;{&lt;br /&gt;   margin-left:202px;&lt;br /&gt;   height:600px;&lt;br /&gt;}&lt;br /&gt;&lt;span class=&quot;rem&quot;&gt;#extra&lt;/span&gt;&lt;br /&gt;{&lt;br /&gt;   clear:both;&lt;br /&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;phone.css&lt;/strong&gt;&lt;/p&gt;&lt;pre class=&quot;csharpcode&quot;&gt;&lt;span &gt;div&lt;br /&gt;{&lt;br /&gt;   border: 1px solid;&lt;br /&gt;}&lt;br /&gt;body&lt;br /&gt;{&lt;br /&gt;   width:350px;&lt;br /&gt;   margin: auto;&lt;br /&gt;}&lt;br /&gt;&lt;span class=&quot;rem&quot;&gt;#sideBar&lt;/span&gt;&lt;br /&gt;{&lt;br /&gt;   height:100px;&lt;br /&gt;}&lt;br /&gt;&lt;span class=&quot;rem&quot;&gt;#content&lt;/span&gt;&lt;br /&gt;{&lt;br /&gt;   height:100px;&lt;br /&gt;   background-color:red;&lt;br /&gt;}&lt;br /&gt;&lt;span class=&quot;rem&quot;&gt;#extra&lt;/span&gt;&lt;br /&gt;{&lt;br /&gt;   height:100px;&lt;br /&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;p&gt;This HTML files simple contains 4 Div’s in the &lt;em&gt;body&lt;/em&gt; and &lt;em&gt;head &lt;/em&gt;contains links to some style-sheets with media queries using &lt;em&gt;link&lt;/em&gt; tag, lets see what these queries mean&lt;/p&gt;&lt;pre class=&quot;csharpcode&quot;&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;link&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;rel&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;stylesheet&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;css/desktop.css&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;media&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;only screen and (min-width: 800px)&quot;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;p&gt;It can be read as include the “&lt;strong&gt;desktop.css&lt;/strong&gt;” file if and only if the user agent has a screen and the minimum-width of the device is 800 pixels. Similarly,&lt;/p&gt;&lt;pre class=&quot;csharpcode&quot;&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;link&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;rel&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;stylesheet&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;css/tablet.css&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;media&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;only screen and (min-width: 400px) and (max-width: 800px)&quot;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;p&gt;it says that include the “&lt;strong&gt;tablet.css&lt;/strong&gt;” when the user agent has a screen and its width is between 400 to 800 pixels, something that we think should be suitable for a tablet. &lt;/p&gt;&lt;pre class=&quot;csharpcode&quot;&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;link&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;rel&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;stylesheet&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;css/phone.css&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;media&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;only screen and (max-width: 400px)&quot;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;p&gt;On the same lines, in this rule, we ask the browser to use “&lt;strong&gt;phone.css&lt;/strong&gt;” if the width is less than 400 pixels. Note that these rules are mutually exclusive because we want them to be like so. Each rule must evaluate to a boolean value and depending on that value, the CSS file is downloaded to the client machine and is used for rendering the HTML markup.&lt;/p&gt;&lt;p&gt;You can also embed the media-query inline in the CSS as follows:&lt;/p&gt;&lt;pre class=&quot;csharpcode&quot;&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;style&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;text/css&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;       &lt;br /&gt; @media only screen and (max-width: 400px)&lt;br /&gt;  {&lt;br /&gt;   #content&lt;br /&gt;   {&lt;br /&gt;       height:100px;&lt;br /&gt;       background-color:red;&lt;br /&gt;   }&lt;br /&gt;}   &lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;style&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;Orientation&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Similarly the CSS for phone.css can be broken down into two parts: phonePortrait.css and phoneLandscape.css by applying the following media queries&lt;/p&gt;&lt;pre class=&quot;csharpcode&quot;&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;link&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;media&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;only screen and (max-width=400px) and (orientation=portrait)&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;rel&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;stylesheet&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;phonePortrait.css&quot;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;link&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;media&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;only screen and (max-width=400px) and (orientation=landscape)&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;rel&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;stylesheet&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;phoneLandscape.css&quot;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;Width Vs Device-width&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&quot;width&quot; refers to the width of the viewport width (or the browser’s width) whereas the &quot;device-width&quot; refers to the width of the device (for desktop users, it is the dimensions of the monitor used, for mobile users, it is the dimensions of the smartphone used). Common sense says we should use device as the browser size may be less than the dimension of the device (esp on desktop)&lt;/p&gt;&lt;p&gt;The complication comes in case of mobiles, where the likes of iDevices and Androids incorrectly reports the viewport-width and also neglects the orientation of the device while calculating the width. To make things work, Apple introduced a new &lt;a href=&quot;http://developer.apple.com/library/IOs/#documentation/AppleApplications/Reference/SafariWebContent/UsingtheViewport/UsingtheViewport.html&quot;&gt;meta-tag: Viewport&lt;/a&gt; which is usually used as follows:&lt;/p&gt;&lt;pre class=&quot;csharpcode&quot;&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;meta&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;viewport&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;width=device-width, initial-scale=1&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;p&gt;This instructs the device to report the viewport width equal to the actual width of the device and also take orientation into account while making that calculation. More details can be read &lt;a href=&quot;http://developer.apple.com/library/IOs/#documentation/AppleApplications/Reference/SafariWebContent/UsingtheViewport/UsingtheViewport.html&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Browser Support&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Surprisingly, majority of browsers do support media queries but for those who don’t, a &lt;strong&gt;JavaScript workaround&lt;/strong&gt; can be applied which based on the width of the browser, changes the &lt;em&gt;link&lt;/em&gt;’s &lt;em&gt;href&lt;/em&gt; value to point to the correct CSS file.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Spec&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;A lot more can be achieved by media queries, all of which has been laid out in the spec &lt;a href=&quot;http://www.w3.org/TR/css3-mediaqueries/&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Disclaimer&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;The HTML &amp;amp; CSS used above in the example are merely for demonstrating the power of Media Queries and hence have been intentionally kept lame. &lt;/p&gt;</description><link>http://techno-cratic.blogspot.com/2011/11/need-of-media-queries-gone-were-those.html</link><author>noreply@blogger.com (Anonymous)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhz-P6n0L_Gn5JZsbygE4-jQf6vrUovJoqKmPVAexDr1Xu7_Ni5zCzwqbXVFGHcOLuzZMXiqZYZY4frr0BJEBv53QptT4nqdKMnMfZ9_mHM5tK-BJ7WGIoB13jgf_IA6tTd8Y8bxLnU2aI/s72-c/?imgmax=800" height="72" width="72"/><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5223788876950011016.post-4926878917844832634</guid><pubDate>Tue, 15 Nov 2011 18:07:00 +0000</pubDate><atom:updated>2011-11-15T10:07:42.064-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">DU</category><category domain="http://www.blogger.com/atom/ns#">Personal</category><category domain="http://www.blogger.com/atom/ns#">Sun CA</category><title>Remembering the old Sunny Days</title><description>&lt;p&gt;Although my tenure with Sun Microsystems (now Oracle Corp), working as a &lt;a href=&quot;http://techno-cratic.blogspot.com/2008/01/my-sunny-days.html&quot;&gt;Sun Campus Ambassador&lt;/a&gt; was numbered (just 6 months), but I consider that to be an important phase in my life, a beginning of a new journey, something that motivated me to work on open-source technology and learn new and exciting stuff. &lt;/p&gt; &lt;p&gt;The bad, rather the &lt;strong&gt;ugly&lt;/strong&gt; part is that I cannot access my &lt;a href=&quot;http://blogs.sun.com/agraj&quot;&gt;Sun Blog&lt;/a&gt; anymore !! Yes, I have written to &lt;a href=&quot;http://www.oracle.com/index.html&quot;&gt;Oracle&lt;/a&gt; about it, but nothing has happened so far. Still the sole purpose of writing that post was to re-live moments of the past and&amp;nbsp; thanks to &lt;a href=&quot;http://blogs.oracle.com/arungupta/&quot;&gt;Arun Gupta&lt;/a&gt;, I’m re-posting one of my favourite &lt;a href=&quot;http://blogs.oracle.com/roller-ui/bsc/spider.jsp?entry=c1bc2259-3218-455e-a8f4-f93a39a26e6c&quot;&gt;entries&lt;/a&gt; again: A poem for me from one of my favourite professor: &lt;a href=&quot;http://cs.du.ac.in/pkh.htm&quot;&gt;Dr. P.K. Hazra&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;Under the SUN-MICROSYS SunRay&lt;br&gt;Has bloomed a Lovely Rose,&lt;br&gt;Over Joyful in Java &amp;amp; Solaris&lt;br&gt;He is SUN CAMPUS AMBASSADOR Agraj.&lt;br&gt;Only one request I want to make&lt;br&gt;to the SUN&#39;s shining flower,&lt;br&gt;To remain in serene silence&lt;br&gt;During my lecture hour&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Quoted by Dr. P.K Hazra  &lt;p&gt;and As they say,&amp;nbsp; “I’m really gonna miss this place, I’m gonna my college days…”&lt;/p&gt;  </description><link>http://techno-cratic.blogspot.com/2011/11/although-my-tenure-with-sun.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5223788876950011016.post-47250143867176024</guid><pubDate>Sat, 12 Nov 2011 09:51:00 +0000</pubDate><atom:updated>2011-11-12T09:18:01.090-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">jQuery</category><category domain="http://www.blogger.com/atom/ns#">Mobile</category><title>jQuery Mobile: Hello Mobile World</title><description>&lt;p&gt;After more than one year of online-hibernation, I’m more than happy to be back and today would be writing about creating a basic mobile application using &lt;a href=&quot;http://jquerymobile.com/&quot;&gt;jQuery Mobile&lt;/a&gt;.  &lt;/p&gt;&lt;p&gt;&lt;u&gt;&lt;strong&gt;Overview&lt;/strong&gt; &lt;/u&gt; &lt;/p&gt;&lt;p&gt;jQuery Mobile provides a robust framework to develop mobile applications on the fly and is as simple as creating a HTML page and including jQuery mobile specific JS and CSS files. The framework is not only pretty straightforward to use, but also provides a familiar approach for web developers (who are already comfortable with HTML, CSS &amp;amp; Javascript/&lt;a href=&quot;http://jquery.com/&quot;&gt;jQuery&lt;/a&gt;). It also provides 5 predefined themes to choose from and recently &lt;a href=&quot;http://jquerymobile.com/themeroller/&quot;&gt;ThemeRoller&lt;/a&gt; has been launched which can be used to create a custom theme for your app. Fortunately for you guys, I’m not going to rant about how awesome jQuery Mobile is, as all that can be found &lt;a href=&quot;http://jquerymobile.com/&quot;&gt;here&lt;/a&gt;. :-)  &lt;/p&gt;&lt;p&gt;&lt;u&gt;&lt;strong&gt;Getting Started&lt;/strong&gt; &lt;/u&gt; &lt;/p&gt;&lt;p&gt;In this post, we will be creating a basic contacts app which looks like below:  &lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCW52XZhj55rvLQ4o0S4xMxAHcY_EARm82wpigIFF8m7slKiwBpKXFWO_4AuC2AcWVlhLO511ayVTKebLbetC5jOzSRfPAKxZCSeTnaIg-J_rf-v1IF_ixZpexTzxXUKbLVT1hLh7DgI8/s1600-h/homePage%25255B5%25255D.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;homePage&quot; border=&quot;0&quot; alt=&quot;homePage&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_hqQfQtONsyjL3feryOPUQjH8GHkL0nAhKtMI-r5HwGQaf9XY4dXsV7h05AdeKdQYL-ODwCoFxCEvAfJqUVmOHGkR5qx5sHHWSaRax_KzCaFKQUvWrtvBCsQ4bP5qRQG2kp2Zki6jP5U//?imgmax=800&quot; width=&quot;183&quot; height=&quot;244&quot; /&gt;&lt;/a&gt;         &lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYqqJ_ay4ydifC53FbhVc6ggDtk1MLpihR4gCYJRhk0hdGebpJbuYOCESKVxVjqbTVGHdJJlj0q5TYo0XVgzidskXsx8kH99Yr45leoU2FK7evxLOIMdz3lgMa7yTLy1YqFhNS-LfkKbk/s1600-h/allFriendsView%25255B2%25255D.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;allFriendsView&quot; border=&quot;0&quot; alt=&quot;allFriendsView&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAwjUCcWg84GO-rLI0aIHtSUVxbyMDMBYLTlfH2BG8KqP2ULqr-tKRfmLPBSdLnGEOdON16YY8Ej3uP1oqvutfNr6AwAFQSDNoK7Q225KqKDsVWaFjAZYM-9bruImfGIHknk0uJGJyhG4//?imgmax=800&quot; width=&quot;173&quot; height=&quot;244&quot; /&gt;&lt;/a&gt;  &lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKdUYnugd-j7lRrSzcze7YXz5qKWXWpbem01gMymdebGPKMQEWO-D3FBJixFK4OHiyP27nxdkqXFaQ1wp5NpUhYj9ddGzvxIEAC4q_ZaAeMmGIHdL7IDEG2YaqaNoBn61TOZZxKbDORNo/s1600-h/addNewFriend%25255B2%25255D.png&quot;&gt;&lt;img style=&quot;background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px&quot; title=&quot;addNewFriend&quot; border=&quot;0&quot; alt=&quot;addNewFriend&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEibD1HcXcLO8DYVHfdfz2TQwSwp-3dSoTJ7P6KOsa243iW2Tcbqh_P_za3BYyNwwBTkmbm2wEDDThn_2rBK5-LRSyAwEWsup0TrrpsGPJniW9eS1mNl3EZ16eZA6mx-5TByI7nYBQ4ZY78//?imgmax=800&quot; width=&quot;183&quot; height=&quot;244&quot; /&gt;&lt;/a&gt;  &lt;/p&gt;&lt;p&gt;Lets start by creating a basic html file (&lt;strong&gt;index.html&lt;/strong&gt;) for the home page/the first view and add the code below to it: &lt;/p&gt;&lt;pre class=&quot;csharpcode&quot;&gt;&lt;span &gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;!&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;DOCTYPE&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;html&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;html&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;meta&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;charset&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;utf-8&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;My Friends&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;link&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;jquery-mobile/jquery.mobile-1.0a3.min.css&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;rel&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;stylesheet&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;text/css&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;jquery-mobile/jquery-1.5.min.js&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;text/javascript&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &amp;lt;script src=&lt;span class=&quot;str&quot;&gt;&quot;jquery-mobile/jquery.mobile-1.0a3.min.js&quot;&lt;/span&gt; type=&lt;span class=&quot;str&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&amp;gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;link&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;css/styles.css&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;rel&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;stylesheet&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;text/css&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;data-role&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;page&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;page&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;data-role&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;header&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;       &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;h1&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;My Friends&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;h1&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;data-role&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;content&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;   &lt;br /&gt;       &lt;span class=&quot;rem&quot;&gt;&amp;lt;!-- Logo --&amp;gt;&lt;/span&gt;&lt;br /&gt;       &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;logo&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;       &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;ul&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;data-role&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;listview&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;           &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;li&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;allFriends.html&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;data-transition&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;pop&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;All Friends&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;li&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;           &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;li&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;addFriend.html&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;data-transition&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;fade&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;Add Friend&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;li&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;       &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;ul&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;       &lt;br /&gt;   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;data-role&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;footer&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;data-position&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;fixed&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;       &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;h4&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;attr&quot;&gt;&amp;amp;copy;&lt;/span&gt; Copyright 2011&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;h4&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;html&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;p&gt;In the &lt;em&gt;head&lt;/em&gt; section, we have included jQuery mobile specific CSS and JS files. We have also included our custom CSS file: &lt;strong&gt;styles.css&lt;/strong&gt; which is primarily used to position the logo for our application and consists of the following code:&lt;/p&gt;&lt;pre class=&quot;csharpcode&quot;&gt;&lt;span &gt;&lt;span &gt;#page div #logo {&lt;/span&gt;&lt;br /&gt;   width: 300px;&lt;br /&gt;   height: 100px;&lt;br /&gt;   background-image: url(../images/jQueryLogo.jpg);&lt;br /&gt;   background-repeat: no-repeat;&lt;br /&gt;   background-position: center 0px;&lt;br /&gt;   margin-top: 0px;&lt;br /&gt;   margin-right: auto;&lt;br /&gt;   margin-bottom: 0px;&lt;br /&gt;   margin-left: auto;&lt;br /&gt;&lt;span &gt;}&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;p&gt;The &lt;em&gt;body&lt;/em&gt; contains various div’s which form one view/page of the mobile app. The “page” div usually contains “&lt;a href=&quot;http://jquerymobile.com/demos/1.0rc2/docs/toolbars/docs-headers.html&quot;&gt;header&lt;/a&gt;”, “content” and a “&lt;a href=&quot;http://jquerymobile.com/demos/1.0rc2/docs/toolbars/docs-footers.html&quot;&gt;footer&lt;/a&gt;”. These div’s can then contain anything that you want to put inside those sections of the page (following some conventions).&lt;br /&gt;&lt;/p&gt;&lt;p&gt;As the name suggests, header and footer are the blocks at top and bottom of the page and the “content” div is used to lay out the elements to be shown in the rest of page. Here, we show a logo and  list view of 2 elements.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;As you might have noticed we have made extensive use of &lt;a href=&quot;http://dev.w3.org/html5/spec/elements.html#embedding-custom-non-visible-data-with-the-data-attributes&quot;&gt;HTML5 custom data-attributes&lt;/a&gt; (the data-* attributes on HTML tags) throughout our tutorial. jQuery mobile leverages this uber cool feature of HTML5 to add capabilities to its framework. These custom data-attributes (like data-role, data-transition, data-position etc) are defined in jQuery Mobile framework and support predefined values.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Lets create another pages/html files, which we will then link to our main page (index.html). Creating the second view/page (allFriends.html) in which we will show all the friends in our list.&lt;/p&gt;&lt;pre class=&quot;csharpcode&quot;&gt;&lt;span &gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;!&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;DOCTYPE&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;HTML&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;html&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;meta&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;charset&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;utf-8&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;All Friends&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;link&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;jquery-mobile/jquery.mobile-1.0a3.min.css&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;rel&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;stylesheet&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;text/css&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;jquery-mobile/jquery-1.5.min.js&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;text/javascript&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &amp;lt;script src=&lt;span class=&quot;str&quot;&gt;&quot;jquery-mobile/jquery.mobile-1.0a3.min.js&quot;&lt;/span&gt; type=&lt;span class=&quot;str&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&amp;gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;data-role&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;page&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;       &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;data-role&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;header&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;       &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;index.html&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;data-icon&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;home&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt; Home &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;       &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;h1&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt; All Friends&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;h1&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;               &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;index.html&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;data-icon&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;back&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt; Back &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;       &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;  &lt;br /&gt;       &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;data-role&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;content&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;       &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;ul&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;data-role&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;listview&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;           &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;li&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;friendDetails.html&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                       &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;img&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;images/face1.jpg&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                        &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;h3&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt; Andrea &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;h3&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                       &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt; Office Colleague &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                       &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;               &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;li&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;           &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;li&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;friendDetails.html&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                       &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;img&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;images/face2.jpg&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                      &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;h3&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt; Aria &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;h3&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt; Childhood Friend &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                 &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;           &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;li&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;            &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;li&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;friendDetails.html&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;img&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;images/face3.jpg&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;h3&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt; Tom &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;h3&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt; Brother &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                 &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;           &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;li&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;            &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;li&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;friendDetails.html&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;img&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;images/face4.jpg&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;h3&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt; Home &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;h3&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt; Danger &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                 &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;           &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;li&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;            &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;li&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;friendDetails.html&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;img&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;images/face5.jpg&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;h3&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt; Melinda &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;h3&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt; Close Friend &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                 &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;           &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;li&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;           &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;li&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;friendDetails.html&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;img&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;images/face6.jpg&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;h3&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt; Taanya &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;h3&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt; College &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                 &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;           &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;li&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;            &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;li&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;friendDetails.html&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;img&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;images/face7.jpg&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;h3&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt; Micheal &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;h3&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt; Rockstar &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                 &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;           &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;li&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;            &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;li&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;friendDetails.html&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;img&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;images/face8.jpg&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;h3&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt; Maria &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;h3&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt; Friend &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                 &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;           &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;li&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;       &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;ul&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;        &lt;br /&gt;   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;data-role&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;footer&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;data-position&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;fixed&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;       &lt;br /&gt;       &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;data-role&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;navbar&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;           &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;ul&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;               &lt;span class=&quot;rem&quot;&gt;&amp;lt;!-- Add icons here for Delete, Edit, Call Friend --&amp;gt;&lt;/span&gt;&lt;br /&gt;               &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;li&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;#&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;data-icon&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;info&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;data-iconpos&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;top&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;Edit&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;li&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;               &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;li&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;#&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;data-icon&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;delete&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;data-iconpos&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;top&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;Delete&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;li&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;               &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;li&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;#&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;data-icon&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;alert&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;data-iconpos&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;top&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;Call&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;li&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;           &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;ul&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;       &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&amp;lt;!&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;--&lt;/span&gt; /&lt;span class=&quot;attr&quot;&gt;navbar&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&amp;lt;!&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;--&lt;/span&gt; /&lt;span class=&quot;attr&quot;&gt;footer&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;  &lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;   &amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;html&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;p&gt;By writing this small piece of code, we can show the thumbnails in the &lt;em&gt;listview&lt;/em&gt; along with some description of each element. To make things simpler, this is simply some static data hardcoded into HTML. A real-world application would read this data from some persistence store and using jQuery would create this markup dynamically with that data.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;jQuery Mobile also provides a rich set of form elements as can be read &lt;a href=&quot;http://jquerymobile.com/demos/1.0rc2/docs/forms/forms-all.html&quot;&gt;here&lt;/a&gt;. We create a simple form using the html below (&lt;strong&gt;addFriend.html&lt;/strong&gt;) to show some basic form elements to create the third page/view of our app in which we provide a simple form to add a new friends in the existing contacts.&lt;/p&gt;&lt;pre class=&quot;csharpcode&quot;&gt;&lt;span &gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;!&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;DOCTYPE&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;HTML&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;html&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;meta&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;charset&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;utf-8&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;Add Friend&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;link&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;jquery-mobile/jquery.mobile-1.0a3.min.css&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;rel&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;stylesheet&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;text/css&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;jquery-mobile/jquery-1.5.min.js&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;text/javascript&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;lt;script src=&lt;span class=&quot;str&quot;&gt;&quot;jquery-mobile/jquery.mobile-1.0a3.min.js&quot;&lt;/span&gt; type=&lt;span class=&quot;str&quot;&gt;&quot;text/javascript&quot;&lt;/span&gt;&amp;gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;data-role&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;page&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;data-role&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;header&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;       &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;index.html&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;data-icon&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;home&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt; Home &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;       &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;h1&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt; Add Friend &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;h1&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;       &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;index.html&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;data-icon&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;back&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt; Back &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;data-role&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;content&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;       &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;form action=&lt;span &gt;”submit.jsp”&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;post&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;           &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;data-role&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;fieldcontain&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;               &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;label&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;Name: &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;               &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;text&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;name&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;name&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;placeholder&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;Enter Name&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;           &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;           &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;data-role&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;fieldcontain&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;               &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;label&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;gender&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;Gender:&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;               &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;gender&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;gender&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;data-role&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;slider&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;option&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;MALE&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;Male&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;option&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;option&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;FEMALE&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;Female&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;option&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;               &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;           &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;           &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;data-role&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;fieldcontain&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;               &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;label&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;age&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;Age&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;               &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;range&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;age&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;age&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;min&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;0&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;100&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;0&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;br /&gt;           &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt; &lt;br /&gt;           &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;fieldset&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;ui-grid-a&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;               &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;ui-block-a&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;index.html&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;data-role&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;button&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;cancel&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;Cancel&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;               &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;               &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;ui-block-b&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;                   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;button&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;submit&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;data-theme&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;a&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;Submit&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;button&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;               &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;           &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;fieldset&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt; &lt;br /&gt;       &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;form&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;data-role&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;footer&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;data-position&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;fixed&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;       &lt;br /&gt;       &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;h4&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;attr&quot;&gt;&amp;amp;copy;&lt;/span&gt; Copyright 2011&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;h4&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;html&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;p&gt;Again the markup is pretty much similar to a normal HTML page, just we have used certain specific &lt;em&gt;data-roles&lt;/em&gt;, specific &lt;em&gt;classes&lt;/em&gt; which are defined in the framework to layout the elements in a certain fashion and apply a theme to our UI. Since this is just for introducing the framework and not on developing a fully functional app, so the form submission does not work, rather it gives an elegant error message on click of submit button as we have not provided a &lt;em&gt;submit.jsp&lt;/em&gt; page to handle the request. (Done intentionally to show the elegant error handling of the framework)&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Single-page template Vs Multiple-page templates &lt;/strong&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Here we have used one html file per page. We also have an option to keep multiple pages inside one html file. In that case, we need to give id to our pages and link them to each other accordingly using that id. But that can soon explode &amp;amp; become unmanageable, and is only recommended when there is some static data to be shown&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;CSS Layout Magic&lt;/strong&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;We didn’t write much CSS still our HTML pages looks just like a mobile site and the “header”, “footer” and “content” data-roles are layout perfectly nice. It’s so because of the framework’s CSS file (jquery.mobile-1.0a3.min.css) which we have included in our HTML pages. Again proves what amazing things CSS can do :-)  &lt;/p&gt;&lt;p&gt;&lt;strong&gt;Dreamweaver Integration with jQuery Mobile&lt;/strong&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Adobe has done a fantastic job in integrating jQuery Mobile with &lt;a href=&quot;http://www.adobe.com/products/dreamweaver.html&quot;&gt;Dreamweaver&lt;/a&gt; and provides several templates to get you started. The editor also supports some level of code-completion for jQuery Mobile and even some support for Javascript.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Want to learn more ?&lt;/strong&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Even after writing such a long post, its hard to explain each line of code written above so the best way to learn more is to refer to the &lt;a href=&quot;http://jquerymobile.com/demos/1.0rc2/&quot;&gt;Docs&lt;/a&gt;. Or I might just write another post to explain some more.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Disclaimer&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;This is just an introduction to jQuery Mobile and might not follow the best practices like normally you would refer to jQuery framework files from some CDN than to include them with your own code. Also, the above code is static in nature, but it can be easily integrated with any database using some script and can form a fully-fledged application.&lt;/p&gt;&lt;p&gt;As always, comments and corrections are welcomed and appreciated.&lt;/p&gt;</description><link>http://techno-cratic.blogspot.com/2011/11/jquery-mobile-hello-mobile-world.html</link><author>noreply@blogger.com (Anonymous)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_hqQfQtONsyjL3feryOPUQjH8GHkL0nAhKtMI-r5HwGQaf9XY4dXsV7h05AdeKdQYL-ODwCoFxCEvAfJqUVmOHGkR5qx5sHHWSaRax_KzCaFKQUvWrtvBCsQ4bP5qRQG2kp2Zki6jP5U/s72-c/?imgmax=800" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5223788876950011016.post-3806098644175944878</guid><pubDate>Fri, 24 Sep 2010 17:39:00 +0000</pubDate><atom:updated>2010-10-21T09:11:53.782-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Flex 3</category><category domain="http://www.blogger.com/atom/ns#">RSL</category><title>Runtime Shared Library (RSL) – Flex 3</title><description>&lt;p&gt;The best way to reduce the size of your &lt;a href=&quot;http://www.adobe.com/products/flex/?sdid=GXZOA&quot;&gt;Flex&lt;/a&gt; application (or the resultant SWF file)  is to use &lt;strong&gt;Runtime Shared Library&lt;/strong&gt; which uses the concept of dynamic linking.&lt;/p&gt;  &lt;p&gt;Normally a Flex application consists of your application code as well as the framework code and the both of these codes are &lt;strong&gt;statically merged&lt;/strong&gt; together in a single &lt;strong&gt;SWF&lt;/strong&gt; file. It makes the resultant size of your application (the SWF file) larger by adding some 500 KB’s of data to it, which has to be downloaded each time the application is downloaded to a client.&lt;/p&gt;  &lt;p&gt;On the other hand, RSL allows you to &lt;strong&gt;decouple&lt;/strong&gt; your application code with the framework code and allows you to &lt;strong&gt;dynamically link&lt;/strong&gt; both of them as and when needed (while running the application). Without wasting time, lets try  and configure our project to use RSL instead of static linking. It can be done either using command line Compiler Options or by changing certain settings in Flex Builder. We’ll go the easy way:&lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;u&gt;Setup in Flex Builder&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Following Steps are needed to Compile and Build a Project in Flex Builder with RSL in it:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Select your Flex Project. Click on Project –&amp;gt; Properties &lt;/li&gt;    &lt;li&gt;Go to Flex Build Path &lt;/li&gt;    &lt;li&gt;Open Library Path Tab. By default the framework linkage is statically linked --&amp;gt; Merged into Code as shown below: &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg5ige3NsY0zNmcZGsruMA37A23Ma8mTk6ALwCS76sSCnbfnqmHEq7vhHsgdU0HUhBdsVFi4jk7y84WGk7LsiXufLttm6GG45nutsi3BYjXPB0ecobvT0uFHfr19if9LIr8S3sKGhMdxes/s1600-h/clip_image002%5B7%5D.jpg&quot;&gt;&lt;img style=&quot;border-width: 0px; display: inline;&quot; title=&quot;clip_image002&quot; alt=&quot;clip_image002&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMUBOI2ZY5wiimz-0IOavQap_-f_wmn1nghWr3F7tFsC1mlOaDvyF1TYs7BURbO18-xM5ZOY0VYmP7GJz9USaBFRmu0faLCl60onvcmJIZLejELmSeJgaKVBr-V0DVokS9V2hWxZUEUYo//?imgmax=800&quot; width=&quot;420&quot; border=&quot;0&quot; height=&quot;384&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Change the drop down to Runtime Shared Library (RSL) for dynamic binding.&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuBmpcD9geWib9i5LytzfdurkcagoynsP466_hKMHwMibFKmUFuRprvwZFDVCdzwy43rDHLfiYrnk2UqVSr2FwjuN4y7XCP6BFziVp3uYxu1YhLuRh4F2IVgJNRTD12LlXX38PdNF9_-A/s1600-h/clip_image004%5B7%5D.jpg&quot;&gt;&lt;img style=&quot;border-width: 0px; display: inline;&quot; title=&quot;clip_image004&quot; alt=&quot;clip_image004&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPkgdAalJNKM68roGq09LxNTBz0xHma69HUHEW0gMtLIqiIS6K9PdjmYonAv6vfq7wrDIG1ybVAikFrEnBIcrX0wL0sBuIUrC6x1-V2LogVrkelFXQ6WobnGH_qDkP2Vv-ZLIHIHbZmkU//?imgmax=800&quot; width=&quot;416&quot; border=&quot;0&quot; height=&quot;368&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Make sure that Verify RSL digests checkbox is checked. Click Ok to complete the changes and the project will be recompiled with updated compiler settings.&lt;/p&gt;  &lt;p&gt;This will create 2 files for &lt;a href=&quot;http://livedocs.adobe.com/flex/3/html/help.html?content=rsl_01.html&quot;&gt;RSL&lt;/a&gt; in the Output Folder of your project:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;framework_3.X.X.XXX.swf (Unsigned/Failover RSL) &lt;/li&gt;    &lt;li&gt;framework_3.X.X.XXX.swz (Signed RSL) &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;By default, the Flash player will try and use the Signed RSL to link with your application code on loading but the signed RSL works only with &lt;strong&gt;Flash Player 9.0.115&lt;/strong&gt; and later. If your clients are using a lower version, then it will be unable to load the &lt;strong&gt;Signed RSL (swz)&lt;/strong&gt; and will automatically switch over to the &lt;strong&gt;failover RSL (swf)&lt;/strong&gt; and use it in place of Signed RSL.  &lt;/p&gt;  &lt;p&gt;A Major benefit of using Framework RSL is &lt;strong&gt;caching&lt;/strong&gt;. RSLs are cached when they are first used. When they are needed by another application, they can be loaded from the cache rather than across the network. The signed framework RSL (RSL’s can be signed by Adobe only) can be cached in the &lt;strong&gt;Flash Player cache&lt;/strong&gt; as well. This benefits by reducing the initial download time as there is no need to download the framework code every time you need to run your Flex Application. And since the caching is done in the special cache of the Flash Player and not in the browser cache, so this signed RSL can be used for some other Flex Application (served from a different domain than yours) On the other hand, the failover RSL is cached in the &lt;strong&gt;browser’s cache&lt;/strong&gt;. &lt;/p&gt;  &lt;p&gt;&lt;b&gt;&lt;u&gt;Compiler Settings&lt;/u&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;Apart from RSL, while building the project for Production Environment, the debug option must be set to &lt;strong&gt;false&lt;/strong&gt;, else the resultant SWF file will also contain the debug information, which is unnecessary for the production environment. To do so, right click the project, go to Project Properties and open the Flex Compiler View and add&lt;/p&gt;  &lt;p&gt;&lt;b&gt;-debug=false&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;in Additional Compiler Arguments as shown below:&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKyMcaQ3V9WzBLIjuOZa46nVXbR18mv-NaAB79ibKzd-QdViGJ28RbL0ZVt0jCxk3iW5ueVefVb6KAmdmddThUATGjXqFLVzGt_fjVQQH4MXjxzKSurYex67IQiKKOV1kjDt9Cgo9Z5vc/s1600-h/clip_image002%5B8%5D%5B5%5D.jpg&quot;&gt;&lt;img style=&quot;border-width: 0px; display: inline;&quot; title=&quot;clip_image002[8]&quot; alt=&quot;clip_image002[8]&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_vQb6vKhlPDZtqoo7WVJbgFuTv_bgzLO1ZYm5i0adkNBFpJhJiLLwcspzyVN5KNuvNIhH7oPJ5vri5nNn70cuEke5Po_UYdsuYZdr_J5ZDzjts5ZDyS0rFEcVhjcwtY3ZGsCD4h4Wjrw//?imgmax=800&quot; width=&quot;422&quot; border=&quot;0&quot; height=&quot;312&quot; /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Without doing this also, it will work but the resultant SWF file will have debug information with it. The default value of this parameter is true.&lt;/p&gt;  &lt;p&gt;Go Check the output folder of your web application and you will definitely see a reduced SWF file there Happy Flexing :-)&lt;/p&gt;</description><link>http://techno-cratic.blogspot.com/2010/09/runtime-shared-library-rsl-flex-3.html</link><author>noreply@blogger.com (Anonymous)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMUBOI2ZY5wiimz-0IOavQap_-f_wmn1nghWr3F7tFsC1mlOaDvyF1TYs7BURbO18-xM5ZOY0VYmP7GJz9USaBFRmu0faLCl60onvcmJIZLejELmSeJgaKVBr-V0DVokS9V2hWxZUEUYo/s72-c/?imgmax=800" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5223788876950011016.post-7011733214753983068</guid><pubDate>Fri, 20 Aug 2010 18:07:00 +0000</pubDate><atom:updated>2010-08-20T11:17:09.516-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Generics</category><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">Threads</category><title>Thread-safe Generic Class in Java</title><description>&lt;p&gt;Assuming that you are a Java Developer, I can say that you have at some point or the other must have used &lt;strong&gt;Generics&lt;/strong&gt; in your code, be it using a Generic Collection (if you have worked with &lt;strong&gt;Java5+&lt;/strong&gt;) or in any other way. Even if you are not a Java developer, you must have played with &lt;strong&gt;Templates&lt;/strong&gt; (in C++) in your school/college days. &lt;/p&gt;  &lt;p&gt;Today, we are going to do something similar in Java. We are going to create a &lt;strong&gt;Generic Stack&lt;/strong&gt; class in Java, which you can use to create a Stack of Integers, Floating Point Numbers, or a Stack of Students or any custom type that you have. Just to make code a bit more interesting and tough, I have also made it&lt;strong&gt; thread-safe&lt;/strong&gt; so that multiple threads can use this stack without leaving it in an inconsistent state.&lt;/p&gt;  &lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:375910a4-3b99-4810-bb8f-3752bf7db606&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;public class GenericStack&amp;lt;T&amp;gt; {&lt;br /&gt;&lt;br /&gt;private List&amp;lt;T&amp;gt; items;&lt;br /&gt;private int top;&lt;br /&gt;private int size;&lt;br /&gt;private static final int INIT_SIZE = 100;&lt;br /&gt;&lt;br /&gt;public GenericStack(){&lt;br /&gt;    size = INIT_SIZE;&lt;br /&gt;    items = new ArrayList&amp;lt;T&amp;gt;(INIT_SIZE);&lt;br /&gt;    top = -1;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public GenericStack(int size){&lt;br /&gt;    this.size = size;&lt;br /&gt;    items = new ArrayList&amp;lt;T&amp;gt;(size);&lt;br /&gt;    top = -1;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;private boolean isEmpty(){&lt;br /&gt;    return (top==-1);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;private boolean isFull(){&lt;br /&gt;    return (top == size-1);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt; // Push an Item in Stack&lt;br /&gt; public void push(T item){&lt;br /&gt;    synchronized(items){&lt;br /&gt;       // While stack is Full&lt;br /&gt;       while(isFull()){&lt;br /&gt;          try{&lt;br /&gt;             // Wait till Stack is Full&lt;br /&gt;             items.wait();&lt;br /&gt;          }&lt;br /&gt;          catch(InterruptedException e){&lt;br /&gt;            e.printStackTrace();&lt;br /&gt;          }&lt;br /&gt;       }&lt;br /&gt;       // Produce Item&lt;br /&gt;       items.add(++top, item);&lt;br /&gt;       // Notify other threads&lt;br /&gt;       items.notify();&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt; // Pop an item out of stack&lt;br /&gt; public T pop(){&lt;br /&gt;     T item = null;&lt;br /&gt;     synchronized(items){&lt;br /&gt;        // While Stack is Empty&lt;br /&gt;        while(isEmpty()){&lt;br /&gt;           try{&lt;br /&gt;             // Wait if its empty&lt;br /&gt;             items.wait();&lt;br /&gt;           }&lt;br /&gt;           catch(InterruptedException e){&lt;br /&gt;             e.printStackTrace();&lt;br /&gt;           }&lt;br /&gt;        }&lt;br /&gt;        // Consume an item&lt;br /&gt;        item = items.get(top--);&lt;br /&gt;        // Notify other threads&lt;br /&gt;        items.notify();&lt;br /&gt;     }&lt;br /&gt;     return item;&lt;br /&gt;  }&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;Most of the above code is self-explanatory but lets highlight some of the major concepts used here:&lt;ul&gt;  &lt;li&gt;To create a Generic class, one must specify the &lt;strong&gt;Type&lt;/strong&gt; along with the class name (as done using &lt;strong&gt;T&lt;/strong&gt;).  &lt;/li&gt;&lt;li&gt;When you initialize it, all the occurrences of &lt;strong&gt;T&lt;/strong&gt; will be replaced by that particular type. &lt;/li&gt;&lt;li&gt;We have also made the above Stack class &lt;strong&gt;thread-safe&lt;/strong&gt;, i.e. it can be shared and updated by multiple threads in a consistent manner using &lt;strong&gt;synchronized&lt;/strong&gt; blocks. &lt;/li&gt;&lt;li&gt;We have checked before &lt;strong&gt;pushing&lt;/strong&gt; for a &lt;strong&gt;Full Stack&lt;/strong&gt; and we also check for an &lt;strong&gt;Empty Stack&lt;/strong&gt; before &lt;strong&gt;popping&lt;/strong&gt; an element &lt;/li&gt;&lt;li&gt;We have not made the &lt;strong&gt;isFull()&lt;/strong&gt; and &lt;strong&gt;isEmpty()&lt;/strong&gt; methods as synchronized as they are &lt;strong&gt;private&lt;/strong&gt; (hence not visible to clients) and are always called from an synchronized context from within the class. &lt;/li&gt;&lt;li&gt;If you need isFull() and isEmpty() to be &lt;strong&gt;public&lt;/strong&gt; then make them also &lt;strong&gt;synchronized&lt;/strong&gt; to make them thread-safe &lt;/li&gt;&lt;li&gt;It is always better to have synchronized blocks rather than synchronized methods as it is always better to synchronize as less code as possible. Although, here we could not make much use of this concept but rather than obtaining the &lt;strong&gt;lock&lt;/strong&gt; on the calling object, we obtain a lock on the shared list of items. &lt;/li&gt;&lt;li&gt;Calling &lt;strong&gt;synchronized(items)&lt;/strong&gt; means if some other thread has not yet acquired a lock on items (By the way, each Object in Java has an associated Lock with it), then this current thread acquires the associated &lt;strong&gt;lock&lt;/strong&gt; and proceeds. Otherwise if some other thread has currently acquired the synchronized block, then it must wait in the &lt;strong&gt;wait list&lt;/strong&gt; of the object (items) in question. The thread then waits until it receives a &lt;strong&gt;notification&lt;/strong&gt; that the lock has become available for acquisition and then it &lt;strong&gt;competes&lt;/strong&gt; with other &lt;strong&gt;waiting threads&lt;/strong&gt; to acquire the lock. &lt;/li&gt;&lt;li&gt;Calling &lt;strong&gt;items.wait()&lt;/strong&gt; results in the current thread being placed in the wait list of items after releasing the lock. You can only call object.wait() after you have acquired the lock on the object. &lt;/li&gt;&lt;li&gt;Calling &lt;strong&gt;items.notify()&lt;/strong&gt; results in sending the notification to one of the threads in the wait pool of threads which can then compete for the lock. &lt;/li&gt;&lt;li&gt;Note that &lt;strong&gt;items.notify()&lt;/strong&gt; does &lt;strong&gt;NOT&lt;/strong&gt; &lt;strong&gt;releases&lt;/strong&gt; the lock. Only exiting the synchronized block/method releases the lock that was acquired when the thread entered the synchronized block/method. &lt;/li&gt;&lt;/ul&gt;&lt;p&gt;You can easily create two or more threads (viz. Producer and Consumer) and pass them the same Stack and play with them to randomly create and consume data and check that you Stack class is indeed thread-safe.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Generic Methods&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Talking more about generics, you can also make a &lt;strong&gt;method&lt;/strong&gt; accept &lt;strong&gt;Generic parameters&lt;/strong&gt; without the enclosing class declaring the Generic type as done in the following example:&lt;/p&gt;&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:752048ee-87aa-4ab5-9e87-2bc2407c7355&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;public &amp;lt;T&amp;gt; List&amp;lt;T&amp;gt; createArrayList(T t){&lt;br /&gt;  List&amp;lt;T&amp;gt; arr = new ArrayList&amp;lt;T&amp;gt;();&lt;br /&gt;  return arr;&lt;br /&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This &lt;strong&gt;weird&lt;/strong&gt; looking syntax has a meaning:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;This method basically lets you create an arraylist of any type, type is passed to it as an argument.&lt;/li&gt;&lt;li&gt;Since you are not defining the type at Class-level, then there must be a place where you should define the &lt;strong&gt;type&lt;/strong&gt; of your method and &lt;strong&gt;distinguish&lt;/strong&gt; it from other non-generic methods for the compiler. &lt;/li&gt;&lt;li&gt;So, we declare the type&lt;strong&gt; &amp;lt;T&amp;gt;&lt;/strong&gt; immediately after &lt;strong&gt;public&lt;/strong&gt; modifier to say that we use a &lt;strong&gt;Generic Type T&lt;/strong&gt; in this method, which like others will be replaced at runtime with any real type. (just like in case of Generic classes) &lt;/li&gt;&lt;li&gt;We call this method passing to it a valid reference to any Object of any type (Integer, Float, or you own custom class Student). For example, we can do:&lt;/li&gt;&lt;/ul&gt;&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:65e66dfc-3757-49eb-90ba-30643c853218&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;   style=&quot; white-space: normal;  font-family:Georgia, serif;font-size:16px;&quot;&gt;&lt;div id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:da7b8fb9-88dc-4070-ac0c-9c7992ee2188&quot; class=&quot;wlWriterEditableSmartContent&quot; style=&quot;padding-bottom: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px; &quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;Integer i = 23;&lt;br /&gt;List&amp;lt;Integer&amp;gt; intList = createList(i);&lt;/pre&gt;&lt;/div&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;or&lt;/p&gt;&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:da7b8fb9-88dc-4070-ac0c-9c7992ee2188&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:medium;&quot;&gt;Student st = new Student();&lt;br /&gt;// Do anything with st here&lt;br /&gt;List&amp;lt;Student&amp;gt; students = createList(st);&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Ok, I agree this is not one of really useful examples for showcasing the power of a generic method but I hope that the intent is clear and so is the syntax. As always, your valuable comments are welcome and desired. Any corrections must also found place in comments. Sayonara :-)&lt;/p&gt;</description><link>http://techno-cratic.blogspot.com/2010/08/thread-safe-generic-class-in-java.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5223788876950011016.post-1862080923046957640</guid><pubDate>Sun, 15 Aug 2010 08:03:00 +0000</pubDate><atom:updated>2010-08-20T10:36:23.335-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Generics</category><category domain="http://www.blogger.com/atom/ns#">Java</category><title>Mixing Generic &amp;amp; Non-generic code in Java</title><description>&lt;p&gt;Can you spot the error in the following code:&lt;/p&gt;  &lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:0a0e3f43-7abf-492b-8be9-acb32a69164b&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;public class MixingGenerics{&lt;br /&gt;&lt;br /&gt;public static void main(String[] args){&lt;br /&gt;    List&amp;lt;Integer&amp;gt; arr = new ArrayList&amp;lt;Integer&amp;gt;();&lt;br /&gt;    arr.add(&quot;String 1&quot;);&lt;br /&gt;    arr.add(&quot;String 2&quot;);&lt;br /&gt;&lt;br /&gt;   // add something more&lt;br /&gt;   addToList(arr);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public static void addToList(List arr){&lt;br /&gt;   arr.add(new Integer(1));&lt;br /&gt;}&lt;br /&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;I’m sure you are able to point out the mistake that we are adding an &lt;strong&gt;Integer&lt;/strong&gt; to an ArrayList of &lt;strong&gt;Strings&lt;/strong&gt;. That’s definitely not done. But can you tell without compiling this code that we get an error at &lt;strong&gt;compile-time&lt;/strong&gt; or at&lt;strong&gt; run-time&lt;/strong&gt; ?&lt;/p&gt;&lt;p&gt;Unfortunately and even more &lt;strong&gt;surprisingly&lt;/strong&gt;, this code doesn’t give any compilation error or runtime exception. Everything works fine and an Integer is added into your ArrayList (of Strings) !! Yes, you do get a &lt;strong&gt;compiler warning&lt;/strong&gt; that says something about &lt;strong&gt;Type Safety&lt;/strong&gt; of your code. We will get back to this point later on. &lt;/p&gt;&lt;p&gt;But first examine how is possible that you can actually store an Integer in a String Arraylist? Actually, it is an unfortunate outcome of &lt;strong&gt;mixing Generic &amp;amp; Non-generic code&lt;/strong&gt;. The reason why we  get no error is due to a property of Generics called &lt;strong&gt;Type-Erasure&lt;/strong&gt;. We’ll get to it soon but first lets see when the previous code will throw an Error/Exception. This code will explode as soon as you would try and iterate the ArrayList of Strings, in which you have put an Integer unknowingly as shown below:&lt;/p&gt;&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:a07ecee1-29c1-4fc1-88bd-f5a1a0674453&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: medium;&quot;&gt;public class MixingGenerics{&lt;br /&gt;&lt;br /&gt;public static void main(String[] args){&lt;br /&gt;    List&amp;lt;Integer&amp;gt; arr = new ArrayList&amp;lt;Integer&amp;gt;();&lt;br /&gt;    arr.add(&quot;String 1&quot;);&lt;br /&gt;    arr.add(&quot;String 2&quot;);&lt;br /&gt;&lt;br /&gt;   // add something more&lt;br /&gt;   addToList(arr);&lt;br /&gt;&lt;br /&gt;  // print the list&lt;br /&gt;  printMyList(arr);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public static void addToList(List arr){&lt;br /&gt;   arr.add(new Integer(1));&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public static void printMyList(List&amp;lt;String&amp;gt; arr){&lt;br /&gt;   for(String s:arr){&lt;br /&gt;       System.out.println(&quot;String : &quot;+s);&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;So we get a runtime exception now on iterating the list. It prints the first two strings and then throws &lt;strong&gt;ClassCastException&lt;/strong&gt; as we are trying to cast an Integer into a String s. That’s okay but why does it allows you to add an Integer into List of Strings. &lt;/p&gt;&lt;p&gt;&lt;strong&gt;Type-Erasure&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Generic code in Java exhibit a very important property: Type-erasure. What it means is that the so-called type-safe collection of yours (the generic collection here: &lt;strong&gt;ArrayList&amp;lt;String&amp;gt;&lt;/strong&gt;) loses its &lt;strong&gt;type information&lt;/strong&gt; at run-time and acts as if its just a List (like pre-Java 5 lists, the non-generic list). This has been made such so that we can integrate pre-Java 5 (the non-generic code) with newly written Generic code (Java 5 or later), but then while mixing them, you must be careful. Very careful indeed, else you could happen to write a code that will explode unpredictably.&lt;/p&gt;&lt;p&gt;So the &lt;strong&gt;answer&lt;/strong&gt; to our question that why it allows an Integer to a list of Strings is because at runtime we only have a list, just like we had a list in pre-Java 5 days. Without generics, we had to take care while taking object out of the list and casting them but with Java 5 and above code, that casting is implicitly inserted by the compiler. So when we say &lt;/p&gt;&lt;p&gt;String s = arr.get(0) gets converted into String s = (String) arr.get(0) &lt;/p&gt;&lt;p&gt;Doing exactly the same with our list, it gives an error when we try and cast an Integer into a String and hence the error: &lt;span style=&quot;color:#ff0000;&quot;&gt;java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Apart from giving the error, t&lt;span style=&quot;color:#000000;&quot;&gt;he compiler does his best and warns you when you are trying to mix Generic code with Non-Generic Code. &lt;/span&gt;&lt;span style=&quot;color:#000000;&quot;&gt;If you are very sure about your code and do not want any compiler warning, then you can do by using following Annotation (valid with Java5+ code)&lt;/span&gt;&lt;/p&gt;&lt;div style=&quot;padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px&quot; id=&quot;scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:31baa196-ad65-49f3-9a39-62d62f349a52&quot; class=&quot;wlWriterEditableSmartContent&quot;&gt;&lt;pre class=&quot;brush: java;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot;  style=&quot;font-size:large;&quot;&gt;@SuppressWarnings(&quot;unchecked&quot;)&lt;br /&gt;public static void addToList(List arr){&lt;br /&gt;arr.add(new Integer(1));&lt;br /&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This lets the compiler know that you are pretty sure about the code that you have written and do not give me any warnings with this method. Generally, it is not recommended to use such Annotations and if you really need to use one, you must do proper documentation of your code. &lt;/p&gt;&lt;p&gt;Any comments and corrections are welcome :-)&lt;/p&gt;</description><link>http://techno-cratic.blogspot.com/2010/08/mixing-generic-non-generic-code-in-java.html</link><author>noreply@blogger.com (Anonymous)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5223788876950011016.post-954363143802612187</guid><pubDate>Thu, 15 Jul 2010 17:45:00 +0000</pubDate><atom:updated>2010-10-21T09:14:10.574-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Authentication</category><category domain="http://www.blogger.com/atom/ns#">JBoss</category><category domain="http://www.blogger.com/atom/ns#">Web-Apps</category><title>JBoss – Basic &amp;amp; Digest Authentication</title><description>&lt;p&gt;This blog entry is a replication of my previous blog entry: &lt;a href=&quot;http://techno-cratic.blogspot.com/2010/05/tomcat-container-managed-security.html&quot;&gt;Tomcat – Container Managed Security&lt;/a&gt;. It is extending the same entry for JBoss, so I’m gonna skip all the introduction and straight-away get to work.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Basic Authentication&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;1.&lt;/strong&gt; Open the &lt;strong&gt;login-config.xml&lt;/strong&gt; file located at &lt;strong&gt;${JBOSS_HOME}/server/${USER_PROFILE}/conf&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;This file sets up the configuration for the &lt;strong&gt;security domains&lt;/strong&gt; available to applications running in the server. &lt;strong&gt;JBoss&lt;/strong&gt; uses &lt;a href=&quot;http://download.oracle.com/docs/cd/E17476_01/javase/1.4.2/docs/guide/security/jaas/JAASRefGuide.html&quot;&gt;JAAS&lt;/a&gt; for the underlying security infrastructure, and JAAS interacts with a security store for authenticating credentials. &lt;/p&gt;  &lt;p&gt;In simple words, we specify an &lt;strong&gt;application policy&lt;/strong&gt; in this file, which tells the Login Module that we will use (Like Tomcat, here also we have plenty of options like &lt;strong&gt;LDAP&lt;/strong&gt;, &lt;strong&gt;Database&lt;/strong&gt;, &lt;strong&gt;Property Files&lt;/strong&gt; etc for Login Modules). Basically, Login Module specifies the usernames, passwords and roles used for protecting your application. To start with, we will use &lt;strong&gt;UsersRolesLoginModule&lt;/strong&gt;, which uses a &lt;strong&gt;property file&lt;/strong&gt; to specify all the above mentioned information. Obviously, this isn’t secure and not really a choice for a system in production. Time to make changes:&lt;/p&gt;  &lt;p&gt;Make changes in &lt;strong&gt;login-config.xml&lt;/strong&gt; file : Add the following policy at the end of the file:&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghddmSv-PKSx-S-i60YKZtc7OqaNoIpjM2afUMfL-jpD15YfB2SasNeYFNQgE3gTZRhVaTTWqOwpVhaCR3vgADi0yftY3lN8jIkh998OJ2o5D65beC7s15AKoB9awYgV8E3Wzda2WllcE/s1600-h/ApplicationPolicy%5B5%5D.jpg&quot;&gt;&lt;img style=&quot;border-width: 0px; display: inline;&quot; title=&quot;ApplicationPolicy&quot; alt=&quot;ApplicationPolicy&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzq6I8Rt95oMFe41wigEbbGnVGacRXhi95Rzd-CFWLCJzRs6LTSvuiqvCWez4f_FDS6xnkc7gk93_m-DBEnEJmDW1FWQnL6fvgI7qLHAjYbNG16G0LHxDT4y3ZlhEbe1HHEOg-2_23Ezw//?imgmax=800&quot; width=&quot;435&quot; border=&quot;0&quot; height=&quot;284&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;The &quot;&lt;strong&gt;name&lt;/strong&gt;&quot; attribute on the &quot;&lt;strong&gt;application-policy&lt;/strong&gt;&quot; element specifies the name of the &lt;strong&gt;security domain&lt;/strong&gt;.  This name is important because it is what will be used to tie the security domain to the web application later. We will mention it in application’s web.xml.  &lt;/li&gt;    &lt;li&gt;The &quot;&lt;strong&gt;login-module&lt;/strong&gt;&quot; element specifies the login module that this domain will use. &lt;/li&gt;    &lt;li&gt;The &quot;&lt;strong&gt;module-option&lt;/strong&gt;&quot; elements specify some values to pass into the login module&#39;s &quot;initialize&quot; method. For UserRolesLoginModule, we will specify the property files for user information and role information. These paths are relative to the &lt;strong&gt;${JBOSS_HOME}/server/${USER_PROFILE}/conf&lt;/strong&gt; directory.  &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;2. Open the &lt;strong&gt;${jboss.dist}/server/${&lt;/strong&gt;&lt;a href=&quot;http://server.name/&quot;&gt;&lt;strong&gt;server.name&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;}/conf/props&lt;/strong&gt; and &lt;strong&gt;create 2 files&lt;/strong&gt;:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;strong&gt;web-users.properties&lt;/strong&gt;      (user information) &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;web-roles.properties&lt;/strong&gt;       (role information) &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;In web-users.properties property file, add&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6H0MT-Nu_4DQhSg8U19x-lR3XUUYxlDdNk5wnK3GQ3pWsRAIRIORK68IziGRnKXXssr6TE2j8wHcYMDOwKM2Fo8_uLek-z9Men7ADthPAXOuMH8RvUzckQGYVJqJjewn-VDbWjlKQf_8/s1600-h/userNamePassword%5B5%5D.jpg&quot;&gt;&lt;img style=&quot;border-width: 0px; display: inline;&quot; title=&quot;userNamePassword&quot; alt=&quot;userNamePassword&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXRNuR-f8nlKrKWMi48eTOLaQ4Q4BwORKIJX5GMHCbiYanGTq-NHWwRkLE6wWVGEQGQy7XALepzZZ4wuwYk9EgdveVYd2PP2NiO7__zRXkR0d93T14jg11qtttdDFGK-HJwEfKK7ktNp0//?imgmax=800&quot; width=&quot;307&quot; border=&quot;0&quot; height=&quot;77&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;In web-roles.properties, add&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4fF8SjMpv2jlQP9eHu4XwGYi2cO6mfcWH0foiF5t5MoouHgPv6vw1p9aLYjPitTUGvQYy1nq0l_QyoczyybId73GYgKYg27jY7kbj_70XSvUbDu7F1epHI9BGv3aRr5DiLhkVXVsBx1Q/s1600-h/userRoleInfo%5B3%5D.jpg&quot;&gt;&lt;img style=&quot;border-width: 0px; display: inline;&quot; title=&quot;userRoleInfo&quot; alt=&quot;userRoleInfo&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqfdKirK87xcNSM5MOmkJJ74rogCLBLIax2IZDEf-NO6ALsvZAb6iNo9gBpJDxr4lrSO4qLVPi4E4EX-aKr4UPyPglAL1gWSYHZAmdt0PlWn64UanYBTWmZa-HkvBjQ2EpDs33ePfA6rw//?imgmax=800&quot; width=&quot;297&quot; border=&quot;0&quot; height=&quot;72&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;3.&lt;/strong&gt; Open &lt;strong&gt;web.xml&lt;/strong&gt; of your web application and make following changes -- add following &lt;strong&gt;security constraint&lt;/strong&gt;:&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1MD-GwRxvd6H23Cp1SPAM-8ZQc6TybGFA1JPCGW7j9BqZOmLzGqsYwxrXqOw_QpnoWRE1o2DyYMrlA3_oVi7d6sHeWUBgjcNmMrWJTpVaAm42TA5sRiOhNsiRlef0cGKo2eWr_YTQ_2A/s1600-h/securityConstraints%5B5%5D.jpg&quot;&gt;&lt;img style=&quot;border-width: 0px; display: inline;&quot; title=&quot;securityConstraints&quot; alt=&quot;securityConstraints&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzuMYroySvxgX5BrdDwNnSFAUN08jjacS05XA1ZDiqOk3zew9XzPkSSvHqR4DbixrrdWhqqPkw-yYcgjZqG4REi8fj-z31irTHy843QwfX8Xc-aOUEx_j5HuDHJF6WfVQFGZRMtbCVP0A//?imgmax=800&quot; width=&quot;434&quot; border=&quot;0&quot; height=&quot;327&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;4.&lt;/strong&gt; Open &lt;strong&gt;jboss-web.xml&lt;/strong&gt; of your web application and add following line inside the &lt;strong&gt;&amp;lt;jboss-web&amp;gt;&lt;/strong&gt; element:&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgINCI05GwtpWwILJi2tiHi3BlPNK_7qlcsemcQ4xTOokV4JolGmZ8_4v0MPcFG6SC6aKe6o7mSgq39gjhNJWwEtZFWka6xavRW5jCCObh6wKd2tlYBOYDKMVJkQKoPei74W-u_HkNUFas/s1600-h/JAASSettigns%5B4%5D.jpg&quot;&gt;&lt;img style=&quot;border-width: 0px; display: inline;&quot; title=&quot;JAASSettigns&quot; alt=&quot;JAASSettigns&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwGPR5yII5myNNpOLPJulEISJrZ1uXtmbKre4YFTGdaPqu9Boq1kTm2prtgiaT3OYt1hu5VGgjbO5uJpwWK1L7y889KEoPkstYPLBgN0MzqL0kmOtPo9hHkTx-DkxdGuaZ7clzuZDXENk//?imgmax=800&quot; width=&quot;401&quot; border=&quot;0&quot; height=&quot;54&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;This element tells &lt;strong&gt;JBoss&lt;/strong&gt; to connect the web application to the &quot;&lt;strong&gt;webPasswordProtection&lt;/strong&gt;&quot; security domain (application policy) we defined in the &lt;strong&gt;login-config.xml&lt;/strong&gt; file earlier. JBoss exposes security domains via &lt;a href=&quot;http://java.sun.com/products/jndi/&quot;&gt;JNDI&lt;/a&gt; by pre-pending &quot;&lt;strong&gt;java:/jaas/&lt;/strong&gt;&quot; to the name element in the &lt;strong&gt;application-policy&lt;/strong&gt; element in the login-config.xml file.&lt;/p&gt;  &lt;p&gt;Voila!! You are done now. Just restart the JBoss Server and your authentication should work fine. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;DIGEST Authentication&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Having already said that this basic authentication is not recommended for production purposes, we will try using a different authentication mechanism : Digest Passwords. We will save the passwords in a digest (&lt;strong&gt;hashed&lt;/strong&gt;) form in the properties file instead of saving them in clear-text form. Make following changes:&lt;/p&gt;  &lt;p&gt;1. Change in &lt;strong&gt;login-config.xml&lt;/strong&gt; file&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6vCfq2I3mRi1I-qcq4gHJ3G2LjfHuUZWlxAMMI6mth_khsbBtgCUg1xJj5stFWP8JKKOFSRJrQlRRP7a_xI6sE2Uzsf8FvfBNmCyNuu3QmTe_XWO3hynztxPzYiz39D3aVqE_cNz_oog/s1600-h/Digest%5B3%5D.jpg&quot;&gt;&lt;img style=&quot;border-width: 0px; display: inline;&quot; title=&quot;Digest&quot; alt=&quot;Digest&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjoR8c9WYBTHkWbua_t7GQFtSfz0eI5VRCVNLlsBR3ccTUXHc_OB91Ck6jLpXjSu0uIqTKrFK1znyMVuePzqD3udwBxFYlT9pqdXlllmB1R0nEvL_8IMsnGDRyQU1ApUMRfchI96O2QtyE//?imgmax=800&quot; width=&quot;398&quot; border=&quot;0&quot; height=&quot;76&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;2. Find the new &lt;strong&gt;hashed&lt;/strong&gt; password using built-in RFC2617Digest class:&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigzLO2OgpH6p0YixPU0sELMYUz01_1p_W2nDRLlKT3XhTs-SqUIg8QGGUN2lj3m1ZxClu0eu7lMf9vnKyS2t2f92KTO74eAUXp7Tx_gT1A3N4yU0DLnNbielGRHedFuZA0X1msWC-Cffo/s1600-h/digestpassword%5B5%5D.jpg&quot;&gt;&lt;img style=&quot;border-width: 0px; display: inline;&quot; title=&quot;digestpassword&quot; alt=&quot;digestpassword&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiXxMTg-LWQH6rIhyphenhyphennuN6l7d0hyenHhfZGlgt6i7QAmP_96EwKGk86HmkmB8OUCc7RfoL3q9VVzJ5z0N2OOirVS74SSe-NtmCO8ZnhtvIimzOsyKJsyM9KScRwy-b0MA1v_9cecouJ2b8g//?imgmax=800&quot; width=&quot;442&quot; border=&quot;0&quot; height=&quot;105&quot; /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The &lt;strong&gt;RFC2617Digest&lt;/strong&gt; class is present in jbosssx.jar which is present in &lt;strong&gt;${JBOSS_HOME}/server/default/lib&lt;/strong&gt; directory. So this jar file must be on your classpath when you execute the above command. If it is not so, then use &lt;strong&gt;–cp&lt;/strong&gt; option of java tool to set CLASSPATH as done above. The generated password is &lt;strong&gt;b63289befb5c9bb0509eed20b253e985&lt;/strong&gt;. Note that the arguments passed to this class are &lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;User Name &lt;/li&gt;    &lt;li&gt;Realm Name &lt;/li&gt;    &lt;li&gt;Password &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;in that order. Now is the time to store this &lt;strong&gt;hashed password&lt;/strong&gt; in your &lt;strong&gt;web-users.properties&lt;/strong&gt; file.&lt;/p&gt;  &lt;p&gt;3. Change &lt;strong&gt;web-users.properties&lt;/strong&gt; file as follows:&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_5gNyHFzqpqNsW7iatv30HD8tMTp62_CUY2hepSepq82aN7kYMYarfLCoCntx67I-14tUPpP5cOjZ-1Havcg4fRkwPTJVokwU8y0X61Xgw_BcIAfbQjhyphenhyphenvB6Zjq4KzKabo1xG3GEvVPE/s1600-h/digestpass%5B4%5D.jpg&quot;&gt;&lt;img style=&quot;border-width: 0px; display: inline;&quot; title=&quot;digestpass&quot; alt=&quot;digestpass&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiwbTzOwps57qLjick9vT-Ow7BXX0SKn6twib9_PM8Ey_ZkWm4SiXmIY0Z1qqFchkYLgWoZF2z-gzqTZSNYl_6VU0k_7mfgTwjMXkXx1CjlN1SEIDjJQMHuMktd5wPLFJcVmWyueIvCEDM//?imgmax=800&quot; width=&quot;304&quot; border=&quot;0&quot; height=&quot;80&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Now, just restart JBoss to see the effect. And it is more secure than Basic authentication as you are not transmitting the password over the wire.&lt;/p&gt;</description><link>http://techno-cratic.blogspot.com/2010/07/jboss-basic-digest-authentication.html</link><author>noreply@blogger.com (Anonymous)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzq6I8Rt95oMFe41wigEbbGnVGacRXhi95Rzd-CFWLCJzRs6LTSvuiqvCWez4f_FDS6xnkc7gk93_m-DBEnEJmDW1FWQnL6fvgI7qLHAjYbNG16G0LHxDT4y3ZlhEbe1HHEOg-2_23Ezw/s72-c/?imgmax=800" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5223788876950011016.post-7752603950735640660</guid><pubDate>Sun, 27 Jun 2010 18:54:00 +0000</pubDate><atom:updated>2010-07-04T11:55:27.483-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">SSL</category><category domain="http://www.blogger.com/atom/ns#">Tomcat</category><category domain="http://www.blogger.com/atom/ns#">Web-Apps</category><title>SSL Configuration in Tomcat</title><description>&lt;p&gt;Today, we are going to learn about how to setup &lt;strong&gt;SSL&lt;/strong&gt; on your &lt;strong&gt;Tomcat&lt;/strong&gt; so that you can access your application on &lt;strong&gt;HTTPS&lt;/strong&gt; instead of &lt;strong&gt;HTTP&lt;/strong&gt; and provide a &lt;strong&gt;secure interface&lt;/strong&gt; to your clients. But before going into that, lets understand the basic &lt;strong&gt;difference&lt;/strong&gt; between HTTP &amp;amp; HTTPS. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Introduction to HTTPS&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;HTTPS &lt;/strong&gt;&lt;em&gt;(&lt;a href=&quot;http://en.wikipedia.org/wiki/HTTP_Secure&quot;&gt;HyperText Transfer Protocol Secure&lt;/a&gt;)&lt;/em&gt; combines &lt;strong&gt;HTTP&lt;/strong&gt; protocol with &lt;strong&gt;SSL &lt;/strong&gt;&lt;em&gt;(&lt;a href=&quot;http://en.wikipedia.org/wiki/SSL&quot;&gt;Secure Sockets Layer&lt;/a&gt;)&lt;/em&gt; or &lt;strong&gt;TLS &lt;/strong&gt;&lt;em&gt;(&lt;a href=&quot;http://en.wikipedia.org/wiki/Transport_Layer_Security&quot;&gt;Transport Layer Security&lt;/a&gt;)&lt;/em&gt; and offers a secure channel to browse the web so that you can trust the connection to send &lt;strong&gt;sensitive&lt;/strong&gt; &lt;strong&gt;information&lt;/strong&gt; like &lt;em&gt;payment transactions&lt;/em&gt; details or your &lt;em&gt;bank account details&lt;/em&gt;. The difference between the two clearly shows in the address bar where you can see &lt;strong&gt;“&lt;em&gt;https://&lt;/em&gt;”&lt;/strong&gt; instead of &lt;strong&gt;“&lt;em&gt;http://&lt;/em&gt;”&lt;/strong&gt;. Also HTTPS uses port &lt;strong&gt;443&lt;/strong&gt; as the default port, whereas HTTP uses port &lt;strong&gt;80&lt;/strong&gt; as the default port for communication.&lt;/p&gt;  &lt;p&gt;Using HTTPS, the two-way communication that occurs between your web browser and the host server is now &lt;strong&gt;secure&lt;/strong&gt; and &lt;strong&gt;encrypted&lt;/strong&gt;. This means that the data being sent is encrypted by one side, transmitted, then decrypted by the other side before processing. &lt;/p&gt;  &lt;p&gt;When a web browser initially attempts to contact a web server over a secure connection, it is presented with a “&lt;strong&gt;certificate&lt;/strong&gt;” (set of credentials), as a proof of the site is who what it claims to be. These certificates are &lt;strong&gt;signed&lt;/strong&gt; (digitally verified) by certain &lt;strong&gt;authorities&lt;/strong&gt; like VeriSign and typically purchased by the web server. Remember that you need to buy a certificate for each port on which you want a secure connection. For this blog entry, we will sign our own certificate and make other changes to Tomcat configuration so that it starts accepting connection on port 443 using HTTPS protocol. &lt;/p&gt;  &lt;p&gt;But before we begin setting up SSL on Tomcat, its very important to iterate that this is valid only if you are using Tomcat as a &lt;strong&gt;stand-alone web server&lt;/strong&gt;, the other possibility being Microsoft IIS or Apache Server serving as the main interface to the outside world and Tomcat is serving as the &lt;strong&gt;JSP/Servlet Container&lt;/strong&gt; at the backend, communicating with one of these servers. In that case, you have to make SSL configuration changes in IIS or Apache, while Tomcat will continue to work normally sending cleartext responses (no encryption at Tomcat level).&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Creating a Certificate&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Fortunately, Java provides us with a utility (&lt;strong&gt;keytool&lt;/strong&gt;) which can be used to create a self-signed certificate. This is not validated by any authority, hence not suitable for production use. But it can certainly be used for development purposes. So, lets&amp;#160; create a certificate from scratch for our application:&lt;/p&gt;  &lt;p&gt;Type in the following command and enter details(credentials) about your organization that users of your site/application would see in the certificate given to them when they use it. The default password for Tomcat is “changeit” (all in lower-case). It would be asked when you type the following command to generate your self signed certificate:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&amp;gt;&amp;gt; keytool –genkey –alias –tomcat –keyalg RSA&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Note, you must enter the password (as told above) and then all the credentials as shown below:&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgPAWir7FVc4R9zQMh4H8J2izzJSPz2oyREP8vWKBAAXZAVwnjHP8sjW5TK0uZT-2Bcrp3Vg6mn3dUfUU7Cn1lD_1C3At33GqxMUK76u5yMxIlJgs0hlHL7hyJryA_Fb42a-b4a8MmJba0/s1600-h/newCertificate%5B7%5D.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;newCertificate&quot; border=&quot;0&quot; alt=&quot;newCertificate&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhe9qLztZYHElVomgW1PXeBgLY8le3A1ckIuTEDE7LfxbSQ9ablD2hkn9uqIVQNUKP0ndJgX-emG3kK3IQidcn4QUrXpmiow68AhljPf81dR0rCQgoIrbGZ8WEwUQb-S_Wqmlzu1oTOSh4//?imgmax=800&quot; width=&quot;438&quot; height=&quot;333&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;After doing this correctly, a &lt;strong&gt;.keystore&lt;/strong&gt; file will be generated in your home folder (in the home folder of the user who did this). This is the certificate your tomcat would use and present to any user who visit the secure site.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Configuring Tomcat&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Now, we make changes in Tomcat configuration to reflect this change. Tomcat uses 2 different implementations for SSL: &lt;a href=&quot;http://tomcat.apache.org/tomcat-5.5-doc/apr.html&quot;&gt;Apache Portable Runtime&lt;/a&gt; (&lt;strong&gt;APR&lt;/strong&gt;) implementation and JSSE Connector implementation, provided by default with JRE (Java Runtime). Most of the users (like me) do not have APR installed by default, so following steps are valid for JSSE implementation&lt;/p&gt;  &lt;p&gt;We now open server.xml present in &lt;strong&gt;$CATALINA_HOME/conf&lt;/strong&gt;. An example &lt;strong&gt;&amp;lt;Connector&amp;gt;&lt;/strong&gt; element for SSL is included by default in most server.xml that comes with Tomcat. It looks something like this: &lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8ZFEy58hzV5sWrR9wn8-tg3MQk7h0bzHRio4ByfCF2jjUHGCmnD1X4CuL69593zxhYrYSElYX-TaRVWb1GdcHfezEjv05dkymVDMCwscG38MSKqtQyuVwtDe3TirQZfysdC8MrW1I90o/s1600-h/SSLconnector%5B4%5D.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;SSLconnector&quot; border=&quot;0&quot; alt=&quot;SSLconnector&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgeX4HWZ_mkE2Zez9EPWs4JizVuHtVIsUZrn5_J4vE5w9KwHdzcw13vt0kPDWQF0cOXGbanYLWXHBOJDwSW_I5k6saA9jMxn-r5N8tgMT5bsEpSe1ytPoK5rbwUS6VborW2SWE5j567y1g//?imgmax=800&quot; width=&quot;431&quot; height=&quot;150&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;All you have to do is to &lt;strong&gt;uncomment&lt;/strong&gt; this connector and add to it the &lt;strong&gt;location&lt;/strong&gt; of &lt;strong&gt;your certificate (.keystore) &lt;/strong&gt;that we generated and the &lt;strong&gt;password&lt;/strong&gt; we used to generate it. So finally the entry for the connector looks like:&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSCecuEAvbU2GeU6C0IyQ3UWagW0SZwBgAPDiRTSr7SbCjw1_gMYJ1uVuQDjzg4wbS_ByMRSA8edqd4QJzu_wwwNt_kgjuhu3sLi_WcTbodLg3yX2EDKE_Yc24Yy0JgjzbIO0xHxkifAI/s1600-h/NewConnector%5B14%5D.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;NewConnector&quot; border=&quot;0&quot; alt=&quot;NewConnector&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEji8dcXuRtwreeuBVqNfd3QmI0Y_lTtv4f-Nrz9kpEVAosts-aXD4pcb7ARj79yEkIY24xjLu13lyye86DkutlSANoY5dKvyrE9K2uVo9nFgczXli-ckceWY9YBs2v3Q_XjtIY-56V-O20//?imgmax=800&quot; width=&quot;438&quot; height=&quot;219&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Also, make sure that the &lt;strong&gt;Non-SSL Connector&lt;/strong&gt; (the default one) which accepts connection on 8080, should have a &lt;strong&gt;redirectPort&lt;/strong&gt; attribute set to &lt;strong&gt;8443&lt;/strong&gt; or to the port that you specified for SSL Connection in the connector above. The entry looks like:&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjotSZOcIM-uXQVr_FuwBQQdFE6SV6IGBFMqpGxS-pyIT_amvzxA1CvE5NVzaTM8bJtfYhG51O3pQtyWthw2CwArD2-Rc9Gvvz1nJcFb3Bt8fjMy7KPE9-QoRWjp1Xv_-UUCMYDzdWbTbc/s1600-h/NonSSLConnector%5B4%5D.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;NonSSLConnector&quot; border=&quot;0&quot; alt=&quot;NonSSLConnector&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgUnMy52bFTbD_UFflTVXkSVmBsSke0gAr03A5VaSuJTMb2v9HBxNTR_XICbHYr7JcbKwTqO7mTK3HlPOlF-i1b3JRHNktWSmrdCSU3amY3U4OsHc-dyjNbym6BfvEa5r41CX3m0Cs7y98//?imgmax=800&quot; width=&quot;425&quot; height=&quot;166&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;That’s all you need to do to make sure that Tomcat starts accepting secure connections on 8443 and redirects users who attempt to access a secure page with http to https. For more details regarding each attribute of the connector, you can refer &lt;a href=&quot;http://tomcat.apache.org/tomcat-5.5-doc/config/http.html&quot;&gt;Java HTTP Connector&lt;/a&gt; configuration reference.&lt;/p&gt;  &lt;p&gt;Go ahead, try it out and feel the magic that Tomcat provides you. :-) Please post any bugs, queries and corrections as comments. &lt;/p&gt;  </description><link>http://techno-cratic.blogspot.com/2010/06/ssl-configuration-in-tomcat.html</link><author>noreply@blogger.com (Anonymous)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhe9qLztZYHElVomgW1PXeBgLY8le3A1ckIuTEDE7LfxbSQ9ablD2hkn9uqIVQNUKP0ndJgX-emG3kK3IQidcn4QUrXpmiow68AhljPf81dR0rCQgoIrbGZ8WEwUQb-S_Wqmlzu1oTOSh4/s72-c/?imgmax=800" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5223788876950011016.post-4305272554986104494</guid><pubDate>Sat, 29 May 2010 19:07:00 +0000</pubDate><atom:updated>2010-05-29T12:07:38.185-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Tomcat</category><category domain="http://www.blogger.com/atom/ns#">Web-Apps</category><title>Tomcat – Container Managed Security</title><description>&lt;p&gt;If you are a web developer, then I will not think twice before saying that you must have used &lt;strong&gt;Tomcat&lt;/strong&gt; knowingly or unknowingly for deploying your web applications.&lt;/p&gt;  &lt;p&gt;For me, &lt;a href=&quot;http://tomcat.apache.org/&quot;&gt;Tomcat&lt;/a&gt; is a pretty basic web server, which mainly serves as a &lt;strong&gt;JSP/Servlet Container&lt;/strong&gt;. Today, we explore some basic &lt;strong&gt;security&lt;/strong&gt; features that are provided by the container itself. There are different ways in which this &lt;strong&gt;authentication&lt;/strong&gt; can be provided. In this blog entry, we will try to understand and implement &lt;strong&gt;Basic&lt;/strong&gt; &amp;amp; &lt;strong&gt;Form&lt;/strong&gt;-based Authentication using &lt;a href=&quot;http://tomcat.apache.org/tomcat-5.5-doc/realm-howto.html#MemoryRealm&quot;&gt;MemoryRealm&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;What’s a Realm?&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;According to the Tomcat specification, a &lt;strong&gt;Realm&lt;/strong&gt; is a &amp;quot;database&amp;quot; of &lt;em&gt;usernames&lt;/em&gt; and &lt;em&gt;passwords&lt;/em&gt; that identify valid users of a web application (or set of web applications), plus an enumeration of the list of &lt;em&gt;roles&lt;/em&gt; associated with each valid user. Obviously, there are many ways to specify the valid username-password combinations and the associated roles. We will use something known as &lt;strong&gt;MemoryRealm&lt;/strong&gt;, which uses a file: &lt;strong&gt;tomcat-users.xml&lt;/strong&gt; to specify this database.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Steps to Enable Authentication&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Change the configuration file (&lt;strong&gt;server.xml&lt;/strong&gt;) of the Tomcat Server to specify the realm that you will use &lt;/li&gt;    &lt;li&gt;Change the &lt;strong&gt;tomcat-users.xml&lt;/strong&gt; file to list the valid username-passwords and the associated roles &lt;/li&gt;    &lt;li&gt;Change the deployment descriptor (&lt;strong&gt;web.xml&lt;/strong&gt;) for your web application to reflect security constraints needed by the application. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&lt;u&gt;&lt;strong&gt;Step1: Change server.xml of Tomcat&lt;/strong&gt;&lt;/u&gt;&lt;/p&gt;  &lt;p&gt;The default server.xml has the &lt;a href=&quot;http://tomcat.apache.org/tomcat-5.5-doc/realm-howto.html#UserDatabaseRealm&quot;&gt;UserDatabaseRealm&lt;/a&gt; enabled as shown below:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjAh8_ZN9Im-959TeEVKeEQg69Vvt79tUc_mEqOsl-ZcebhHTTZn2B9sKAEpOFH8RkUYyr3XB5fJb7kha9ZGN40Ns9vrk1ZXRuqkIjVb-3ItjLl-hfvHGytE3GydKLppPo_snokklEUl4/s1600-h/serverXml4.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;serverXml&quot; border=&quot;0&quot; alt=&quot;serverXml&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgonjgEb1i4vvl861HvNXpzy-vweEDAg8vU2kIqY4E9pHMzOvvsG7eigTiJHxQlCPyYt3LqXQ_igqvScpUP83DbNZLAHTeKQufWZUf-whSPptxIWfNxtR8DnVLPHRlxOO3Ah3UIe-TeGm8//?imgmax=800&quot; width=&quot;413&quot; height=&quot;100&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Note: This can change depending on the versions of the Tomcat, but for Tomcat 5.5 and Tomcat 6, it is the default one. We change it to use &lt;strong&gt;MemoryRealm&lt;/strong&gt; by commenting the previous line and adding the following declaration as shown below:&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUA5SEPGIa0kawiMFh78f7FxLKrxMt1yVeuxA55NYy-Aves5zpAQbSLNl7xdnyMuwFAA0oI1kIuiAmfYj-adrd1WrPIvAT7gSrgYnFoZfHeQwQ7GkeT2rqHK-F4ohQiu9DFEDLArOB0vw/s1600-h/serverXmlChanged6.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;serverXmlChanged&quot; border=&quot;0&quot; alt=&quot;serverXmlChanged&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjawnFInjqkSJ6Nz8-5cc1WDPSqug7OlPeJd_S6ywJJLmAka_sx5hNHkOXAPncUbxWUHAROZ7Sj6JordTQNHrnFZLrXXyBjFeaXH-a7udMSguMKRq2FfxBoHHN1Tps7nVAY51u6ZYHu-YY//?imgmax=800&quot; width=&quot;434&quot; height=&quot;197&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Step2: Change tomcat-users.xml of Tomcat&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;The default tomcat-users.xml file, which is present at &lt;em&gt;$CATALINA_HOME/conf/tomcat-users.xml&amp;#160; &lt;/em&gt;where &lt;strong&gt;$CATALINA_HOME&lt;/strong&gt; is the directory in which your Tomcat server is installed, looks like:&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgry1hNl-rW5EFjbB3wlOoHxatkspxgpUT10z04VtKK9d2BwPxqD0w9W3OI8HZeD6DltfsPWb8OQl-m8DIv890FWCD8WiSOvqp8n5B1IpN7QAVU5Ue0bUYLfHGEgDuDPDl20yDnucVzTs0/s1600-h/tomcatUsers4.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;tomcatUsers&quot; border=&quot;0&quot; alt=&quot;tomcatUsers&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhh5upDB5BRDDEwbPW_ZZ8liuVKdGvtgxxYjDMKjICYMgnU9N1UoVbwcVQjaqHjAXrUnhLSRjwkmMJ5awB_RuyeGy8m0qbj49x6EtfkGpdccZZQDJt7gpxfXHdKAa0MY_vZncTyKCxQwqc//?imgmax=800&quot; width=&quot;432&quot; height=&quot;133&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;To this, add your own role and associate with it, some valid combination of username and password as done below:&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8rM4wRJq5qaRZd4l2JzAcypChDs2cj_7AxrcGodXIHCQMCBEtzCVMfMB5IF6-PE4gk4Jq1ydGtRqcE75ReLJJQlkJnzr8udp5aXwKB9m89A6MQWYvU5hqy9cmP1jzmBlOnkc9MCSZkn4/s1600-h/tomcatUsersChanged5.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;tomcatUsersChanged&quot; border=&quot;0&quot; alt=&quot;tomcatUsersChanged&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIY0rY94_lNv9_LttAmXyk4bwhEJu4JDUDcFqO56faT4yPY3VzIj_z7iEfiwSm0E33fIeTZN9tGg0zKilVR6II4tamHD80h3Jhx2t4WeE0gG6aCIKz_i2d57r2088KbxI-9maBpyM8I1o//?imgmax=800&quot; width=&quot;443&quot; height=&quot;170&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Step3: Change web.xml of your web application&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;So far, we have made changes in the Tomcat server itself, its time we must modify our application to reflect the security constraints that we want. To do so, we add the following to our web.xml file:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;a) Security Constraints as per the need&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhX0HQWQ5sSTGodaiyI5UKD7qj8x4Xd3wNPOOhFV7AnVonZ6yJMlIKnzyJyNZEEZtKldX3EstbVkedan3Fm2-p08b9Lfpfg7ZHzhyphenhyphenqqpah4erBPVWfJEJOKvqD0xtDSTjyvtq2_2dpZvA4/s1600-h/securityConstraint4.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;securityConstraint&quot; border=&quot;0&quot; alt=&quot;securityConstraint&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzdLNRjoj6_0gyaymdCQ_-yMa_8JXjN49ClaMN9yy5k9V29TOGVc8xbRXshCz5E-viqAECtSNxvwP1fbImhETI8PxslldoKmTou7efxVO4pELUUAb4wRNXceAgaoZV3cDdDTUiigWCpt8//?imgmax=800&quot; width=&quot;422&quot; height=&quot;248&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Here, We specify that in order to access any URL in our application which comes after &lt;a href=&quot;http://{context_App}/jsp/&quot;&gt;http://{context_App}/jsp/&lt;/a&gt;…&amp;#160; should be password-protected. Also, we associate a role with it, so users associated with that role can only access these URLs now.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;b) Declaring the Security Role&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhkQOE8qVx3FCCjiWnu-Brmf7vMiYELJYbCCX4VSFhQhhsIfKgzCSyrsaQnhF97CEGGTttYL6psOYf0VBerZKJOr0K8qQ5WmDT4OAXCVW71UK_U3NsZzKQAyAI-mXMSTOp_GItGy5_7Ocg/s1600-h/securityRole3.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;securityRole&quot; border=&quot;0&quot; alt=&quot;securityRole&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiR19xtgXXruXncigtIIK_ZI2X-1yoaTpV8hB7UssJ6_8ZagSXZkmM3Ao48M7y6CflsY-DihMbMhKQdiXojQTGVcplDVh41_igmdMMjP9XF4NV_khNIscNvb3IQqCiVaD33FTz7C-DDUPs//?imgmax=800&quot; width=&quot;381&quot; height=&quot;106&quot; /&gt;&lt;/a&gt; &lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;c) Specifying the Type of Authentication &lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9nKqJU4GHks5L5gQzK4RsG3ek5keZ0vhLZfPYbcSDrbmS_AbvRUi5OACAgXK_w3EFWZC-wbxwva8pUpgIrrVB3SkGtA8UVGrsr_LBeC9NepIqUL8Zb2v3ZNXIkzY7HJHivckPWVZi9dc/s1600-h/basicAuthntication5.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;basicAuthntication&quot; border=&quot;0&quot; alt=&quot;basicAuthntication&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuFuWJvLPNZaWzGVLmLwrDgAsy__qHo6sYQYRxn5SyHw1MgKdHhEFKHvkZKhBA0eUQlu4ytfow1f-Zq54ZsCn7mRPXdedlPNkT6JhzIU30Orexzt9JF4qJJk2_O2A-KH7VvinXAUbAfFY//?imgmax=800&quot; width=&quot;396&quot; height=&quot;140&quot; /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;We tell Tomcat that we want to use BASIC authentication for our web application and the realm that we will use will use your tomcat-users.xml file.&amp;#160; &lt;/p&gt;  &lt;p&gt;That’s it. All you need to do now, is to &lt;strong&gt;restart&lt;/strong&gt; &lt;strong&gt;Tomcat&lt;/strong&gt; and check whether this works or not. Obviously you need to create a basic web application to deploy onto the Tomcat , for which you have specified the security constraints. You can download my test web application here. (Provide a Link)…………………&lt;/p&gt;  &lt;p&gt;This was pretty basic stuff, but it has several &lt;strong&gt;limitations&lt;/strong&gt;. For one, this is not suitable for production environments and we must use FORM-based authentication instead of BASIC. Secondly, it is not a good practice to use clear-text passwords in tomcat-users.xml file. We can save the encrypted password (encrypted by any algorithm like SHA, MD2, MD5 etc) supported by the realm.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Changes to overcome limitations&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;1. Use Digested Passwords&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Obviously, storing passwords in clear-text readable format in tomcat-users.xml cannot be considered &lt;strong&gt;safe&lt;/strong&gt; or practical. In a production environment, it is essential to use some &lt;strong&gt;encryption&lt;/strong&gt; to provide security. Tomcat provides us with several digest algorithms (&lt;strong&gt;SHA&lt;/strong&gt;, &lt;strong&gt;MD2&lt;/strong&gt;, &lt;strong&gt;MD5&lt;/strong&gt; etc) supported by &lt;a href=&quot;http://java.sun.com/j2se/1.4.2/docs/api/java/security/MessageDigest.html&quot;&gt;MessageDigest&lt;/a&gt; class. To enable it, change the realm declaration in server.xml of Tomcat to the following:&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7G2jk2ZKL-NOiPRKJeklkBL4duPi3QMHAi_bLaSyXsINg_JuN3fk5RJnOMTV_9uIj-Pg4aAtb8wtXN4M-KxR8hMm0FZhrC3Ipmi2NgcXXM0AoJeGMVxSLFi1gjx08y5k_8qZX38VIras/s1600-h/memoryRealmMD54.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;memoryRealmMD5&quot; border=&quot;0&quot; alt=&quot;memoryRealmMD5&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjaacyAQpp2ixy6WzCFulUF2CVx2vyWGRJigxdmMBGv1A1GgRQyYZwtjBqXiyY10LKiGzbdOBFN8RzrqiJMlzTJ5I0JhWDVknDdWBIWwUtA-WlBHQ3he2CZcIaJaU8bfBbkL0V0WmTiXQo//?imgmax=800&quot; width=&quot;432&quot; height=&quot;85&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Also, change the password you specified in tomcat-users.xml to the encrypted version of the original password, by using &lt;a href=&quot;http://tomcat.apache.org/tomcat-5.5-doc/catalina/docs/api/org/apache/catalina/realm/RealmBase.html&quot;&gt;RealmBase&lt;/a&gt; class. You can find this class in &lt;strong&gt;catalina.jar&lt;/strong&gt; in $CATALINA_HOME/lib directory. Use it as follows: &lt;strong&gt;RealmBase.digest(“password”, “MD5”, null)&lt;/strong&gt; . Now, restart your Tomcat and test your authentication.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;2. Use FORM-based Authentication&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Since using &lt;strong&gt;BASIC&lt;/strong&gt; authentication, you have very little control over the authentication/login method used by Tomcat and it is not considered practical for &lt;strong&gt;production&lt;/strong&gt; environment. So we demonstrate another way: FORM-based authentication. The whole setup remains same, only you can provide your own custom login and error pages (with your company logo and whatever you want) instead of just popping up a window (as done by Tomcat in BASIC mode)&lt;/p&gt;  &lt;p&gt;We will change the &lt;strong&gt;&amp;lt;login-config&amp;gt;&lt;/strong&gt; element declared in your application’s &lt;strong&gt;web.xml&lt;/strong&gt; as follows:&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijqkKAsWhb42Xj0UCV3i99fCedLhVDwxSbdOT1uqnSG4eRP4wyOm6gH5Dv-MPcwr-jArGFQw-mc2TIo0RHmPEW0r_v6riFzSai9ivn6B25oZJW24tTwJcLXNBQFTGoXuAJK4mPqjeRAyM/s1600-h/form-login-config%5B5%5D.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;form-login-config&quot; border=&quot;0&quot; alt=&quot;form-login-config&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjz7xhjxTDoI6XsFOZ0DOXp_AA1u4syX8llhjT_2GTsoVcBbLR6_5654tHeNdFP3AA3g03l6sWKd0HLwxWRdmHbCMu7gUuOMss53aQQySTB8fr_pwZMhCn8TyXFYOpi1QI8RMGiNALE7o0//?imgmax=800&quot; width=&quot;414&quot; height=&quot;161&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;We will now add &lt;strong&gt;login.jsp&lt;/strong&gt; and &lt;strong&gt;error.jsp&lt;/strong&gt; to our application. login.jsp is used to authenticate the user: hence it would provide a form while error.jsp is the page to which user is redirected in case of an error: invalid username-password. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;login.jsp &lt;/strong&gt;will have at least a login field with name as “&lt;strong&gt;j_username&lt;/strong&gt;” and password field with name as “&lt;strong&gt;j_password&lt;/strong&gt;”. This must be same so that tomcat can identify the password and login fields in the form. Also the action of the form must be “&lt;strong&gt;j_security_check&lt;/strong&gt;”. You can find the link to download the whole project at the end. My authentication page looks like this, which I believe is much better and safer than basic mode.&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAt-6KRubBVWdTrAQWYUHQMxwUYEizmW0FHyzmmYJ5WESPBbZe-_X-7c5y7DoGrcciPy3uk8lDUGxnDkOnzplhWgUGr436FMEf85fthULZ8Io_iG_Gr_jMAlKf7BDB4nhoWpi5TdeU8xs/s1600-h/authenticate%5B4%5D.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto&quot; title=&quot;authenticate&quot; border=&quot;0&quot; alt=&quot;authenticate&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEirJe9eMnccBSWR1OzYrS0V23GVggjupcubMtrhebKrmeEPs6rjFdRkWpbBayjEnCnDPzcjIWnYJ164hrPFrHTnpQvW65qAhJfyRqohrpImwTpGZGq1_ARwLkJy6ONIWx-XVv0zay1obeo//?imgmax=800&quot; width=&quot;276&quot; height=&quot;206&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Still, we have one &lt;strong&gt;limitation&lt;/strong&gt;:&lt;/p&gt;  &lt;p&gt;Any changes made to the file: &lt;strong&gt;tomcat-users.xml&lt;/strong&gt; will be reflected only when the &lt;strong&gt;Tomcat&lt;/strong&gt; server is &lt;strong&gt;restarted&lt;/strong&gt;. So, if you add a new username-password combination to it, you must restart Tomcat in order to have its effect. We can also overcome this limitation by specifying the username-password and roles in a database table and using a &lt;a href=&quot;http://tomcat.apache.org/tomcat-5.5-doc/realm-howto.html#JDBCRealm&quot;&gt;&lt;strong&gt;JDBCRealm&lt;/strong&gt;&lt;/a&gt; instead of &lt;strong&gt;MemoryRealm. &lt;/strong&gt;You can download entire project from &lt;a href=&quot;http://techno-cratic-blog.googlegroups.com/web/TomcatSecurity.zip&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;  </description><link>http://techno-cratic.blogspot.com/2010/05/tomcat-container-managed-security.html</link><author>noreply@blogger.com (Anonymous)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgonjgEb1i4vvl861HvNXpzy-vweEDAg8vU2kIqY4E9pHMzOvvsG7eigTiJHxQlCPyYt3LqXQ_igqvScpUP83DbNZLAHTeKQufWZUf-whSPptxIWfNxtR8DnVLPHRlxOO3Ah3UIe-TeGm8/s72-c/?imgmax=800" height="72" width="72"/><thr:total>3</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5223788876950011016.post-4203408403313785201</guid><pubDate>Sun, 23 May 2010 10:08:00 +0000</pubDate><atom:updated>2010-05-23T03:08:13.974-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Flex 3</category><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">RPC</category><title>Flex Remoting with Java Part 2</title><description>&lt;p&gt;In the &lt;a href=&quot;http://techno-cratic.blogspot.com/2010/04/flex-remoting-with-java.html&quot;&gt;last blog entry&lt;/a&gt;, I wrote about setting up a simple &lt;a href=&quot;http://www.adobe.com/products/flex/overview/&quot;&gt;Flex&lt;/a&gt; Application and integrating it with Java so as to be able to make Remote Calls to Java Methods and display the result in Flex.&lt;/p&gt;  &lt;p&gt;Today, we are going to make those efforts valuable by seeing how a &lt;strong&gt;user-defined object&lt;/strong&gt; can be passed between Java &amp;amp; Flex. We will create a Employee List in Java and show it in a &lt;a href=&quot;http://livedocs.adobe.com/flex/3/html/help.html?content=dpcontrols_6.html&quot;&gt;DataGrid&lt;/a&gt; in Flex. As Simple as that. To start with, you must have all the environment setup as explained &lt;a href=&quot;http://techno-cratic.blogspot.com/2010/04/flex-remoting-with-java.html&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;&lt;u&gt;&lt;strong&gt;RPC with User Defined Objects&lt;/strong&gt; &lt;/u&gt;&lt;/p&gt;  &lt;p&gt;To be able to do so, we must create classes in both &lt;strong&gt;ActionScript&lt;/strong&gt; and &lt;strong&gt;Java&lt;/strong&gt; and &lt;strong&gt;bind them together&lt;/strong&gt; as shown below:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Employee.java&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCnI4QYeUiUyAzQ-5n_zmuSi2lc8gncKZ2dGcCRlfXi6ED_mXtYoOu2E2163tbaQUPtxtuhp5uTlbpx8ZLECqbaIUwO85J_AA73bxnphtj_zxXaGYpCVb0vuVOD6-kvvQ48dTGKT-EcDQ/s1600-h/EmployeeJava%5B5%5D.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;EmployeeJava&quot; border=&quot;0&quot; alt=&quot;EmployeeJava&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZLXLVeFFJpq-KIMwOgZIeDxLzF37YVD7C5etRGemnnBtBx16iF8hI-YQJej0VJXLNOyEBnXS5yjfsJJp2z2AQPbuV0zjpT1TLtBRFNOK2TZ9QTWOCKO7BsL5H1WfduE13id2LKcEkwAQ//?imgmax=800&quot; width=&quot;390&quot; height=&quot;377&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Employee.as&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4kmTB8SSmRoaREBBGvJOddyKPVQDJOjitZ8AaDzrpInit5BisbnlOdaZaVKBbRkR5-nVQc1qZ6MwI5nt92h-0oSigKbI26y2NiYupY0wqR_lho1O8b_Ye6Q39jT_MgUTkLbTuyl90joQ/s1600-h/EmployeeAS%5B3%5D.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;EmployeeAS&quot; border=&quot;0&quot; alt=&quot;EmployeeAS&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMO9J2XQkCEXbWq-WVbWaX6bpZjw-6N_1l338FsHxO0wp5UUZJ_bRdGh3EQ_ZKgoKgJDrlX3Bt3w-sShZOuWnfI-fMyOlUV9CiOijbLKoZ6g1mZHxmzf9SYUMbjM8jwfIaSKvEK8MFWT0//?imgmax=800&quot; width=&quot;372&quot; height=&quot;227&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;The Java and the ActionScript file have the same attributes and they map to each other using Flex Metadata: &lt;strong&gt;RemoteClass(alias=””) &lt;/strong&gt;which maps the java object returned from server to ActionScript object which can be displayed. This &lt;strong&gt;metadata tag&lt;/strong&gt; used in ActionScript Class (Employee.as) specifies the fully qualified name of the corresponding Java Class. We now create a Utility class for getting Employee details:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;EmployeeUtils.java&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiPeoJWuNV5xSd1sS9mGIN2j7vJH1D71LFlwVZ59vlVojVbi0mdTnuOsqrpO0udmR7qP8H2qpyP4ZT-UMEPBhv5v6TlW1J4WXHPn0OceQMcTpdDNcl5SuL8cjZmMdWrrwktRZl61iYzXRM/s1600-h/EmployeeUtils%5B7%5D.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;EmployeeUtils&quot; border=&quot;0&quot; alt=&quot;EmployeeUtils&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmTWGbG3vf4Fy_6Xs17ncRxdElw_CZBHYotswrR8yU3Kb4_eNDv9CiP30NLQryPbMTTPcENR-ffTT7CE3FBUf2ggtZ320UZYGLWt92OR-lnrAtUye7bWITp3lI5xkHpH4M5cW0ji-eCe4//?imgmax=800&quot; width=&quot;426&quot; height=&quot;474&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Here, we have hard-coded the Employees Data, but it is as easy to get these employees from a database by firing a query. We now make a RPC call from Flex to get this list so that we can display it in a DataGrid.&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgEbvQEB7jsZPSWr3j_fwFEonSTyRYxjzzv0-ayvKeahYSjQPDHNSfrXoNYzJ0-YIPMcfblGYjktr5H-ZtXbWDwdcAN-GJ_flzRdUv9nfkn5V0WX34cXkogEk4ynkL8CtRFvGSyo6IH6GA/s1600-h/getAllEmployees%5B12%5D.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;getAllEmployees&quot; border=&quot;0&quot; alt=&quot;getAllEmployees&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJrAspOkY7PEx-bXXeLnz6JUiYxljOuaShEW1UI6i3AGb5IwTKlbbmop-rLzZ6fN4o2LMiMNGjEl4MfYmMp2JgN5Kwu1cJOqj6gpfTVfdghi51qfQTM7opwRkt2jfF_sVsPBtnDMSIuPk//?imgmax=800&quot; width=&quot;431&quot; height=&quot;419&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;We create a &lt;a href=&quot;http://livedocs.adobe.com/flex/3/langref/mx/rpc/remoting/mxml/RemoteObject.html&quot;&gt;RemoteObject&lt;/a&gt; in Flex and specify a destination “&lt;strong&gt;employee&lt;/strong&gt;” which is present in a &lt;strong&gt;remoting-config.xml&lt;/strong&gt; to specify the Java Class file to look for methods called (&lt;strong&gt;getAllEmployees&lt;/strong&gt;) using this RemoteObject. Part of flex-config.xml which specifies this looks like:&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxej1wHwV5lc0hcTPcDHhyhkAvLTK5inWCFCkZ_nfhVnhByaflht9GW7VPVrBpq3oNT99gcSdtNEBwO7r1DZsCkS1FZJ9PyrIcdgcSxB0UcURVtAUc32Pk6alWxIRsgnTGeaRfj5Mhebs/s1600-h/remotingConfig%5B4%5D.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;remotingConfig&quot; border=&quot;0&quot; alt=&quot;remotingConfig&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjd8iG6JUJOvdAWfrZH0zS4Ru8zU657RoFtFlHrw5z4cVjsvzLAaYQ7Ww2X3Fi6gPwog0vCbKXpjOEs06NrLxKqW6Vfw7d23rPv9KcmWPp7dERMFr5OFlZHejcRn9suHxB5cqIq06aGKdA//?imgmax=800&quot; width=&quot;387&quot; height=&quot;91&quot; /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;We specify the &lt;strong&gt;result and fault handlers&lt;/strong&gt; with the remote object, which are called when result or fault occurs. In the result handler function, we save the result in a &lt;strong&gt;ArrayCollection&lt;/strong&gt;, which we &lt;strong&gt;bind with our DataGrid&lt;/strong&gt; as shown below:&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgU5da-7RX9cyOuBR9A2nfDJfeRg8DjVj8X8gie9b_DxJOinOjmSaE3khpR4KjbIA9oEFAwQ_R8Yb4ED0BXgo5lyQuqiSNyVdBPWxTUsb9YTn_dFzl0hs29DIQu0IOPlPB7MpCbnZsjyus/s1600-h/employeeDatagrid%5B6%5D.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;employeeDatagrid&quot; border=&quot;0&quot; alt=&quot;employeeDatagrid&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgemQj5k26DTLaidwPPc238Jy3S36xlJIwxUGlpWhtJKfA3s_OSfRwQC_I7QYJ5D3uXiUVaaxKIm4og2bMhB3QV3HRklRK2OmBIjitktqMmfdD-l0Sb8A01Nw40WBxQQDcBQrjilAMwmE//?imgmax=800&quot; width=&quot;426&quot; height=&quot;303&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;We set the &lt;strong&gt;dataProvider&lt;/strong&gt; property of our &lt;strong&gt;DataGrid&lt;/strong&gt; component to &lt;strong&gt;__employeeList&lt;/strong&gt;, which is a bindable ArrayCollection which contains the result data. The advantage of making the ArrayCollection as &lt;strong&gt;bindable&lt;/strong&gt; is that any changes made to this ArrayCllection (due to any event) is reflected in our DataGrid automatically.&lt;/p&gt;  &lt;p&gt;When we run this example, we get a DataGrid as shown below:&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhc9tjythvzWgaOGzUVd0uF0EOXYB05SY4TU8VvRauL6NyLEpBNmqugsQd9R872YvKPOUL8snVuOxFuWu4jpBjqSqYTPIFYnPyYFGljvpusTSHNh4AT1Y1nwcuv_9o8mpM0apQZ584Amp8/s1600-h/output%5B6%5D.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;output&quot; border=&quot;0&quot; alt=&quot;output&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-VgLbbqXL7e_6DR17GJeaC1639mWfBaJ4LJFQnt-oYkzr88_i35TEEjLYOgreXKzxBSQpBfYWB621UYPdrEGNZPQjtDSjSF1Msuty0mx7wFs6MIP89t4LH3m8BbVeYut70NiNDufIEKY//?imgmax=800&quot; width=&quot;425&quot; height=&quot;272&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Again this is &lt;strong&gt;not&lt;/strong&gt; a best-way to code your flex application. The intent was to show how user-defined objects can be passed between Java &amp;amp; Flex. In practice and in large scale application, we would use tested frameworks like &lt;a href=&quot;http://www.adobe.com/devnet/flex/articles/cairngorm_pt1.html&quot;&gt;&lt;strong&gt;Cairngorm&lt;/strong&gt;&lt;/a&gt; or &lt;a href=&quot;http://puremvc.org/&quot;&gt;&lt;strong&gt;PureMVC&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Wishing you very Happy Coding with Flex :-) &lt;/p&gt;  </description><link>http://techno-cratic.blogspot.com/2010/05/flex-remoting-with-java-part-2.html</link><author>noreply@blogger.com (Anonymous)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZLXLVeFFJpq-KIMwOgZIeDxLzF37YVD7C5etRGemnnBtBx16iF8hI-YQJej0VJXLNOyEBnXS5yjfsJJp2z2AQPbuV0zjpT1TLtBRFNOK2TZ9QTWOCKO7BsL5H1WfduE13id2LKcEkwAQ/s72-c/?imgmax=800" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5223788876950011016.post-7013278407881681103</guid><pubDate>Wed, 28 Apr 2010 16:17:00 +0000</pubDate><atom:updated>2010-05-03T07:47:00.721-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Flex 3</category><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">RPC</category><title>Flex Remoting with Java</title><description>&lt;p&gt;&lt;a href=&quot;http://www.adobe.com/products/flex/?promoid=AINA&quot;&gt;&lt;strong&gt;Flex&lt;/strong&gt;&lt;/a&gt; is one of those technologies that has taken the &lt;strong&gt;RIA &lt;/strong&gt;(rich internet applications) world by storm and surprise. It has never been so easy to create interactive user interfaces before. Flex offers various ways to interact with languages like Java, PHP and Coldfusion:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;RPC Services&lt;/strong&gt; which enables Flex applications to make &lt;strong&gt;asynchronous&lt;/strong&gt; calls to remote services following a call and response model. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Data Management Services&lt;/strong&gt; provides data synchronization and &lt;strong&gt;real-time updates&lt;/strong&gt;, on-demand data paging and many other data integration features to Flex Applications. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Message Services&lt;/strong&gt; that provides Flex with a &lt;strong&gt;publish-subscribe mechanism&lt;/strong&gt; to create rich and collaborative real-time applications &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;All these capabilities are provided as a part of &lt;a href=&quot;http://www.adobe.com/ap/products/livecycle/dataservices/&quot;&gt;Adobe’s LiveCycle Data Services Pack&lt;/a&gt;. But unlike the Flex SDK, the entire LiveCycle Data Services Pack is not free and open Source. Rather, Adobe has open sourced a part of it, basically the RPC services and Message Services known as &lt;a href=&quot;http://opensource.adobe.com/wiki/display/blazeds/BlazeDS/&quot;&gt;BlazeDS&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;Using the &lt;strong&gt;RPC Services&lt;/strong&gt;, one can &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Call and invoke remote Java Methods directly and bind the result to a Flex component. (using &lt;strong&gt;RemoteObject&lt;/strong&gt; Component ). It follows a &lt;strong&gt;request and response model&lt;/strong&gt; making asynchronous calls to the backend.  &lt;/li&gt;    &lt;li&gt;Invoke an already deployed &lt;strong&gt;SOAP-based Web Service&lt;/strong&gt; over HTTP using &lt;strong&gt;WebService&lt;/strong&gt; Component. &lt;/li&gt;    &lt;li&gt;Send and receive data using &lt;strong&gt;HTTP GET and POST&lt;/strong&gt; using &lt;strong&gt;HTTPService&lt;/strong&gt; Component. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Today, we are going to make use of &lt;strong&gt;RemoteObject&lt;/strong&gt; to invoke Java Methods and show the result in Flex. For this purpose, we are going to use &lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;a href=&quot;http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+3&quot;&gt;Flex 3 SDK&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href=&quot;http://alist.adobe.co.uk/products/flex/&quot;&gt;Flex Builder 3&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href=&quot;http://opensource.adobe.com/wiki/display/blazeds/Downloads&quot;&gt;BlazeDS&lt;/a&gt; for making &lt;strong&gt;asynchronous&lt;/strong&gt; calls to Java &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Open Flex Builder. Create a new &lt;strong&gt;Java&lt;/strong&gt; Project. Name it ‘&lt;strong&gt;testFlexRPC’&lt;/strong&gt;. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Project Structure&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Structure of a typical flex application that we will use looks like:&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzOkaE_KxFBt1VYpu5vc6U1cwtfs1kPw5O45Qp0Agxajb53zB-5Y1gs_5qomlAoOBhf9PEnN1xo-ByfjAW-Vl6t0BdXK2hKKwEz3rrgWEPNOhHtDvdNgkfaaGOI4ZOY8Ju1seIlcj0BLg/s1600-h/projectStructure2.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;projectStructure&quot; border=&quot;0&quot; alt=&quot;projectStructure&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgxqZiA0RF9eSI-_iX52-gp9Fr9IUlTqxzZi5ggxTH20KiE960JbjVijJ2Nr1th65RFy4vnvO3X4kcnde-EmOdiWtjN5Wl5kKEX4ZviG4rjYRMRBdICQyp5VO74V7JewYdYs1_XYI7xG-Q//?imgmax=800&quot; width=&quot;184&quot; height=&quot;210&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;‘&lt;strong&gt;web’&lt;/strong&gt; is our output folder. We will deploy it as a WAR file later on. The output folder contains the &lt;strong&gt;WEB-INF&lt;/strong&gt; folder, in which we will add the deployment descriptor ‘&lt;strong&gt;web.xml&lt;/strong&gt;’ file and other folders such as classes. (the path web/WEB-INF/classes should be your default output folder in Java Build Path, which will store the class files). Make two other folders, flex and lib which will contain the flex files for remoting purposes (&lt;strong&gt;remoting-config.xml&lt;/strong&gt; and &lt;strong&gt;services-config.xml&lt;/strong&gt;) and the libraries needed for Flex Remoting (typically the &lt;a href=&quot;http://opensource.adobe.com/wiki/display/blazeds/Downloads&quot;&gt;BlazeDS JARs&lt;/a&gt; for messaging).&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Deployment Descriptor&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Lets add the deployment descriptor (&lt;strong&gt;web.xml&lt;/strong&gt;) to the project. It will typically contain an entry for the &lt;strong&gt;MessageBroker&lt;/strong&gt; Servlet (which is used by the flex framework for RPC communication) and specify the location of &lt;strong&gt;services-config.xml&lt;/strong&gt;, which is used to define the kind of RPC services to be used. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;web.xml&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhutaMjglHQE27CbBTPsWkD0_KK-ShkrZ5owG7oxT4HpjoCZC4wqeesWQdjpML3isl1kk_j8AVvJlMfJM3_aSRcBhYAykeg1nh6Rie1MMBnbb_zadx_4h3pyQrIW_8ql-0uzBmg6uypt60/s1600-h/deploymentDescriptor6.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;deploymentDescriptor&quot; border=&quot;0&quot; alt=&quot;deploymentDescriptor&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEij-vxAtPGDObt4b8gSb4sU7P580HAhvABehewZbQmrTMSmy-dTD3Ne7RMZMnZ4T0DwCRCqdL9ujTxsHYso8GruERUWRw9oRTmJ_ZjB_BMm2f3WduRLLf05ADm1JBpf292rZaLoNzYNSTM//?imgmax=800&quot; width=&quot;426&quot; height=&quot;355&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Services-Config.xml&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Line 14 of web.xml specifies the location of services-config.xml in your project. It is the &lt;strong&gt;top-level configuration file&lt;/strong&gt; that contains &lt;strong&gt;security-constraint definitions&lt;/strong&gt;, &lt;strong&gt;channel definitions&lt;/strong&gt;, &lt;strong&gt;logging settings&lt;/strong&gt; that each of the services can use. Create an empty XML file on that location and add the following to it:&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEialfFrtOu-sR-0ik75UW0HY7t_PUSE8hqNL2zzWDXIWsiISJxF8QlAnReC2y-Ld557hmDJ-DN3GengSLKSxnK_DQbprvp80wgDen93Q59imoEaHY465J5jD5vhl7FGTWy1dHrgLSe8eWw/s1600-h/servicesConfig16.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;servicesConfig1&quot; border=&quot;0&quot; alt=&quot;servicesConfig1&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhH-0Wdh50gndMQSBET3oaugSXx5267UnfDcFHhJYB4JTaZvrJimx2STJqkqNDtd5-Hssezd6P5RDNF7UWMyBa3YysPIKIEdcut9smO11KWtT35bPwkjrCXocpaZtbb7dv6VilZmAKL7rg//?imgmax=800&quot; width=&quot;430&quot; height=&quot;372&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Firstly, it defines the kind of RPC services that we will use in this project. It includes another file: &lt;strong&gt;remoting-config.xml&lt;/strong&gt; which will contain the destinations for RPC Calls. &lt;/p&gt;  &lt;p&gt;Next, it defines the channels that are actually used by the flex application to transfer data between client and server. It defines two channels: &lt;strong&gt;HTTP channel&lt;/strong&gt; and &lt;strong&gt;AMF Channel &lt;/strong&gt;(AMF stands for Actionscript Messaging Format). These channels are used in remoting-config.xml as we will see in a moment. These channels are a key element of the &lt;strong&gt;destinations&lt;/strong&gt; that are specified and perform all work needed for the asynchronous communication that is required by the application.&lt;/p&gt;  &lt;p&gt;The other part of this file: services-config.xml specifies the logging information and looks like:&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh9RFhSmNnO2EQZGC6WI31P0Ig77Oy5q88uWPO3XcGZo63IUGT1cwbCODoPhge6WXLtNxrB4qolaD8YQ_Z3jN0Zngi2E5N_uUqsQnOFUPuzVT3JEY2fKgtGum6sJgpRJ4ZqPZ9awmqaBF4/s1600-h/servicesConfig27.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;servicesConfig2&quot; border=&quot;0&quot; alt=&quot;servicesConfig2&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpShTy5oFppN3842M0b-aHSsQOhIzPNBsbjtSzhcco39BJK0IhlIruN36-rbbXhzVVEQgzcFrvqE60SAh5gk3k9GxlSnUSiRjlPQjA1D2yKqNhy886xwBbOkH39SRkp2Ev1yhlXDj_RKw//?imgmax=800&quot; width=&quot;447&quot; height=&quot;362&quot; /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Remoting-Config.xml&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Lets create another XML file, which will list the destinations that we will make use of, for making asynchronous calls to remote Java methods from Flex. &lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOWJlag1pvpoDSjCqP4RxkoIky-fla35B3r7a5K_zo6sRX7MFDP1KNJSEyKKby-GDVfeZ-B3KukhTKP9LrmfihEjBPrnxHjt39bQoWP_FGQrV6keqggp4b_2oTW5CnQvBJPikNeroIQ9Q/s1600-h/remotingConfig6.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;remotingConfig&quot; border=&quot;0&quot; alt=&quot;remotingConfig&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtdQrdLCzHJNav-x0nQj7eC0sAs_nkylCPE7_gU47Mz88cnDCGAUj9ob6sbYcKmtXtXxqSj9nAT6kgZyTEMiqipddND2CCZ8eUJOXpSzJvKN32CZ8kcnmQTAiaOSsAmeFAA_p0u8RKAEg//?imgmax=800&quot; width=&quot;430&quot; height=&quot;366&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;It specifies the &lt;strong&gt;channels&lt;/strong&gt; (HTTP and AMF that we configured in services-config.xml) that these destinations will use to communicate between client and server. This file also lists the &lt;strong&gt;adapter&lt;/strong&gt; (server-side code) that interacts directly with the object or the service.&lt;/p&gt;  &lt;p&gt;Next, it defines the &lt;strong&gt;destinations&lt;/strong&gt; that can be used with &lt;strong&gt;&amp;lt;mx:RemoteObject&amp;gt;&lt;/strong&gt;, &lt;strong&gt;&amp;lt;mx:WebService&amp;gt;&lt;/strong&gt; and &lt;strong&gt;&amp;lt;mx:WebService&amp;gt;&lt;/strong&gt; tags in MXML or its equivalent in Actionscript code.&lt;/p&gt;  &lt;p&gt;Here, we define a destination (&lt;strong&gt;sayHelloToMe&lt;/strong&gt;) and bind it with the Java Class &lt;strong&gt;SayHello.java&lt;/strong&gt; present in java.myPackage package. &lt;/p&gt;  &lt;p&gt;Now, add the following &lt;strong&gt;libraries&lt;/strong&gt; in your project. You can find them in the &lt;strong&gt;BlazeDS&lt;/strong&gt; zipped file that you downloaded at the start. &lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhRGn0rTQdMNl45KZsemgpnMLPWN_dLfV8y99SYTwA1RK12vTp81p2QRZt3YRtKXKlsrb_BbLu9X593Ov5nb29xNL-8N2FqNwDm_hDXDCSeK24jg0k4IDyMKvsP8ip-7XrH_88M1rRG-y0/s1600-h/libraries2.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;libraries&quot; border=&quot;0&quot; alt=&quot;libraries&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMyfCfOQPgDmxYCggLvOcR56XdadhmwWiLo8vkW4ArOYeYPmxaUx_3rwEi-bB2AADtqlrqNkQSxmzI8RLeo_0nNwk9O783afiLPoOzItrpTaXy8kRwV4uTVqd5SPHDliEZyMfShyphenhyphenPMfaU//?imgmax=800&quot; width=&quot;233&quot; height=&quot;182&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Now, right click on the project node and go to Flex Project Nature –&amp;gt; Add Flex Project Nature&lt;/p&gt;  &lt;p&gt;A popup would appear asking for &lt;strong&gt;Flex Project Settings&lt;/strong&gt;. Choose the default settings: application server type to &lt;strong&gt;J2EE&lt;/strong&gt; and check the box Using remote object access service. Click Next to configure J2EE server for your application &lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiWZmFfiYLi2dxu9PgSZUhkQr2FVCJRlovGSq49J8N6woVty1uJWDdBh-E5davt-7xBU1DpeTbBBvRftUN6lugIJ3A4XsJipb_A8XYZnArKmC7srI-gynoJqcd8vmUxfkWpJvjBa2tv99A/s1600-h/flexProjectNature3.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;flexProjectNature&quot; border=&quot;0&quot; alt=&quot;flexProjectNature&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijVebgRAplrTZKp13cNJsxprJhrx5GGw496jYFibPifFSAZfqAGSZR87QLE183UTNz7lsK8SDG7PRaaf_C4GtklbrFhJrBqmDP_M48SQGciNmzxtwfX152ozzEIO2e7ffzjCDnCMeMt2o//?imgmax=800&quot; width=&quot;331&quot; height=&quot;343&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;Enter your application deployment settings like your application server’s port number and the context root that you want for this application. Also specify the output folder, where you want the resulting SWF file (and the html wrapper) to be stored. Click Finish to successfully add the Flex Project Nature to your Java application.&lt;/p&gt;  &lt;p&gt;It will automatically create a &lt;strong&gt;default MXML application file&lt;/strong&gt; with the same name as the project to the source folder (configurable in Flex Build Path). We move this mxml file to flex folder that we created under &lt;strong&gt;src/flex&lt;/strong&gt; folder (not necessarily needed, but we have a thing for being organized :-) ). Though for this, we also have to change the Flex Build Path. So, right click on the project node, go to properties. Click on Flex Build Path tab and set the following settings:&lt;/p&gt;  &lt;p&gt;Click Add Folder and add “src”. Also change the &lt;strong&gt;main source folder from “src” to “src/flex”&lt;/strong&gt;. Click Ok to update the compiler settings. You still need to set the testFlexRPC.mxml as the default mxml application. so, right click Project node, go to Properties, Go to tab Flex Application. click on Flex folder and click add. Now add the &lt;strong&gt;testFlexRPC.mxml&lt;/strong&gt; file and click set on default button to make it &lt;strong&gt;default application file&lt;/strong&gt;. &lt;/p&gt;  &lt;p&gt;If you check out, the project must be giving you a compile-time error since we have not created any &lt;strong&gt;html file (wrapper) &lt;/strong&gt;to embed the SWF file which contains the compiled flex application. So right click on the error and click ‘Re-create HTML Templates’ to create the default html wrapper which can be used as is.&lt;/p&gt;  &lt;p&gt;Now, your application is ready to be deployed (technically), but since we have not added any display element and made use of Flex Remoting (the long and tiring process that we have done so far), so there is no use of deploying it currently.&lt;/p&gt;  &lt;p&gt;Now, comes the easy part. Click the &lt;strong&gt;src/java&lt;/strong&gt; and add a new package: &lt;strong&gt;mypackage&lt;/strong&gt; and create a new Java File: &lt;strong&gt;SayHello.java&lt;/strong&gt; ( as specified in remoting-config.xml ) It looks like the following:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;SayHello.java&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjK1gt0mzUDgK-H5ATURGtsr_FV7GChlyh2niEILgr809Zjh3H4d_8SREYxyEQW4InnKiGZb7V2a8j-Q2vm7_hxiN4ak3U7_UvPN44TAWU_XZN7pvv6r3ulVMbJYwyjD6JbKGt-wuJXjTo/s1600-h/SayHelloToMe5.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;SayHelloToMe&quot; border=&quot;0&quot; alt=&quot;SayHelloToMe&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1m1gWVrl4OcEk-2aghl0NMS5nwNLgBNnOV9rVWb5laqNjusmqF2E5y9YjY_1uhILSZVq5x-VfzTddmNJMsS-rQtS2c0rb-M82ZGg7ifKtuF-aJ9gLHHvzE0IArCpCjoUnm7letrX_Kpw//?imgmax=800&quot; width=&quot;410&quot; height=&quot;233&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Now, this is a very simple example (because I think you already have had enough !!) and this is not something for which you have to go to Java from Flex. But it is enough to show you how things can be done and results calculated in Java can be passed to Flex (whether its a primitive or any other object: String or any user-defined object as well)&lt;/p&gt;  &lt;p&gt;Now, we will call this java Method in Flex. Add the following code in testFlexRPC.mxml file, already created.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;testFlexRPC.mxml&lt;/u&gt;&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgE6ApyevY2sTaWm5VpmZCFjIB_aZVD45qLVth52fOu_jo-jDheKsHrFTpe4oklxNsrZtHXQL204eWooQvDGzVTBDkTS1P-66O7UC-0uhCYeUHxx_0FGcPJ7beRDAc6NL7ML7CQ4Ohpv1c/s1600-h/ApplicationMXML6.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;ApplicationMXML&quot; border=&quot;0&quot; alt=&quot;ApplicationMXML&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPfno5VZbPJVUuGJ80PZur6nPcJD_Nb8zyFfWEx_mjwkAHHCW7Y_jbrIbUJE_OKs55KlIqkjmZQA2T7ieizFHTj_Gx2RcTO2DnwPGeDa-h5pFjpynHGWVcvwZZdgMNprAJWcYBVUSbLyI//?imgmax=800&quot; width=&quot;415&quot; height=&quot;311&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Again, this is not a best-practice way to code, but since I’m running out of space and you are running out of patience, so I’m doing things quickly :-)&lt;/p&gt;  &lt;p&gt;Finally, we are ready for deployment and I’m using &lt;strong&gt;Tomcat&lt;/strong&gt; to deploy my web application. To accomplish this, we create the following XML file specifying the context.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;flexRPCJava.xml&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhWYiR0wsJEUJeBdZZq9p2ovUOnb26lM6ScwUnAdJ5rpScN2dJeEiWs1gJvafcJ0t9XrHkfsTACL1z56YuEK7NQeil7faNe6NXmiZSXTuMvZnzobaX54HY7ZEdEwPkNe-0EJnCBWO0RJ-o/s1600-h/flexRPCJavaXML6.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;flexRPCJavaXML&quot; border=&quot;0&quot; alt=&quot;flexRPCJavaXML&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyEiGEl44FHUnJFE30_ULOWwRUNJDalZeG5iZw691opym8VQG54gYvRNMOO83KPIfr0dxoVj3C2nS0J4hY7BP8MnPG5_hXnvSLfQdrdAIVOxxZX-13ROSZ7R1uOhhGWgYaTJdZQ35chxk//?imgmax=800&quot; width=&quot;318&quot; height=&quot;86&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;To learn more on how to deploy Web Applications on Tomcat, please read my previous &lt;a href=&quot;http://techno-cratic.blogspot.com/2009/11/deploying-web-apps-on-tomcat.html&quot;&gt;blog entry about the same&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Now, all you need to do is to start Tomcat and check whether your application is working correctly or not by checking the HTML wrapper that Flex Builder created for you:&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7EshghNzv-i2p91GF41uf8iTopghzjrq7aQH4-7RFa3cFOF8_lOcpE2N0sawdEGnhf9j_SKhpfWs3Pm3mzOjAMRx_MscrvPEXMV2Q0preG8-yCGL4y3hTiAPvTJV7fnINRY6p_svrbi4/s1600-h/output4.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;output&quot; border=&quot;0&quot; alt=&quot;output&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhq8rTaDhrguWIlGzFIlh7xCoW-v45VQ5A0z30a33HXQnXVirs7casHCcG90yfrLbNNqPdbY8yXGm_uq3ub3GQ4hyphenhyphenaB8tv3HFFdMUh1we0D7ih9t3fx-Xm0PYJHMHRiNhbUp3_K4Wr6aMg//?imgmax=800&quot; width=&quot;337&quot; height=&quot;227&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;I hope you are with me till now and would be &lt;strong&gt;happy&lt;/strong&gt; to know that this (perhaps the longest blog I ever wrote) has finished and you have successfully learned how to use Flex with Java.&lt;/p&gt;  &lt;p&gt;I could have taught the same in a very concise manner using the &lt;a href=&quot;http://opensource.adobe.com/wiki/display/blazeds/Release+Builds&quot;&gt;&lt;strong&gt;BlazeDS Turnkey Server&lt;/strong&gt;&lt;/a&gt; and pre-configured examples, but that would have defeated the purpose of structuring and creating a web-application from scratch. Hope you had fun. Cheers !!&lt;/p&gt;  &lt;p&gt;Any suggestions, corrections or Comments are welcome and wanted :-)&lt;/p&gt;</description><link>http://techno-cratic.blogspot.com/2010/04/flex-remoting-with-java.html</link><author>noreply@blogger.com (Anonymous)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgxqZiA0RF9eSI-_iX52-gp9Fr9IUlTqxzZi5ggxTH20KiE960JbjVijJ2Nr1th65RFy4vnvO3X4kcnde-EmOdiWtjN5Wl5kKEX4ZviG4rjYRMRBdICQyp5VO74V7JewYdYs1_XYI7xG-Q/s72-c/?imgmax=800" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5223788876950011016.post-1837435412468013551</guid><pubDate>Wed, 24 Mar 2010 07:42:00 +0000</pubDate><atom:updated>2010-10-21T09:17:06.613-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Double-checked Locking</category><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">Singleton</category><category domain="http://www.blogger.com/atom/ns#">Threads</category><title>Singletons, Threads &amp;amp; Double Checked Locking</title><description>&lt;p&gt;This blog entry extends on the &lt;a href=&quot;http://techno-cratic.blogspot.com/2009/07/singleton-class-in-java.html&quot;&gt;first entry&lt;/a&gt; I wrote about &lt;strong&gt;Singletons. &lt;/strong&gt;Today I try to explain the usage of Singletons in a &lt;strong&gt;multi-threaded&lt;/strong&gt; environment.&lt;/p&gt;  &lt;p&gt;A typical Singleton would look like the following:&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVUBgp3xEBnZYVbP5nwM0D46Bvxe5xi0ynwmISqO2gUjeUx4tMbRuwBAuhQeGeAW2S8VYSGg2ggy3oTSbp4wIB5bU9UK83QVHnL-UdFs6wYQLn8x-EqQxQGSULQfYlOWF2wwyvXa7ydhk/s1600-h/MySingletonJava3.jpg&quot;&gt;&lt;img style=&quot;border-width: 0px; display: inline;&quot; title=&quot;MySingletonJava&quot; alt=&quot;MySingletonJava&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmgUODg2XSNPljJ-9fc4PSWSAfVYzdVoTCZ4Tmxu3-bS3eM1Per4CU_eSgZCZF-Zup6ie1MrwlhvK7UyXceVMlVSa2y9lV1c_0-NKNYreKF0O6_pOUlLqVNsN-BaKqR3BZbC6ab7lAh7g//?imgmax=800&quot; width=&quot;426&quot; border=&quot;0&quot; height=&quot;261&quot; /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;This Singleton class would work perfectly fine in a single-threaded environment. But, &lt;strong&gt;how many Java based applications that you have worked on, are single-threaded? None, perhaps. &lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Can you see what’s terribly wrong with it when your application has multiple threads running simultaneously ??&lt;/p&gt;  &lt;p&gt;Well, the answer lies in the way the instance is lazy initialized. The &lt;strong&gt;null-checking&lt;/strong&gt; and &lt;strong&gt;initializing the instance&lt;/strong&gt; need to be an &lt;strong&gt;atomic operation&lt;/strong&gt;. Lets see what would happen if following sequence of events happen:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;Thead A&lt;/strong&gt; calls &lt;strong&gt;getInstance()&lt;/strong&gt; for the first time. And checks whether instance is null or not. It finds it true and goes to execute line 11. &lt;/li&gt;    &lt;li&gt;At this point, it is pre-empted by another thread: &lt;strong&gt;Thread B&lt;/strong&gt;, which also calls &lt;strong&gt;getInstance()&lt;/strong&gt;, checks for the instance null check, since it is not yet initialized, the private constructor is called and instance is now initialized with a state. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Thread A&lt;/strong&gt; resumes control back and starts from where it left i.e line 11. Now the real problem occurs. Since it checked for the null-check on line 10 when it last run and found it to be true, so when it resumes execution, it will execute from line 11 and again initialize the instance and hence two objects would be created and the whole point of having a single object is violated. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Thus, we really need to do something about the situation. No problems, &lt;strong&gt;Synchronization&lt;/strong&gt; comes to the rescue. Most of us (naive programmers) would tend to get rid of this problem by writing code like below:&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigPGFgJE7z5ExcqYFg-E0flbSVpqMyv4yi5MIauVwsltVGBm70KOivKjCEYQSwOnKqSVghCvK7QY2__C_GmOLtJNA5zS4CoNh36b7fVq0wrErh4-9uBuvA8B_UcR42d0niFvx65VCxCb0/s1600-h/MySynchronizedSingletonJava5.jpg&quot;&gt;&lt;img style=&quot;border-width: 0px; display: inline;&quot; title=&quot;MySynchronizedSingletonJava&quot; alt=&quot;MySynchronizedSingletonJava&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLL19BPgLSmnnP1CwkkTCQLPIuIZLxO8a9xIh6EJUEajVrhV-lrugKhtoXPZ4e0bicTNRz2kaIGp6Gbb32pN45EBgypg8FU9g660pgCXMU1EN_hRoQrcTalsiiT4gg7I7p3_I7hP0mrWU//?imgmax=800&quot; width=&quot;436&quot; border=&quot;0&quot; height=&quot;308&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;The only change that occurs here is that we have made our static factory as synchronized method, which makes sure that no possible combination of &lt;strong&gt;interleaving of threads&lt;/strong&gt; could create two objects like it did in the previous case. Although, this works fine but on close inspection, we find that synchronization is necessary only for the first time, and not needed later on (since instance will always be non-null later on) And &lt;strong&gt;synchronizing the whole method&lt;/strong&gt; is thus uncalled for and &lt;strong&gt;pretty expensive&lt;/strong&gt;. We must think of  other ways of accomplishing this.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;1. Do Not Lazy Initialize&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;If we &lt;strong&gt;do NOT need&lt;/strong&gt; lazy initialization of the resource, then a perfect method to do away with synchronization would be:&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8P2ODho_vPZU2i0bfFfc2Q3EcoD4zRgm_MBAVFurnWVWD2cDfA_Pqdm0QLzUqstREko1f5k3fGVjz0Fx1BGtlwjlQxEgZuKJj7RfutunnZahjzRMJemzzbD7ZpDCelwI9xEbnIivhqm0/s1600-h/Singleton1Java4.jpg&quot;&gt;&lt;img style=&quot;border-width: 0px; display: inline;&quot; title=&quot;Singleton1Java&quot; alt=&quot;Singleton1Java&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqnnbxIH07YmgVj9tJS4QjnTty2KmQBuhp2sZP3c1oXzHPCsGCkQPMIc_-UInHcOxA5HzD5BpHDzd38CDs0iDq_DaCa4Qs72o_QHGR2c-ojRl3NGqhggljsZfRT5auAgIgcT_MCzYopNg//?imgmax=800&quot; width=&quot;427&quot; border=&quot;0&quot; height=&quot;245&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Using this, we depend on the &lt;strong&gt;JVM’s capability to execute the static block as soon as the class is loaded first&lt;/strong&gt; (when it is accessed or referred in code). &lt;/p&gt;  &lt;p&gt;Thus, the VM makes sure that the instance is well initialized, before any thread tries to call &lt;strong&gt;getInstance()&lt;/strong&gt; method. And since static blocks are executed only once, so no chance of creating more objects. One scenario that I could fail this approach is when this class is loaded again (perhaps by a different &lt;strong&gt;classloader&lt;/strong&gt; in a different namespace)&lt;/p&gt;  &lt;p&gt;Another way to write the above code would be:&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiAdA1Gs5Ahuds1RAjlazI-INdeetvygaaoIcUBYqCrX6KxEgW_MgeAlzx0ZKntoD-ef6oj03u3xatDKxXhxEuUtcOO1ysaaj-l-AAHxmW2M02uD8dEr2RAhc80cXVxMu9HoApCD5D7E3g/s1600-h/Singleton2Java13.jpg&quot;&gt;&lt;img style=&quot;border-width: 0px; display: inline;&quot; title=&quot;Singleton2Java&quot; alt=&quot;Singleton2Java&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFz2SMx0Gkd8VVMlBtv12MIhwpPxwU_9VVFYOuyAP1w5L2w-NnW1VCoc1HJ2MlW9UgW9Z7fWwln8PIQ5V1rWB8mxvPEG3dakMAWPNDmoDrhI1v4Qvk6FZrcdI5X_aOHj89fA9kuhEE3TU//?imgmax=800&quot; width=&quot;420&quot; border=&quot;0&quot; height=&quot;229&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;However, I prefer the first way (with static blocks) that gives us more &lt;strong&gt;flexibility&lt;/strong&gt; by allowing us to write a block of code instead of just calling the constructor.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;2. Use Double Checked Locking&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;A very common, popular and misunderstood programming idiom that looks like the following and works with Java 1.5 and above only.&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqckT3DBRvSMeRFgu33YeENb_hzX8M5mfZtgSMDdK2ALt4W1bblQ4FY8OY88fSszhKruvj1tv32J4slAyYSjaklxC-ze7pI6ZaRk1ZAVbLM-kOSssyuiCGJFW319FbTHzfC7y0sbK2jic/s1600-h/Singleton3Java8.jpg&quot;&gt;&lt;img style=&quot;border-width: 0px; display: inline;&quot; title=&quot;Singleton3Java&quot; alt=&quot;Singleton3Java&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuCP8hE9zPZKJkByU9TyacWej8tiNDKRem11H6IOZWYy3Fr0zjwDb-vUmnNP6GGNgALzjwIf4g0FclJRVyDI7jGai4HqD8wUpPDIhIWRrTevvG1amLzCKhb0C1Z5n0U_6Zf4ZcTeojubA//?imgmax=800&quot; width=&quot;437&quot; border=&quot;0&quot; height=&quot;374&quot; /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;See how cleverly, we have &lt;strong&gt;limited&lt;/strong&gt; the scope of synchronization here. The synchronization occurs only for the first time (when the instance is null), after that the synchronization never occurs as the instance is not null. This is what we needed. But you must make this variable as volatile to work it correctly (due to &lt;a href=&quot;http://www.ibm.com/developerworks/library/j-jtp02244.html&quot;&gt;Java Memory Model&lt;/a&gt; implementation) &lt;/p&gt;  &lt;p&gt;To better understand this programming idiom, I would suggest reading &lt;a href=&quot;http://www.ibm.com/developerworks/java/library/j-dcl.html&quot;&gt;this&lt;/a&gt; and &lt;a href=&quot;http://www.javaworld.com/jw-02-2001/jw-0209-double.html&quot;&gt;this&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;I think its enough for one blog post. Any code corrections, new ideas and comments are welcome. &lt;/p&gt;</description><link>http://techno-cratic.blogspot.com/2010/03/singletons-threads-double-checked.html</link><author>noreply@blogger.com (Anonymous)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmgUODg2XSNPljJ-9fc4PSWSAfVYzdVoTCZ4Tmxu3-bS3eM1Per4CU_eSgZCZF-Zup6ie1MrwlhvK7UyXceVMlVSa2y9lV1c_0-NKNYreKF0O6_pOUlLqVNsN-BaKqR3BZbC6ab7lAh7g/s72-c/?imgmax=800" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5223788876950011016.post-1630752433203164566</guid><pubDate>Sat, 27 Feb 2010 11:51:00 +0000</pubDate><atom:updated>2010-02-27T03:53:40.749-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Immutable</category><category domain="http://www.blogger.com/atom/ns#">Java</category><title>Creating Immutable Objects in Java</title><description>&lt;p&gt;Immutable Objects are those objects, who &lt;strong&gt;cannot change their STATE&lt;/strong&gt; once they are created. Most common examples of such objects are String, Integer, Double etc.. (other Wrapper classes). By State, we mean the values assigned to the instance variables of the object in question. &lt;/p&gt;  &lt;p&gt;Immutable Classes are one of the most &lt;strong&gt;robust&lt;/strong&gt; classes that you can ever build and the reasons that we love them are:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;They are &lt;strong&gt;Thread-safe&lt;/strong&gt;, hence no need to synchronize them for concurrent access. &lt;/li&gt;    &lt;li&gt;They are &lt;strong&gt;Easy&lt;/strong&gt; to construct, test and use &lt;/li&gt;    &lt;li&gt;They Serve as &lt;strong&gt;good&lt;/strong&gt; Map and Set &lt;strong&gt;keys&lt;/strong&gt; &lt;/li&gt;    &lt;li&gt;If such an object throws an exception, it is never left in &lt;strong&gt;undesirable&lt;/strong&gt; or &lt;strong&gt;inconsistent&lt;/strong&gt; state. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Strategy to Construct Immutable Objects&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;If we follow the following steps, we can easily create Immutable objects or convert an existing Mutable class into Immutable:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Since we have to restrict our object to change its state once they are created, we must &lt;strong&gt;not provide&lt;/strong&gt; any &lt;strong&gt;setter&lt;/strong&gt; methods. &lt;/li&gt;    &lt;li&gt;If a object has references to other mutable objects, then do not provide getter methods that simply return a reference to the mutable object. Rather, create a new object containing the &lt;strong&gt;copy of the mutable object&lt;/strong&gt;. &lt;/li&gt;    &lt;li&gt;Don&#39;t allow any subclass to override methods of the given class. This can be done by making the class as &lt;strong&gt;final&lt;/strong&gt;. Another way is to make the constructor as private and provide factory methods to construct the object. &lt;/li&gt;    &lt;li&gt;Make all the fields &lt;strong&gt;private and final&lt;/strong&gt;. This way only your class has&amp;#160; the control how these fields are to be manipulated. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCVw8KQgifvUq36zmJyKhjIbAEE6-8m573DwiyTlVvcyLTox-xh_gZp08WvlLz2fFdmRTPN3-GIB8ykBzFo5POlNBVqSnu3naH8GEF5kDAUTvwK3zAzQP8YFQLBfMDS3hw3FGIOSDUdMs/s1600-h/Person1%5B4%5D.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;Person1&quot; border=&quot;0&quot; alt=&quot;Person1&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4R6jI-nSvrt52Rlac1ZjqA7VJgHTRfOiSETrjo7lvLPI-pINmn3NDn87FHJ7h7PJUVTL1VSMEI6vufaPvYfaU8Ae8TBcbtbYG3Wgn8UdiOAXhDYeG2VxInyaJ0eDdlmEC3NQU7w_XhVM//?imgmax=800&quot; width=&quot;448&quot; height=&quot;373&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Also, do not provide any other methods that &lt;strong&gt;modify&lt;/strong&gt; the object. In case you have to, then do not modify the existing object, rather create a copy of the original object, modify it and return the modified object. &lt;/li&gt;    &lt;li&gt;Construct the whole object in one go, initialize the whole object (assign values to all the instance variables) while creating the object. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEia6TshX9HdrPHFGV2o9jSbirpD-Dc-Gz_On_KSKsrcTSuriX9yi2NL-MfoNXPdoU1q0tJo2fqqEPNCL-kX9nNVljZyX7wJRgOfgygmeY7NcAdzL8HiQPc3sYQ2AAOvzfdOGletCRBI0fw/s1600-h/Person2%5B6%5D.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;Person2&quot; border=&quot;0&quot; alt=&quot;Person2&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2MmrnIFUgfWKpjCiHyPnzQs-pBhbZGYWPgPyoKinSKs7EeV3oDWA1lvSoieeIBeSnZ-SwR9iDwoxq7jm7L1kg3QuASD5r6Fsv45gUgTVRGw3ihurWhdRxtAIUMAg7Y767Wm5vqeEhcCc//?imgmax=800&quot; width=&quot;456&quot; height=&quot;333&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;One may argue that immutable objects calls for creation of &lt;strong&gt;unnecessary&lt;/strong&gt; objects every now and then, for example if we do &lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjiuMmjSQACIPubAC7zxm3Sm40GVQmVWpWnNhLI-9roV_cBjjkU-io93YBpAwwG5qYp7EjHKk4jP83iIlhmye1d-fC5cIjjlxvQvLOWq4xHsEBL5ZIljiNWjs2Q_8gAGY81-aQg3cDsVI/s1600-h/Person3%5B3%5D.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;Person3&quot; border=&quot;0&quot; alt=&quot;Person3&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgj1eavlPG1OCTF-rtujSmSo9jsBaNzjQlRNc2bRsDHV6svwNsDK7y_iQx4c1CEGwooq4OHRrJEk5g5_T1nUg85yv88cc0m4FT7MeeTqaigx_ZKfJyILOfANnsy8up7x2sI17oUDrBIjoI//?imgmax=800&quot; width=&quot;276&quot; height=&quot;83&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;then a new String is created and the original string is not modified. For argument sake, we have 3 Strings created here. viz. “Agraj”, “ Mangal” and “Agraj Mangal”.&lt;/p&gt;  &lt;p&gt;But this so-called shortcoming is taken care of by the &lt;strong&gt;Garbage Collector&lt;/strong&gt; in Java, which marks any dead object for Garbage Collection (any object which has no active reference to it in any thread of execution)&lt;/p&gt;  </description><link>http://techno-cratic.blogspot.com/2010/02/creating-immutable-objects-in-java.html</link><author>noreply@blogger.com (Anonymous)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4R6jI-nSvrt52Rlac1ZjqA7VJgHTRfOiSETrjo7lvLPI-pINmn3NDn87FHJ7h7PJUVTL1VSMEI6vufaPvYfaU8Ae8TBcbtbYG3Wgn8UdiOAXhDYeG2VxInyaJ0eDdlmEC3NQU7w_XhVM/s72-c/?imgmax=800" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5223788876950011016.post-7626782526759901039</guid><pubDate>Wed, 27 Jan 2010 16:53:00 +0000</pubDate><atom:updated>2010-01-29T09:37:32.220-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">DU</category><category domain="http://www.blogger.com/atom/ns#">Sankalan</category><title>Sankalan 2010 Goes Green….the Copenhagen Way !!</title><description>&lt;p&gt;&lt;strong&gt;&lt;a href=&quot;http://cs.du.ac.in/&quot;&gt;The Department of Computer Science, University of Delhi&lt;/a&gt;&lt;/strong&gt; once again proudly presents to you its annual technical fest: &lt;strong&gt;Sankalan 2010: Compiling Innovations towards green future….&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;The students at the department, understand the importance of global warming and its harmful effects and thus plan to create awareness and spread the word around. &lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhG3Ysy3wNtCK0bmGxrAaH0j9vRNu2P79-vKWwyGMB9UJeM0CnSEK3EYyieJirnRSNh9Gg3dpRxX93_sSXm5W1xjoHidQuHZkJvnnBU_zoOkOF7Pd7GY5wla9SulyvujuFchHJrNycmg1E/s1600-h/Sankalan&#39;10_magazine_poster%5B5%5D.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto&quot; title=&quot;Sankalan&#39;10_magazine_poster&quot; border=&quot;0&quot; alt=&quot;Sankalan&#39;10_magazine_poster&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgI8bfLU6qoRVzfyvOoeud1mrgGpN24D1Ar2X_HAiN_LHs6kjMyUv-seCQeRLgOnO9nCtxV-WrjiqQw5pE-GmoRm3e8A9MBKe397wi0MMuWMX1Pu_zh24elfIkOGLmGoYzRoSE-9Nb0HU//?imgmax=800&quot; width=&quot;298&quot; height=&quot;404&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;So here we are, with open arms welcoming students all over the country to come and join us in this effort and have fun along the way. &lt;strong&gt;Sankalan&lt;/strong&gt; ( a hindi word meaning Compilation ) has always been a tech-fest of its own kind, with students pouring in from everywhere and making it a success.&lt;/p&gt;  &lt;p&gt;You can find out more information like the events (both technical and non-technical) on the &lt;a href=&quot;http://sankalan2010-goinggreen.blogspot.com/&quot;&gt;fest’s blog&lt;/a&gt;. You can check out the official site &lt;a href=&quot;http://cs.du.ac.in/sankalan2010/&quot;&gt;here&lt;/a&gt; for registration and detailed information for the fest. So pack up your bags and get ready for entertainment and fun-packed stuff. Hope to see you there at &lt;strong&gt;20-21st Feburary 2010&lt;/strong&gt;.&lt;/p&gt;</description><link>http://techno-cratic.blogspot.com/2010/01/sankalan-2010-goes-greenthe-copenhagen.html</link><author>noreply@blogger.com (Anonymous)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgI8bfLU6qoRVzfyvOoeud1mrgGpN24D1Ar2X_HAiN_LHs6kjMyUv-seCQeRLgOnO9nCtxV-WrjiqQw5pE-GmoRm3e8A9MBKe397wi0MMuWMX1Pu_zh24elfIkOGLmGoYzRoSE-9Nb0HU/s72-c/?imgmax=800" height="72" width="72"/><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5223788876950011016.post-4234372965181830431</guid><pubDate>Fri, 15 Jan 2010 18:36:00 +0000</pubDate><atom:updated>2010-01-18T09:10:40.923-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">JBoss</category><category domain="http://www.blogger.com/atom/ns#">JBossWS</category><category domain="http://www.blogger.com/atom/ns#">Web Services</category><title>Creating JBossWS Web Services with JBoss 4.2.3GA and JDK1.5</title><description>&lt;p&gt;Continuing from the last post, today we will learn about creating a Simple Web Service using &lt;strong&gt;jBossWS&lt;/strong&gt; (a JAX-WS implementation) and deploy it on JBoss Server. Also, we will see how can we create a WS-Client using in-build utilities and consume the web service with ease.&lt;/p&gt;  &lt;p&gt;&lt;u&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;:&lt;/u&gt;&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Intermediate knowledge of Java, some experience with XML would help, though not necessary. &lt;/li&gt;    &lt;li&gt;Basic Know-how of a web-application &lt;/li&gt;    &lt;li&gt;&lt;a href=&quot;http://techno-cratic.blogspot.com/2009/12/jax-ws-web-services-with-jboss-jbossws.html&quot;&gt;Setting up the required environment.&lt;/a&gt; &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Getting Started:&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Create a New &lt;strong&gt;Java Project&lt;/strong&gt;. Name it anything you like. Create appropriate structure for a web application like we create an output folder named ‘&lt;strong&gt;web&lt;/strong&gt;’ and create ‘&lt;strong&gt;WEB-INF&lt;/strong&gt;’ in it, which will hold the deployment descriptor ‘&lt;strong&gt;web.xml&lt;/strong&gt;’. The initial structure of our web application looks as follows:&lt;/p&gt;  &lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiWytAuhej_36DHO-HBdJ4ETVTX66YoWLd-V34Pb2pTV02ktTU59UUeyitsnrNVIWpULE4kjUdD7-vISyziYkKuM3X3N6B1cNV-BsoOX1FC3MtWbBiu1LFbn_pBYi1AMkx6xC_VKSc63nM/s1600-h/jbossws%20initial%20project%20structure%5B2%5D.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;jbossws initial project structure&quot; border=&quot;0&quot; alt=&quot;jbossws initial project structure&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikF8IygoPX24B6KCtDm1R96nQm2S3FV9A_MzCGsRP9z7FdcW7kgqjLK5rb95Hm5UgwNYB-NWR_X3_MjVPwHBHztNH_PXwz6DYHLg4Oxfn0773KYyt1K_JARce0BAGht4bogk3grEHXVDc//?imgmax=800&quot; width=&quot;211&quot; height=&quot;188&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;With &lt;strong&gt;JBossWS&lt;/strong&gt;, to create a web service is as easy as creating a Java class and exposing a method and create its entry in the deployment descriptor. Lets first create an entry in &lt;strong&gt;web.xml&lt;/strong&gt; for the the &lt;strong&gt;EndpointServlet&lt;/strong&gt; class and configure it for the Java class containing the Web Service implementation as shown below:Here, we specify &lt;strong&gt;EndpointServlet&lt;/strong&gt; (comes bundled with JBossWS stack) which is used to publish/deploy your web service over JBoss. We also provide its mapping giving the &lt;strong&gt;url-pattern&lt;/strong&gt; of the web service. &lt;br /&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuOZExH4L3Ry3TE35SGZa82yLfOIdzIM1grAJd7qrDXoiyTyCRrkA-TUQAmSNhLyocuZVuGTK4MzY2O-WKr3KspoQ3pihBfgHm45h0y89HHoZNxH0xDZJNOmxoPcCzkhH3BUEtHb_VNfU/s1600-h/jbossws%20webxml%5B10%5D.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;jbossws webxml&quot; border=&quot;0&quot; alt=&quot;jbossws webxml&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgWCb4CpCZ7KO1yRLkRA19wkoCMZijTFrBXLK2bYvReCRdt5U-3Z6H3og3_vDnx6hqN8v-Ev0ix9WwQkssxeHDWtP0nEqebiWPkdnpQn5WaC3ovBNNMI-8pH-1MO-Jm2ocylD1WavlG_3Q//?imgmax=800&quot; width=&quot;445&quot; height=&quot;312&quot; /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Lets see how our Java Class which contains the web service would look like: &lt;/p&gt;  &lt;div&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgX4tOntBcNu-udgko6HOddsFHxlpi1qAljgDkBLfji11OfB280ZHn6xP7NDEp_LQWkxhX4Wh2wTxM7vb9YjDl-_NhQgMd1_YK0vGM-jlsUtj8vaYT-SKOATfrVAvIXnw8ZRDXUG0N7sbk/s1600-h/jbossws%20helloworld%5B3%5D.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;jbossws helloworld&quot; border=&quot;0&quot; alt=&quot;jbossws helloworld&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi1yHdaQ96u8OmHWn6Pmq8UE4xWkueUxU2kXS-50F-9PRNhQhNtMhJFdKaJZ7ZOx-1F1JJKB9Zt6SA7IFoYgGBVwxxhvb15zfLzW9ntil90MW8VQR98GMiWbZgKaUeVmX_3Ut-1NHqx7EM//?imgmax=800&quot; width=&quot;358&quot; height=&quot;267&quot; /&gt;&lt;/a&gt;    &lt;br /&gt;Notice that we have noticed &lt;strong&gt;JAX-WS Annotations&lt;/strong&gt; to decorate our class. The &lt;strong&gt;@WebService&lt;/strong&gt; annotations tells us that this class contains methods exposed by a web service and &lt;strong&gt;@WebMethod&lt;/strong&gt; annotation points out exactly which method is exposed.    &lt;br /&gt;  &lt;br /&gt;&lt;/div&gt;  &lt;div&gt;To make sure that your code compiles, you must include the &lt;strong&gt;JAR’s&lt;/strong&gt; that come with &lt;strong&gt;JBossWS native stack&lt;/strong&gt;. Therefore, we add the following JAR’s to the &lt;strong&gt;lib&lt;/strong&gt; folder of &lt;strong&gt;WEB-INF&lt;/strong&gt; and also configure it on the &lt;strong&gt;build-path&lt;/strong&gt; of the project so that you do not get compilation error in Eclipse. &lt;/div&gt;  &lt;ul&gt;   &lt;li&gt;jaxb-api.jar &lt;/li&gt;    &lt;li&gt;jbossws-native-jaxws-ext.jar &lt;/li&gt;    &lt;li&gt;jbossws-native-jaxws.jar &lt;/li&gt;    &lt;li&gt;jbossws-native-saaj.jar &lt;/li&gt; &lt;/ul&gt;  &lt;div&gt;So, thats all you need to do in order to expose your web service. Lets now publish this web service on JBoss. To do so, we will package it as a WAR file using ANT. I have used the following ANT script to create WAR for my web service. &lt;/div&gt;  &lt;div&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEix6q4A0RKd7H7M87j9Jl_0IUhyjG_9teDv_-fcdJX-u3-VejVCu6B8gIMye12caBhHmVH93FQk_nY2iI6A37SeLgtVNawcPMlZ6g8PTHko1g3mR9ABvOCAfZWJWqunxhYQvFtpCVrtc8M/s1600-h/jbosswss%20build%5B5%5D.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;jbosswss build&quot; border=&quot;0&quot; alt=&quot;jbosswss build&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSzTSgnPyWQWa7KvdsfDp7oO6LiIj-AfM_KCIzVr2_KPPe6zsppLQWH6EQmqCuhpL-YDm3TLMQfGx1G8N8f8Ark55uDN1O0QWB0OXpyEBCixGLcGc78YcFuVQ8-OHmtEFv6KuPAOUkRAg//?imgmax=800&quot; width=&quot;443&quot; height=&quot;216&quot; /&gt;&lt;/a&gt; &lt;/div&gt;  &lt;p&gt;Now, you can copy this war file to the deploy directory of your JBoss Installation. Restart your server and check the logs to see whether it is deployed successfully or not.&lt;/p&gt;  &lt;div&gt;   &lt;pre style=&quot;border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; padding-left: 5px; width: 450px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px&quot; color=&quot;#fbfbfb&quot;&gt;&lt;pre style=&quot;background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 11px&quot;&gt;[TomcatDeployer] deploy, ctxPath=/jaxWS,&lt;br /&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 11px&quot;&gt;warUrl=.../tmp/deploy/tmp5621016708388909925jaxWS-exp.war/&lt;br /&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 11px&quot;&gt;[WSDLFilePublisher] WSDL published to: file:/E:/JBoss/jboss-4.2.3.GA&lt;br /&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,&#39;Courier New&#39;,courier,monospace; font-size: 11px&quot;&gt;/server/default/data/wsdl/jaxWS.war/HelloWorldService300665606.wsdl&lt;/pre&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;So, that tells you that your web service has been deployed. To double check, you can always check the JBoss web service console on this url: &lt;a href=&quot;http://localhost:8085/jbossws/services&quot;&gt;http://localhost:8085/jbossws/services&lt;/a&gt; It shows you a list of all endpoints deployed currently, something like below: &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiuHOzNkKVVRLDBP0xMQqEZwlJZYy_AYE8-2yGCAwTOUYQaj3WBkWaq1aattbcurnvJzLFyj_1F5AM8Ow0OocH9xdFxKUEgjUPf_PEcM-ygA6yN3Mz6E2d7oulexhVP3pi1Nxw4ynJjVfs/s1600-h/jbossws%20Services%20console%5B5%5D.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;jbossws Services console&quot; border=&quot;0&quot; alt=&quot;jbossws Services console&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDlDehe5MbZscaxbNLGCeT3mAMuxUeqNAjuqwnXD1T-BOosNB_ou4XYsk3x2Wc7v5nPwe-ZaIW6Wy4kIuSzr04z_cqBxmQ9-hk20R-6E4TBL-Tf07b-_a21rgKCqG3p1R8a71D_1czs7k//?imgmax=800&quot; width=&quot;434&quot; height=&quot;312&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p&gt;Lets also have a look at a snippet of generated WSDL, though explaining this is out of scope of this entry. &lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh_gmnbP7aI0kGScfAwiw4RI0rs-7xvX2R2Bmyk0QmF2Ul5oVfonkSPQkL3FbZ34zqkxxYxU7Hqw1MkRUgDCAZi_OsJfyk5aETDzjGtXUUdy-Yo7G8ujQNII0LibV0NXaaYFSIvX0Gn4S4/s1600-h/jbossws%20wsdl%5B4%5D.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;jbossws wsdl&quot; border=&quot;0&quot; alt=&quot;jbossws wsdl&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEis3zPhDYU-Ma_CWA0txQXYAeyme9CqJ3T-EbBttbDmDzqkUb19TlK83jHrDNBEdVAYgmSF0hG2868tY3RB6bVS6CmvvXAue__M6r_Rky8cWyZBvUNJL6o5hpUNqkbi3lpqcIQ-ZKrVS5c//?imgmax=800&quot; width=&quot;441&quot; height=&quot;367&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt; JAX-WS provides supports for all Java in-build data types as well as for complex user-defined objects. The &lt;strong&gt;WSDL&lt;/strong&gt; that is generated on publishing the web service contains all the information about the parameters accepted by the web service and also about the format in which the data is returned. Thus, this WSDL is more of a &lt;strong&gt;contract&lt;/strong&gt; on which the communicating parties must agree before communicating.&lt;br /&gt;  &lt;br /&gt;&lt;span style=&quot;font-weight: bold&quot; class=&quot;Apple-style-span&quot;&gt;&lt;span style=&quot;text-decoration: underline&quot; class=&quot;Apple-style-span&quot;&gt;Client Generation:&lt;/span&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt;Now, we consume this web service by creating client using utilities provided by JBossWS stack ( Examples include &lt;strong&gt;wsconsume&lt;/strong&gt;, &lt;strong&gt;wsget&lt;/strong&gt;, &lt;strong&gt;wsrunclient&lt;/strong&gt; etc ) &lt;/p&gt;&lt;p&gt;&lt;strong&gt;&amp;gt;&amp;gt;&amp;gt; wsconsume –k &lt;/strong&gt;&lt;a href=&quot;http://localhost:8085/jaxWS/prodsWS?wsdl&quot;&gt;&lt;strong&gt;http://localhost:8085/jaxWS/prodsWS?wsdl&lt;/strong&gt;&lt;/a&gt; &lt;/p&gt;&lt;p&gt;&lt;strong&gt;wsconsume&lt;/strong&gt; will parse the WSDL and –k option will generate the java classes which will be used by the client using &lt;strong&gt;JAXB &lt;/strong&gt;framework.&lt;br /&gt;&lt;br /&gt;   Now, we will create a &lt;strong&gt;TestClient &lt;/strong&gt;(to test our webservice), which will finally consume the web service.&lt;br /&gt;&lt;br /&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgu1xBYtZOlQrQDclYa9Ht3jruTfyeSaujUuEhqjtiLiqOhfeIcte8cdY7gAJ4fWIvwR9O9hyKKlVjrae4cW4q_dxNhd6GskEOAQYfqyBVc_V-hpoYleczsYxXsQgNcF-QBj3AtJWHG7Yo/s1600-h/jbossws%20client%5B5%5D.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;jbossws client&quot; border=&quot;0&quot; alt=&quot;jbossws client&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHo00JxlLTZWHxdf9eafucSmrSWBwOuluO7f5-R2_eSTB8TM6JhtyjZoTE4bUE5hTXgaIZ7eG7KdAF_81ha-AexrAyyGxBVniKY9VEUcwFSAhLarIneTmVj9nL9VH_aY8vcR5o7hiEBU4//?imgmax=800&quot; width=&quot;452&quot; height=&quot;236&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt; As expected, on running this client, it will print “Hello My Name is Agraj” as output. Please note that in order to run this client successfully, you must add few more client jars to the project.&lt;br /&gt;&lt;br /&gt;The &lt;strong&gt;final structure&lt;/strong&gt; of the web application (&lt;strong&gt;web service + client&lt;/strong&gt;) looks like following: &lt;/p&gt;&lt;div&gt;&lt;p&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhg-9nSvlDjKtalR_DPDUHmJF7J2c8cdJEO9A6iuLBTfiJfEfhv1GCv4uVKzc6Cufpxs2eGDAiZhs8JDE7xDWZ1k__MhWS8OYHzx139c-1o7K8D72mWnV1QAJ_f2X04QayiQBm8a7QFEzc/s1600-h/jbossws%20final%20project%20structure%5B6%5D.jpg&quot;&gt;&lt;img style=&quot;border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px&quot; title=&quot;jbossws final project structure&quot; border=&quot;0&quot; alt=&quot;jbossws final project structure&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh3SzwudtRPs9HHXBvEW-M7smSB1-rqJvo-5oDt2eT2SCCVKMTNRt6SP3z7bLZb_QQBJz40GeNcumZ7mCYGyJQvHmroXJg2x1wAEDXZHkXauChLFFyyDxlTqwO5Z4pfDHPZeeVjpxiRTqA//?imgmax=800&quot; width=&quot;358&quot; height=&quot;476&quot; /&gt;&lt;/a&gt; &lt;br /&gt;So, that’s all I want to talk about web services today, I hope it was of some help. Please post your views or corrections as comments. &lt;/p&gt;&lt;p&gt;Note: You may encounter a few problems while developing web services using JBossWS and JDK 1.6 since there are some compatibility issues and conflicting jars that create problems. Your best friend in such a case is Google :-)&lt;/p&gt;&lt;/div&gt;</description><link>http://techno-cratic.blogspot.com/2010/01/creating-jbossws-web-services-with.html</link><author>noreply@blogger.com (Anonymous)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikF8IygoPX24B6KCtDm1R96nQm2S3FV9A_MzCGsRP9z7FdcW7kgqjLK5rb95Hm5UgwNYB-NWR_X3_MjVPwHBHztNH_PXwz6DYHLg4Oxfn0773KYyt1K_JARce0BAGht4bogk3grEHXVDc/s72-c/?imgmax=800" height="72" width="72"/><thr:total>2</thr:total></item></channel></rss>