<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7771419712340162338</id><updated>2012-01-22T21:03:05.083-08:00</updated><category term='JPA'/><category term='GXT(Ext GWT) Grid example'/><category term='GWT'/><category term='Java Persistence Query Language'/><category term='Contiuous Integration'/><category term='Google Chart Tool'/><category term='Capistrano Deployment'/><category term='Abstract Entities'/><category term='call method dynamically'/><category term='Session Management'/><category term='Amazon'/><category term='Design pattern'/><category term='Deployment'/><category term='Mapped Superclass'/><category term='ActiveMessaging'/><category term='GXT(Ext GWT) TreeGrid Example'/><category term='GXT Chart'/><category term='Local Paging'/><category term='Geochart'/><category term='Rails Application'/><category term='Web'/><category term='RegularExpressionValidator'/><category term='ASP.NET'/><category term='GXT Example'/><category term='GXT Editable Grid'/><category term='rounded div'/><category term='GroupLayout'/><category term='Image Cropping'/><category term='Persistence Query'/><category term='Deployment by Capistrano'/><category term='create domain'/><category term='XTemplate'/><category term='GXT Tree Filter'/><category term='GXT(Ext GWT) Tree example'/><category term='Ext GWT DnD Framework'/><category term='rounded corner'/><category term='video'/><category term='Ext GWT'/><category term='flash chart'/><category term='Strategy pattern'/><category term='row filter with JTextfield'/><category term='Context Menu'/><category term='Servlet'/><category term='ListView'/><category term='Automatic  Deployment'/><category term='show video from YouTube'/><category term='jQuery'/><category term='filtering row'/><category term='JTable'/><category term='Image Resizing'/><category term='java'/><category term='Session Bean'/><category term='GXT(Ext GWT) Editor TreeGrid Example'/><category term='Remote pagination'/><category term='Amazon SQS'/><category term='reCAPTCHA'/><category term='custom dialog'/><category term='GlassFish'/><category term='Google Maps Javascript API'/><category term='Open flash chart'/><category term='Java Persistence'/><category term='YouTube'/><category term='ColumnConfig'/><category term='Modal'/><category term='Filter Grid'/><category term='filter JTable Row'/><category term='GXT(Ext GWT) Context Menu With TreePanel Example'/><category term='Google App Engine'/><category term='Deploy Rails Application'/><category term='invoke method by name'/><category term='cruisecontrol.rb'/><category term='portbase'/><category term='Creat instance at runtime'/><category term='C#'/><category term='Reflection'/><category term='GXT Grid Grouping'/><category term='first gwt application'/><category term='Asynchronous mail sending'/><category term='set up GXT'/><category term='TreePanel'/><category term='gxt'/><category term='JPQL'/><category term='set up Ext GWT'/><category term='Horizontal Bar Chart'/><category term='Asynchronous'/><category term='Grid'/><category term='JavaMail API'/><category term='JDO'/><category term='Capistrano'/><title type='text'>Sharing Experiences</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>46</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-2900944165728908218</id><published>2011-11-27T00:17:00.001-08:00</published><updated>2011-11-27T09:12:30.483-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Google Maps Javascript API'/><title type='text'>Working with Google Maps Javascript API V3</title><content type='html'>&lt;p&gt;Google Maps Javascript API V3 is an awesome API provided by Google. Today I will give you a little flavor about this API. Later I will write about some advance features.&lt;/p&gt;&lt;p&gt;Here is a simple tool, created using this API. Click on the marker, the Latitude and Longitude position will be displayed in a window and also in the textbox. If you set a Latitude, Longitude point in the textbox and click on the button, that point will be shown in the map with a marker.&lt;/p&gt;&lt;script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"&gt;&lt;/script&gt;&lt;script type="text/javascript" src="http://zmodal.googlecode.com/files/jquery-1.6.1.min.js"&gt;&lt;/script&gt;&lt;script type="text/javascript"&gt;        function LoadMap(lat, longitude) {            var latlng = new google.maps.LatLng(lat, longitude);            var myOptions = {                zoom: 5,                center: latlng,                mapTypeId: google.maps.MapTypeId.ROADMAP            };            var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);            var contentString = '&lt;div&gt;' +                'Latitude : &lt;b&gt;'+lat+'&lt;/b&gt;&lt;br/&gt; Longitude : &lt;b&gt;' + longitude + '&lt;/b&gt;'            '&lt;/div&gt;';            var infowindow = new google.maps.InfoWindow({                content: contentString            });            var marker = new google.maps.Marker({                position: latlng,                map: map,                title: 'Location',                draggable: true,                animation: google.maps.Animation.DROP            });            google.maps.event.addListener(marker, 'click', function (event) {                infowindow.open(map, marker);                setLatLongToTextBox(event.latLng);            });        }        function initializeMap() {            LoadMap(23.70992, 90.40714);        }        google.maps.event.addDomListener(window, 'load', initializeMap);        function showInMap() {            var lat = $("#tbLattitude").attr("value");            var longitude = $("#tbLongitude").attr("value");            LoadMap(lat, longitude);            return false;        }        function setLatLongToTextBox(latlong) {            var latstr = latlong + '';            var value = latstr.slice(1, latstr.length - 1);            var latlongs = value.split(",");            $("#tbLattitude").attr("value", latlongs[0]);            $("#tbLongitude").attr("value", latlongs[1]);        }    &lt;/script&gt;&lt;div style="float:left; padding:5px; border:1px solid #CCCCCC;"&gt;        Latitude&lt;br/&gt; &lt;input type="text" id="tbLattitude"/&gt;&lt;br/&gt;        Longitude&lt;br/&gt; &lt;input type="text" id="tbLongitude"/&gt;&lt;br/&gt;        &lt;input type="button" name="btCal" value="Show in Map" onclick="return showInMap();" /&gt;    &lt;/div&gt;    &lt;div id="map_canvas" style="float:left;width: 350px; height: 350px; border: 2px solid #999;margin-left:10px;"&gt;    &lt;/div&gt;&lt;p&gt;&lt;br/&gt;Now I'm going to show you, how you can make this tool..&lt;/p&gt;&lt;p&gt;First load the Google Maps Javascript API and the latest jQuery version . Then design the user interface.&lt;/p&gt;&lt;pre class="html" name="code"&gt; &lt;br /&gt;&amp;lt;script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"&gt;&amp;lt;/script&gt;&lt;br /&gt;&amp;lt;script type="text/javascript" src="http://zmodal.googlecode.com/files/jquery-1.6.1.min.js"&gt;&amp;lt;/script&gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;div style="float:left; width:200px; border:1px solid #CCCCCC;"&gt;&lt;br /&gt;        Latitude &amp;lt;input type="text" id="tbLattitude"/&gt;&amp;lt;br/&gt;&lt;br /&gt;        Longitude &amp;lt;input type="text" id="tbLongitude"/&gt;&amp;lt;br/&gt;&lt;br /&gt;        &amp;lt;input type="button" name="btCal" value="Show in Map" onclick="return showInMap();" /&gt;&lt;br /&gt;    &amp;lt;/div&gt;&lt;br /&gt;    &amp;lt;div id="map_canvas" style="float:left;width: 400px; height: 400px; border: 2px solid #999;margin-left:10px;"&gt;&lt;br /&gt;    &amp;lt;/div&gt;&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;The DIV element with id &lt;span id="keyword1"&gt;'map_canvas'&lt;/span&gt; will be the container of the Map. This id will be required when you create the map object to display in this div.&lt;/p&gt;&lt;p&gt;Now come to the Javascript part..&lt;/p&gt;&lt;p&gt;Set the window onLoad callback method and in that method, call the &lt;span id="keyword1"&gt;LoadMap&lt;/span&gt; method with initial latitude,longitude.&lt;/p&gt;&lt;pre class="html" name="code"&gt; &lt;br /&gt;google.maps.event.addDomListener(window, 'load', initializeMap);&lt;br /&gt;function initializeMap() {&lt;br /&gt;  LoadMap(23.70992, 90.40714);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;In the LoadMap method first create a &lt;span id="keyword1"&gt;LatLng&lt;/span&gt; object using the lat, long parameter&lt;/p&gt;&lt;pre class="html" name="code"&gt; &lt;br /&gt;function LoadMap(lat, longitude) {&lt;br /&gt;var latlng = new google.maps.LatLng(lat, longitude);&lt;br /&gt;&lt;/pre&gt;      Create a &lt;span id="keyword1"&gt;Map&lt;/span&gt; object using map options and the container ID&lt;pre class="html" name="code"&gt; &lt;br /&gt;var myOptions = {&lt;br /&gt;  zoom: 12,&lt;br /&gt;  center: latlng, // previously created LatLng object&lt;br /&gt;  mapTypeId: google.maps.MapTypeId.ROADMAP&lt;br /&gt;};&lt;br /&gt;var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;For the information window first create the content of the window then create a &lt;span id="keyword1"&gt;InfoWindow&lt;/span&gt; object using the content. This object will be later used in the onClick event of the &lt;span id="keyword1"&gt;Marker&lt;/span&gt;.&lt;/p&gt;&lt;pre class="html" name="code"&gt;&lt;br /&gt;var contentString = '&lt;div&gt;' +&lt;br /&gt;  'Latitude : &lt;b&gt;'+lat+'&lt;/b&gt;&lt;br/&gt; Longitude : &lt;b&gt;' + longitude + '&lt;/b&gt;'&lt;br /&gt;  '&lt;/div&gt;';&lt;br /&gt;var infowindow = new google.maps.InfoWindow({&lt;br /&gt;  content: contentString&lt;br /&gt;});&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;Now create the &lt;span id="keyword1"&gt;Marker&lt;/span&gt; object using the &lt;span id="keyword1"&gt;LatLng&lt;/span&gt; and &lt;span id="keyword1"&gt;Map&lt;/span&gt; object. &lt;/p&gt;&lt;pre class="html" name="code"&gt;&lt;br /&gt;var marker = new google.maps.Marker({&lt;br /&gt;  position: latlng,&lt;br /&gt;  map: map,&lt;br /&gt;  title: 'Location',&lt;br /&gt;  draggable: true,&lt;br /&gt;  animation: google.maps.Animation.DROP&lt;br /&gt;});&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;Finally add an event listener for the &lt;span id="keyword1"&gt;Marker&lt;/span&gt; object. First open the &lt;span id="keyword1"&gt;InfoWindow&lt;/span&gt; object then call the method which set LatLng value to the textbox.&lt;/p&gt;&lt;pre class="html" name="code"&gt;&lt;br /&gt;  google.maps.event.addListener(marker, 'click', function (event) {&lt;br /&gt;    infowindow.open(map, marker);&lt;br /&gt;    setLatLongToTextBox(event.latLng);&lt;br /&gt;  });&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;Here is the &lt;span id="keyword1"&gt;setLatLongToTextBox&lt;/span&gt; and &lt;span id="keyword1"&gt;showInMap&lt;/span&gt; method&lt;pre class="html" name="code"&gt;&lt;br /&gt;function setLatLongToTextBox(latlong) {&lt;br /&gt;  var latstr = latlong + '';&lt;br /&gt;  var value = latstr.slice(1, latstr.length - 1);&lt;br /&gt;  var latlongs = value.split(",");&lt;br /&gt;  $("#tbLattitude").attr("value", latlongs[0]);&lt;br /&gt;  $("#tbLongitude").attr("value", latlongs[1]);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;//this method is used as the onclick method of the button &lt;br /&gt;function showInMap() {&lt;br /&gt;  var lat = $("#tbLattitude").attr("value");&lt;br /&gt;  var longitude = $("#tbLongitude").attr("value");&lt;br /&gt;  LoadMap(lat, longitude);&lt;br /&gt;  return false;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-2900944165728908218?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/2900944165728908218/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=2900944165728908218' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/2900944165728908218'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/2900944165728908218'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2011/11/working-with-google-maps-javascript-api.html' title='Working with Google Maps Javascript API V3'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-4208904977000879073</id><published>2011-11-26T19:59:00.001-08:00</published><updated>2011-11-26T20:59:04.681-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Google Chart Tool'/><category scheme='http://www.blogger.com/atom/ns#' term='Geochart'/><title type='text'>Working with Google Chart Tools : Create a Geochart</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;p&gt;Geochart can be a handy tool if you want to represent the demographic behavior of your service. In my recent project for Bangladesh Post Office I used this tool to represent the usage of their service in each Division of Bangladesh. Another big example is the Google Analytics where you can view the location based visitor information of your site. Here I am going to show you how you can use this in your project.&lt;/p&gt;First load the Google's Javascript API&lt;br /&gt;&lt;pre class="html" name="code"&gt;&amp;lt;script src="https://www.google.com/jsapi" type="text/javascript"&amp;gt;  &lt;br /&gt;&amp;lt;/script&amp;gt; &lt;br /&gt;&lt;/pre&gt;&lt;p&gt;Now create a DIV element and give it an ID. This id will be required when you create the chart object to display in this div.&lt;/p&gt;&lt;pre class="html" name="code"&gt;&amp;lt;div id="map"&amp;gt;&lt;br /&gt;    &amp;lt;/div&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;In your Javascript code first load the &lt;span id="keyword1"&gt;geomap&lt;/span&gt; package and set the onLoadCallback method name.&lt;/p&gt;&lt;pre class="html" name="code"&gt;&amp;lt;script type="text/javascript"&amp;gt;&lt;br /&gt; google.load('visualization', '1', { 'packages': ['geomap'] });&lt;br /&gt; google.setOnLoadCallback(drawGeoChart);&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;In the callback method first create a DataTable object add two columns. Just give a suitable name as per your requirement. &lt;/p&gt;&lt;pre class="html" name="code"&gt; function drawGeoChart() {&lt;br /&gt;            var data = new google.visualization.DataTable();&lt;br /&gt;            data.addRows(6);&lt;br /&gt;            data.addColumn('string', 'Country');&lt;br /&gt;            data.addColumn('number', 'Visit');&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;Now set some value to the DataTable. The first column can be an Address, country name, region name locations, or US metropolitan area codes. For country and region name follow this &lt;a href="http://en.wikipedia.org/wiki/ISO_3166-1" target="_blank"&gt;ISO-3166&lt;/a&gt; code or text equivalent to the code. The second column will be the value of the area.&lt;/p&gt;&lt;pre class="html" name="code"&gt;&lt;br /&gt;            data.setValue(0, 0, 'Germany');&lt;br /&gt;            data.setValue(0, 1, 600);&lt;br /&gt;            data.setValue(1, 0, 'United States');&lt;br /&gt;            data.setValue(1, 1, 500);&lt;br /&gt;            data.setValue(2, 0, 'Bangladesh');&lt;br /&gt;            data.setValue(2, 1, 400);&lt;br /&gt;            data.setValue(3, 0, 'Canada');&lt;br /&gt;            data.setValue(3, 1, 200);&lt;br /&gt;            data.setValue(4, 0, 'France');&lt;br /&gt;            data.setValue(4, 1, 200);&lt;br /&gt;            data.setValue(5, 0, 'RU');&lt;br /&gt;            data.setValue(5, 1, 300);&lt;br /&gt;&lt;/pre&gt;Finally configure some property of the chart and draw it using the data previously set.  &lt;br /&gt;&lt;pre class="html" name="code"&gt;&lt;br /&gt;  var regionOptions = {};&lt;br /&gt;  regionOptions['width'] = '400';&lt;br /&gt;  regionOptions['height'] = '250';&lt;br /&gt;  // Look the div id is used here to create the chart object &lt;br /&gt;  var regionChart = new  google.visualization.GeoMap(document.getElementById('map'));&lt;br /&gt;  regionChart.draw(data, regionOptions);&lt;br /&gt;        &lt;br /&gt;}&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;/pre&gt;And here is the outcome. On mouse over you can view the data of the area &lt;br /&gt;&lt;br /&gt; &lt;script src="https://www.google.com/jsapi" type="text/javascript"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt;   google.load('visualization', '1', { 'packages': ['geomap'] });   google.setOnLoadCallback(drawGeoChart);   function drawGeoChart() {            var data = new google.visualization.DataTable();            data.addRows(6);            data.addColumn('string', 'Country');            data.addColumn('number', 'Visit');            data.setValue(0, 0, 'Germany');            data.setValue(0, 1, 600);            data.setValue(1, 0, 'United States');            data.setValue(1, 1, 500);            data.setValue(2, 0, 'Bangladesh');            data.setValue(2, 1, 400);            data.setValue(3, 0, 'Canada');            data.setValue(3, 1, 200);            data.setValue(4, 0, 'France');            data.setValue(4, 1, 200);            data.setValue(5, 0, 'RU');            data.setValue(5, 1, 300);            var regionOptions = {};            regionOptions['width'] = '400';            regionOptions['height'] = '250';            var regionChart = new google.visualization.GeoMap(document.getElementById('map'));            regionChart.draw(data, regionOptions);                } &lt;/script&gt;&lt;div id="map"&gt;    &lt;/div&gt;&lt;br/&gt;&lt;br/&gt;&lt;p&gt;You can load the chart data by a webservice call. For C# see &lt;a href="http://zawoad.blogspot.com/2011/11/working-with-google-chart-tools-in-c.html" target="_blank"&gt;my previous blog&lt;/a&gt;.Visit this &lt;a href="http://code.google.com/apis/chart/interactive/docs/gallery/geochart.html" target="_blank"&gt;link&lt;/a&gt; to know more about Geochart. &lt;/p&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-4208904977000879073?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/4208904977000879073/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=4208904977000879073' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/4208904977000879073'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/4208904977000879073'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2011/11/working-with-google-chart-tools-create.html' title='Working with Google Chart Tools : Create a Geochart'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-2947800179307541299</id><published>2011-11-18T17:52:00.001-08:00</published><updated>2011-11-21T02:34:31.634-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='Google Chart Tool'/><title type='text'>Working with Google Chart Tools in C# .NET : Create a Simple Pie Chart</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;p&gt;If you want to load a chart asynchronously in C# . NET, &lt;a href="http://code.google.com/intl/pt-BR/apis/chart/interactive/docs/index.html"&gt;Google Chart Tools&lt;/a&gt; will be the perfect choice for you. It is easy to use and enough flexible to customize. Suppose you want to show how many students in your class like Pizza, Burger, Hotdog, and Fried Chicken in a Pie chart. Here I will show you how to load the students' data from server side using WebService and show it in a chart asynchronously.&lt;/p&gt;&lt;p&gt;First create a new WebService file suppose &lt;span id="keyword1"&gt;GoogleChart.asmx&lt;/span&gt; .In this file create a Public Class named &lt;span id="keyword1"&gt;FoodLikingCount&lt;/span&gt;&lt;/p&gt;&lt;pre class="CSharp" name="code"&gt;    public class FoodLikingCount&lt;br /&gt;    {&lt;br /&gt;        public int PizzaCount { get; set; }&lt;br /&gt;        public int BurgerCount { get; set; }&lt;br /&gt;        public int HotdogCount { get; set; }&lt;br /&gt;        public int FriedChickenCount { get; set; }&lt;br /&gt;    }&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;After the class declaration add the following line&lt;br /&gt;&lt;br /&gt;&lt;pre class="CSharp" name="code"&gt;[System.Web.Script.Services.GenerateScriptType(typeof(FoodLikingCount))]&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;It will enable you to use the FoodLikingCount object in your Javascript code.&lt;br /&gt;&lt;br /&gt;Create a new WebMethod in the WebService class named &lt;span id="keyword1"&gt;GetFoodLikingCountData&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="CSharp" name="code"&gt;[WebMethod]&lt;br /&gt;public FoodLikingCount GetFoodLikingCountData()&lt;br /&gt;{&lt;br /&gt;       FoodLikingCount countModel = new FoodLikingCount &lt;br /&gt;       {&lt;br /&gt;           PizzaCount = 12,&lt;br /&gt;           BurgerCount = 16,&lt;br /&gt;           HotdogCount = 8,&lt;br /&gt;           FriedChickenCount = 4,&lt;br /&gt;       };&lt;br /&gt;       // you can also load data from your database here&lt;br /&gt;&lt;br /&gt;       return countModel ;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;Now come to client side code. Create an aspx file named &lt;span id="keyword1"&gt;GoogleChartToolTest.aspx&lt;/span&gt; and add this line between head tag.&lt;/p&gt;&lt;pre class="html" name="code"&gt; &amp;lt;script src="https://www.google.com/jsapi" type="text/javascript"&amp;gt;&lt;br /&gt; &amp;lt;/script&amp;gt; &lt;br /&gt;&lt;/pre&gt;&lt;p&gt;Create a DIV element and give it an ID. This id will be required when you create the chart object to display in this div. Also add a ScriptManager to call your webservice method.&lt;/p&gt;&lt;pre class="html" name="code"&gt;    &amp;lt;form id="form1" runat="server"&amp;gt;&lt;br /&gt;        &amp;lt;asp:ScriptManager ID="sm1" runat="server"&amp;gt;&lt;br /&gt;            &amp;lt;Services&amp;gt;&lt;br /&gt;                 &amp;lt;asp:ServiceReference Path="~/[your_package]/GoogleChart.asmx" /&amp;gt;&lt;br /&gt;            &amp;lt;/Services&amp;gt;&lt;br /&gt;        &amp;lt;/asp:ScriptManager&amp;gt;&lt;br /&gt;    &amp;lt;/form&amp;gt;&lt;br /&gt;    &amp;lt;div id="pie_chart"&amp;gt;&lt;br /&gt;    &amp;lt;/div&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;Here is the Javascript code which you require to load data through the webservice call, create, and show chart in the div.&lt;/p&gt;&lt;pre class="html" name="code"&gt;&amp;lt;script type="text/javascript"&amp;gt;&lt;br /&gt;&lt;br /&gt;//load the corechart package, the pie chart is in this package&lt;br /&gt;google.load('visualization', '1', { packages: ['corechart'] });&lt;br /&gt;&lt;br /&gt;//provide the method name which you want to call as onload callback&lt;br /&gt;google.setOnLoadCallback(loadFoodLikingChart);&lt;br /&gt;&lt;br /&gt;function loadFoodLikingChart()&lt;br /&gt;{&lt;br /&gt;       [your_package].GoogleChart.GetFoodLikingCountData(&lt;br /&gt;            function (ws_rsp) {&lt;br /&gt;              var foodLikingData= new google.visualization.DataTable();&lt;br /&gt;              foodLikingData.addColumn('string', 'Food');&lt;br /&gt;              foodLikingData.addColumn('number', 'Count');&lt;br /&gt;              foodLikingData.addRows(4);&lt;br /&gt;              &lt;br /&gt;              foodLikingData.setValue(0, 0, "Pizza");&lt;br /&gt;              foodLikingData.setValue(0, 1, ws_rsp.PizzaCount );&lt;br /&gt;              foodLikingData.setValue(1, 0, "Burger");&lt;br /&gt;              foodLikingData.setValue(1, 1, ws_rsp.BurgerCount );&lt;br /&gt;              foodLikingData.setValue(2, 0, "Hotdog");&lt;br /&gt;              foodLikingData.setValue(2, 1, ws_rsp.HotdogCount );&lt;br /&gt;              foodLikingData.setValue(3, 0, "Fried Chicken");&lt;br /&gt;              foodLikingData.setValue(3, 1, ws_rsp.FriedChickenCount );&lt;br /&gt;&lt;br /&gt;              var options = {};&lt;br /&gt;              options ['width'] = '400';&lt;br /&gt;              options ['height'] = '250';&lt;br /&gt;              options ['chartArea'] = { left: 20, top: 20, width: '95%', height: '90%' };&lt;br /&gt;&lt;br /&gt;              // Look the div id is used here to create the chart object&lt;br /&gt;              var chart = new google.visualization.PieChart(document.getElementById('pie_chart'));&lt;br /&gt;              chart.draw(foodLikingData,options);&lt;br /&gt;            },&lt;br /&gt;            function (e) {&lt;br /&gt;               alert("Error");&lt;br /&gt;           }&lt;br /&gt;      );&lt;br /&gt;}&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The result will be like this.&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-QV5sZ_brMTw/TsomOsffibI/AAAAAAAAAhA/6M0PtDWLbRc/s1600/googleChartBlog.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="232" src="http://3.bp.blogspot.com/-QV5sZ_brMTw/TsomOsffibI/AAAAAAAAAhA/6M0PtDWLbRc/s320/googleChartBlog.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;/div&gt;&lt;p&gt;Visualize the DataTable as a two dimensional array. It will help you to understand the above code.Here is the &lt;a href="http://code.google.com/intl/pt-BR/apis/chart/interactive/docs/gallery.html"&gt;Google Chart Gallery.&lt;/a&gt;  You will get a lot of example there.&lt;/p&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-2947800179307541299?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/2947800179307541299/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=2947800179307541299' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/2947800179307541299'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/2947800179307541299'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2011/11/working-with-google-chart-tools-in-c.html' title='Working with Google Chart Tools in C# .NET : Create a Simple Pie Chart'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/-QV5sZ_brMTw/TsomOsffibI/AAAAAAAAAhA/6M0PtDWLbRc/s72-c/googleChartBlog.png' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-1361266648643613011</id><published>2011-08-10T00:35:00.000-07:00</published><updated>2011-08-10T08:19:10.443-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Web'/><category scheme='http://www.blogger.com/atom/ns#' term='Modal'/><category scheme='http://www.blogger.com/atom/ns#' term='jQuery'/><title type='text'>zModal, An Easy to Use jQuery Modal Plugin</title><content type='html'>&lt;script type="text/javascript" src="http://zmodal.googlecode.com/files/jquery-1.6.1.min.js"&gt;&lt;/script&gt;&lt;br /&gt;&lt;script type="text/javascript" src="http://zmodal.googlecode.com/files/zModal.js"&gt;&lt;/script&gt;&lt;br /&gt;There are lots of jQuery modal plugin available in the web. For my current project I need one which, I can easily customize. I realized creating a modal by myself is the best way for gaining maximum freedom. &lt;br /&gt;&lt;br /&gt;It is very simple and easy to use and customizable. You can give it a try. Here I will describe how to use it.&lt;br /&gt;&lt;br /&gt;First download all the required files from &lt;a href = "http://code.google.com/p/zmodal/downloads/list" target="_blank"&gt;&lt;b&gt;here&lt;/b&gt;&lt;/a&gt; and include in the page.&lt;br /&gt;&lt;br /&gt;Create a DIV and give it an id and set the display property 'none'.&lt;br /&gt;&lt;pre class="html" name="code"&gt;&amp;lt;div id="modalContent" style="width:400px; display:none;"&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&lt;/pre&gt;You can insert any content between the DIV tag.&lt;br /&gt;&lt;br /&gt;Now place a button, the onclick event of which will show the modal&lt;br /&gt;&lt;pre class="html" name="code"&gt;&amp;lt;input type="button" name="name2" value="Show Modal" &lt;br /&gt;onclick="$('#modalContent').showModal();" /&amp;gt;&lt;br /&gt;&lt;/pre&gt;Here is an example. Click on the button and a modal will pop up.&lt;br /&gt;&lt;div id="modalContent" style="width:400px; height: 150px; display: none;"&gt;&lt;p style="padding-left:20px;"&gt;modalContent:&lt;br /&gt;Click the close button to hide the modal&lt;br /&gt;You can also press ESCAPE button to hide the modal&lt;br /&gt;&lt;/p&gt;&lt;/div&gt;&lt;input type="button" name="name2" value="Show Modal" onclick="$('#modalContent').showModal();" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="html" name="code"&gt;&amp;lt;div id="modalContent" style="width:400px; height: 150px; display: none;"&amp;gt;&lt;br /&gt;&amp;lt;p style="padding-left:20px;"&amp;gt;&lt;br /&gt;modalContent:&lt;br /&gt;Click the close button to hide the modal&lt;br /&gt;You can also press ESCAPE button to hide the modal&lt;br /&gt;&amp;lt;/p&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;input type="button" name="name2" value="Show Modal" &lt;br /&gt;onclick="$('#modalContent').showModal();" /&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;There are some configurable options for the modal.&lt;br /&gt;&lt;span id="keyword1"&gt;setModalButtonCss :&lt;/span&gt; Set True if you want to display all buttons contained in the modal in a zModal style.&lt;br /&gt;&lt;span id="keyword1"&gt;hideDefaultClose :&lt;/span&gt; Set True if you want to hide the default close button.&lt;br /&gt;&lt;span id="keyword1"&gt;opacity :&lt;/span&gt; You can control the opacity of the background with this parameter.&lt;br /&gt;&lt;span id="keyword1"&gt;bgColor :&lt;/span&gt; You can change the background color with this parameter.&lt;br /&gt;&lt;/p&gt;Here is an example with all the options are set.&lt;br /&gt;&lt;pre class="html" name="code"&gt;&amp;lt;div id="modalContent2" style="width:400px; display:none;"&amp;gt;&lt;br /&gt;&amp;lt;p&amp;gt;&lt;br /&gt;User Name:&amp;lt;br /&amp;gt;&lt;br /&gt;&amp;lt;input id="tbUname" type="text" name="uName"&amp;gt;&lt;br /&gt;&amp;lt;/p&amp;gt;&lt;br /&gt;&amp;lt;p&amp;gt;&lt;br /&gt;Password:&amp;lt;br /&amp;gt;&lt;br /&gt;&amp;lt;input id="tbPass" type="text" name="pass"&amp;gt;&lt;br /&gt;&amp;lt;/p&amp;gt;&lt;br /&gt;&amp;lt;p&amp;gt;&lt;br /&gt;&amp;lt;input type="button" name="login" value="Login" onclick="$('#modalContent2').hideModal()" /&amp;gt;&lt;br /&gt;&amp;lt;/p&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;input type="button" name="name" value="Show Modal 1" &lt;br /&gt;onclick="$('#modalContent2').showModal({'setModalButtonCss': 'True', &lt;br /&gt;'hideDefaultClose' : 'True', &lt;br /&gt;'opacity' : '.2', &lt;br /&gt;'bgColor' : '#7FCFF9' });" /&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;div id="modalContent2" style="width:400px; display:none;"&gt;&lt;p&gt;User Name:&lt;br /&gt;&lt;input id="tbUname" type="text" name="uName"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Password:&lt;br /&gt;&lt;input id="tbPass" type="text" name="pass"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;input type="button" name="login" value="Login" onclick="$('#modalContent2').hideModal()"/&gt; &lt;br /&gt;&lt;/p&gt;&lt;/div&gt;Click on the button to view the example &lt;input type="button" name="name" value="Show Modal" onclick="$('#modalContent2').showModal({'setModalButtonCss': 'True', 'hideDefaultClose' : 'True', 'opacity' : '.2', 'bgColor' : '#7FCFF9' });" /&gt;&lt;br /&gt;&lt;br /&gt;If you want to hide your modal like the onclick event of the Login button write this code&lt;br /&gt;&lt;pre class="html" name="code"&gt;$('#divID').hideModal();&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-1361266648643613011?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/1361266648643613011/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=1361266648643613011' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/1361266648643613011'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/1361266648643613011'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2011/08/zmodal-easy-to-use-jquery-modal-plugin.html' title='zModal, An Easy to Use jQuery Modal Plugin'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-3556737327319234797</id><published>2011-04-05T04:01:00.000-07:00</published><updated>2011-04-05T04:08:19.189-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='RegularExpressionValidator'/><category scheme='http://www.blogger.com/atom/ns#' term='Design pattern'/><title type='text'>Remember Old School OO Principle While Using RegularExpressionValidator</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;p&gt;I'm sure all of you are frequently using RegularExpressionValidator in your project. But are sure you are not repeating same expression in multiple pages? Is your code impervious to Change? If you are a bit careful while writing code, you can avoid this. And your friend will be 'Inheritance'. &lt;br /&gt;&lt;br /&gt;Suppose you are using a RegularExpressionValidator to validate phone number. You may possibly going to write following code block&lt;br /&gt;&lt;/p&gt;&lt;pre class="CSharp" name="code"&gt;&amp;lt;asp:RegularExpressionValidator ID="revPhoneNumber" Display="Dynamic" ErrorMessage="Valid phone no required." ControlToValidate="tbPhoneNumber" ValidationExpression="^\d{8,}$" runat="server"&amp;gt;*&amp;lt;/asp:RegularExpressionValidator&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;If you need this Validator in more than one page, then writing the same code block in every page obviously produces code duplication. Moreover if your project manager asks you to allow '+' at the beginning of the phone number then you have to change the regular expression in all pages. That will be surely a painful task for you. You can make your life easy by following approach.&lt;br /&gt;&lt;br /&gt;Create your own validator by inheriting RegularExpressionValidator. Assign a regular expression to the ValidationExpression property&lt;br /&gt;&lt;/p&gt;&lt;pre class="CSharp" name="code"&gt;namespace TestValidator.Validators&lt;br /&gt;{&lt;br /&gt;    public class PhoneNumberValidator : RegularExpressionValidator&lt;br /&gt;    {&lt;br /&gt;        public PhoneNumberValidator()&lt;br /&gt;        {&lt;br /&gt;            ValidationExpression = "^\\d{8,}$";&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;To use your own PhoneNumberValidator first add this in the Registry&lt;br /&gt;&lt;pre class="CSharp" name="code"&gt;&amp;lt;%@ Register Assembly="TestValidator(Project Name)" Namespace="TestValidator.Validators" TagPrefix="myvalidators" %&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Then use this in the following way&lt;br /&gt;&lt;br /&gt;&lt;pre class="CSharp" name="code"&gt;&amp;lt;myvalidators:PhoneNumberValidator ID="revPhoneNumber" Display="Dynamic" ErrorMessage="Valid phone no required." ControlToValidate="tbPhoneNumber" runat="server"&amp;gt;*&amp;lt;/myvalidators:PhoneNumberValidator&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now it is a matter of seconds to accomplish what your project manager wants.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-3556737327319234797?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/3556737327319234797/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=3556737327319234797' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/3556737327319234797'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/3556737327319234797'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2011/04/remember-old-school-oo-principle-while.html' title='Remember Old School OO Principle While Using RegularExpressionValidator'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-3757267854453643912</id><published>2011-02-25T23:19:00.000-08:00</published><updated>2011-08-11T19:57:34.675-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Filter Grid'/><category scheme='http://www.blogger.com/atom/ns#' term='Ext GWT'/><category scheme='http://www.blogger.com/atom/ns#' term='gxt'/><title type='text'>Working With GXT (Ext GWT) Grid : Add Filter Functionality</title><content type='html'>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;p&gt;Yesterday I was looking for something new (new widgets, new functionality) in the latest GXT version (2.2.1) and found that, it is now providing grid filtering support. You can add MS Excel like filtering option in your application through this. I think it was the most demanded and expected feature from the GXT developers which can be highly utilized in Enterprise Reporting. I am going to describe how to add this functionality in GXT Grid.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://zawoad.blogspot.com/2009/06/getting-started-with-gwt-create-your.html" target="_blank"&gt;Create a new project&lt;/a&gt; named GxtFilterGrid and &lt;a href="http://zawoad.blogspot.com/2009/06/how-to-use-ext-gwt-in-eclipse-34-to.html" target="_blank"&gt;add GXT library&lt;/a&gt; in the project. As like my previous blogs about GXT Grid I have used the same &lt;b&gt;&lt;i&gt;Employee &lt;/i&gt;&lt;/b&gt;model and &lt;b&gt;&lt;i&gt;TestData &lt;/i&gt;&lt;/b&gt;class for generating data. You will find the code of these classes &lt;a href="http://zawoad.blogspot.com/2009/08/how-to-create-simple-grid-using-gxtext.html" target="_blank"&gt;here&lt;/a&gt;. Go to the onModuleLoad method of GxtFilterGrid class and remove all the auto generated code of this method. &lt;br /&gt;&lt;br /&gt;First create a list of ColumnConfig and a ColumnModel from this list.&lt;br /&gt;&lt;/p&gt;&lt;pre class="java" name="code"&gt;List&amp;lt;ColumnConfig&amp;gt; configs = new ArrayList&amp;lt;ColumnConfig&amp;gt;();&lt;br /&gt;&lt;br /&gt;  ColumnConfig column = new ColumnConfig();&lt;br /&gt;  column.setId("name");&lt;br /&gt;  column.setHeader("Employee Name");&lt;br /&gt;  column.setWidth(200);&lt;br /&gt;  configs.add(column);&lt;br /&gt;&lt;br /&gt;  column = new ColumnConfig("department", "Department", 150);&lt;br /&gt;  column.setAlignment(HorizontalAlignment.LEFT);&lt;br /&gt;  configs.add(column);&lt;br /&gt;&lt;br /&gt;  column = new ColumnConfig("designation", "Designation", 150);&lt;br /&gt;  column.setAlignment(HorizontalAlignment.LEFT);&lt;br /&gt;  configs.add(column);&lt;br /&gt;&lt;br /&gt;  column = new ColumnConfig("salary", "Slary", 100);&lt;br /&gt;  column.setAlignment(HorizontalAlignment.RIGHT);&lt;br /&gt;  final NumberFormat number = NumberFormat.getFormat("0.00");&lt;br /&gt;  GridCellRenderer&amp;lt;Employee&amp;gt; checkSalary = new GridCellRenderer&amp;lt;Employee&amp;gt;() {&lt;br /&gt;   @Override&lt;br /&gt;   public Object render(Employee model, String property,&lt;br /&gt;     com.extjs.gxt.ui.client.widget.grid.ColumnData config,&lt;br /&gt;     int rowIndex, int colIndex, ListStore&amp;lt;Employee&amp;gt; store,&lt;br /&gt;     Grid&amp;lt;Employee&amp;gt; grid) {&lt;br /&gt;    double val = (Double) model.get(property);&lt;br /&gt;    String style = val &amp;lt; 70000 ? "red" : "green";&lt;br /&gt;    return ""&lt;br /&gt;      + number.format(val) + "";&lt;br /&gt;&lt;br /&gt;   }&lt;br /&gt;  };&lt;br /&gt;  column.setRenderer(checkSalary);&lt;br /&gt;  configs.add(column);&lt;br /&gt;&lt;br /&gt;  column = new ColumnConfig("joiningdate", "Joining Date", 100);&lt;br /&gt;  column.setAlignment(HorizontalAlignment.RIGHT);&lt;br /&gt;  column.setDateTimeFormat(DateTimeFormat.getShortDateFormat());&lt;br /&gt;  configs.add(column);&lt;br /&gt;&lt;br /&gt;  ColumnModel cm = new ColumnModel(configs);&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;Now create different types of filters like Numeric, String, Date, etc. Constructor of these filter classes takes the column name to bind the specific filter with a specific column. &lt;br /&gt;&lt;/p&gt;&lt;pre class="java" name="code"&gt;NumericFilter numericFilter = new NumericFilter("salary");&lt;br /&gt;StringFilter nameFilter = new StringFilter("name");&lt;br /&gt;StringFilter designationFilter = new StringFilter("designation");&lt;br /&gt;DateFilter dateFilter = new DateFilter("joiningdate"); &lt;br /&gt;&lt;/pre&gt;&lt;p&gt;You can also add a ListStore as a filtering option with the help of &lt;span id="keyword1"&gt;ListFilter&lt;/span&gt;. For adding a list filter, create a ListStore of ModelData or your own BaseModel class and add this as the source of ListFilter.&lt;br /&gt;&lt;/p&gt;&lt;pre class="java" name="code"&gt;ListStore&amp;lt;ModelData&amp;gt; departmentStore = new ListStore&amp;lt;ModelData&amp;gt;();&lt;br /&gt;departmentStore.add(departement("General Administration"));&lt;br /&gt;departmentStore.add(departement("Information Technology"));&lt;br /&gt;departmentStore.add(departement("Marketing"));&lt;br /&gt;departmentStore.add(departement("Accounts"));&lt;br /&gt; //department method is stated later&lt;br /&gt;ListFilter listFilter = new ListFilter("department", departmentStore);&lt;br /&gt;listFilter.setDisplayProperty("departmentname");&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;Display Property of the ListFilter will be the key name of your model data. Now create a &lt;span id="keyword1"&gt;GridFilters&lt;/span&gt; instance and add all the filters created above with this instance.&lt;br /&gt;&lt;/p&gt;&lt;pre class="java" name="code"&gt;GridFilters filters = new GridFilters();&lt;br /&gt;filters.setLocal(true);&lt;br /&gt;filters.addFilter(numericFilter);&lt;br /&gt;filters.addFilter(nameFilter);&lt;br /&gt;filters.addFilter(designationFilter);&lt;br /&gt;filters.addFilter(dateFilter);&lt;br /&gt;filters.addFilter(listFilter);&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;Finally create a ListStore of Employee Model and, a Grid from this ListStore and ColumnModel. Add the GridFilters instance as the Plugin of the Grid.&lt;br /&gt;&lt;/p&gt;&lt;pre class="java" name="code"&gt;ListStore&amp;lt;Employee&amp;gt; employeeList = new ListStore&amp;lt;Employee&amp;gt;();&lt;br /&gt;employeeList.add(TestData.getEmployees());&lt;br /&gt;&lt;br /&gt;Grid&amp;lt;Employee&amp;gt; grid = new Grid&amp;lt;Employee&amp;gt;(employeeList, cm);&lt;br /&gt;grid.setStyleAttribute("borderTop", "none");&lt;br /&gt;grid.setAutoExpandColumn("name");&lt;br /&gt;grid.setBorders(true);&lt;br /&gt;grid.setStripeRows(true);&lt;br /&gt;grid.getView().setForceFit(true);&lt;br /&gt;grid.setColumnLines(true);&lt;br /&gt;grid.addPlugin(filters);&lt;br /&gt;&lt;br /&gt;ContentPanel cp = new ContentPanel();&amp;nbsp; &lt;br /&gt;cp.setBodyBorder(false);&amp;nbsp; &lt;br /&gt;cp.setHeading("Employee List With Filtering Option");&amp;nbsp; &lt;br /&gt;cp.setButtonAlign(HorizontalAlignment.CENTER);&amp;nbsp; &lt;br /&gt;cp.setLayout(new FitLayout());&amp;nbsp; &lt;br /&gt;cp.setSize(700, 300); &lt;br /&gt;cp.add(grid);&amp;nbsp; &lt;br /&gt;RootPanel.get().add(cp);&lt;br /&gt;&lt;/pre&gt;Here is the code of department method which is used previously. &lt;br /&gt;&lt;pre class="java" name="code"&gt;private ModelData departement(String departement) {&lt;br /&gt;&amp;nbsp; ModelData model = new BaseModelData();&lt;br /&gt;&amp;nbsp; model.set("departmentname", departement);&lt;br /&gt;&amp;nbsp; return model;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;That's all. Run the project and the output will be like this&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="https://lh6.googleusercontent.com/-X1Avu12mArM/TWieh9be8vI/AAAAAAAAAZ4/UuoBKTs0Wqo/s1600/gxtFilterGrid.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="107" src="https://lh6.googleusercontent.com/-X1Avu12mArM/TWieh9be8vI/AAAAAAAAAZ4/UuoBKTs0Wqo/s320/gxtFilterGrid.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-3757267854453643912?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/3757267854453643912/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=3757267854453643912' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/3757267854453643912'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/3757267854453643912'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2011/02/working-with-gxt-ext-gwt-grid-add.html' title='Working With GXT (Ext GWT) Grid : Add Filter Functionality'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='https://lh6.googleusercontent.com/-X1Avu12mArM/TWieh9be8vI/AAAAAAAAAZ4/UuoBKTs0Wqo/s72-c/gxtFilterGrid.png' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-71690396949767628</id><published>2011-02-19T20:48:00.000-08:00</published><updated>2011-02-19T20:56:38.731-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='Image Resizing'/><category scheme='http://www.blogger.com/atom/ns#' term='Image Cropping'/><title type='text'>Java Image Utility</title><content type='html'>&lt;p&gt;Few days ago I did some image manipulation tasks like resizing, cropping, etc.  java awt provides some useful functionality to do this type of tasks. Here I am going to share how I accomplish the tasks and finally and ImageUtility Class which you can use in your project.&lt;br /&gt;&lt;br /&gt;&lt;span id="keyword1"&gt;&lt;b&gt;Image Resizing&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;First read the image with the &lt;span id="keyword1"&gt;ImageIO &lt;/span&gt; which returns a &lt;span id="keyword1"&gt;BufferedImage&lt;/span&gt;. Then create another BufferedImage instance with the new width, height and image type.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;pre class="java" name="code"&gt;BufferedImage originalImage = ImageIO.read(imageFile); &lt;br /&gt;BufferedImage scaledBI = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;Now get the &lt;span id="keyword1"&gt;Graphics2D&lt;/span&gt; component of the new scaled image and draw it.&lt;br /&gt;&lt;/p&gt;&lt;pre class="java" name="code"&gt;g.drawImage(originalImage, 0, 0, 100, 100, null);&lt;br /&gt;g.dispose();&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;If you want to preserve the image quality, add following line of code before disposing the graphics component.&lt;br /&gt;&lt;/p&gt;&lt;pre class="java" name="code"&gt;g.setComposite(AlphaComposite.Src);&lt;br /&gt;g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,&lt;br /&gt;RenderingHints.VALUE_INTERPOLATION_BILINEAR);&lt;br /&gt;g.setRenderingHint(RenderingHints.KEY_RENDERING,&lt;br /&gt;RenderingHints.VALUE_RENDER_QUALITY);&lt;br /&gt;g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,&lt;br /&gt;RenderingHints.VALUE_ANTIALIAS_ON);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;It's simple, is not it?&lt;br /&gt;&lt;br /&gt;&lt;span id="keyword1"&gt;&lt;b&gt;Image Croping&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;p&gt;Read the image with ImageIO as stated previously and get the sub image of the original image.&lt;br /&gt;&lt;/p&gt;&lt;pre class="java" name="code"&gt;BufferedImage originalImage = ImageIO.read(imageFile); &lt;br /&gt;originalImage .getSubimage(0,0, 100, 100);&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;First two parameter of the &lt;span id="keyword1"&gt;getSubimage&lt;/span&gt; method is the x,y coordinate, from where you want to begin cropping.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;span id="keyword1"&gt;&lt;b&gt;Get Byte Array of an Image&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;p&gt;Sometimes you need this specially when you want to save an image in database in blob data type . We can get byte[] of an image with the help of &lt;span id="keyword1"&gt;ByteArrayOutputStream&lt;/span&gt; and ImageIO class.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;pre class="java" name="code"&gt;BufferedImage originalImage = ImageIO.read(imageFile); &lt;br /&gt;ByteArrayOutputStream baos = new ByteArrayOutputStream();&lt;br /&gt;ImageIO.write(originalImage , getImageExtension(), baos);&lt;br /&gt;//getImageExtension method is stated later&lt;br /&gt;baos.flush();&lt;br /&gt;byte[] imageData = baos.toByteArray();&lt;br /&gt;baos.close();&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span id="keyword1"&gt;&lt;b&gt;ImageUtility.java&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;All the above actions can be encapsulated into a simple ImageUtility class.&lt;br /&gt;&lt;br /&gt;&lt;pre class="java" name="code"&gt;import java.awt.AlphaComposite;&lt;br /&gt;import java.awt.Dimension;&lt;br /&gt;import java.awt.Graphics2D;&lt;br /&gt;import java.awt.Image;&lt;br /&gt;import java.awt.Rectangle;&lt;br /&gt;import java.awt.RenderingHints;&lt;br /&gt;import java.awt.image.BufferedImage;&lt;br /&gt;import java.io.ByteArrayOutputStream;&lt;br /&gt;import java.io.File;&lt;br /&gt;import java.io.IOException;&lt;br /&gt;import javax.imageio.ImageIO;&lt;br /&gt;import javax.swing.ImageIcon;&lt;br /&gt;import org.openide.util.Exceptions;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt;&amp;nbsp;*&lt;br /&gt;&amp;nbsp;* @author ratul&lt;br /&gt;&amp;nbsp;*/&lt;br /&gt;public class ImageUtility&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; private File imageFile;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; private BufferedImage image;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public ImageUtility()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public ImageUtility(File imageFile)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; try&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&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; this.imageFile = imageFile;&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; image = ImageIO.read(imageFile);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; catch (IOException ex)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&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; Exceptions.printStackTrace(ex);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public ImageUtility(File imageFile, BufferedImage image)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.imageFile = imageFile;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.image = image;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public File getImageFile()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return imageFile;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public void setImageFile(File imageFile)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.imageFile = imageFile;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public BufferedImage getImage()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return image;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public void setImage(BufferedImage image)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.image = image;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public String getImageExtension()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; String fName = imageFile.getName();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return fName.substring(fName.indexOf(".")+1, fName.length());&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public BufferedImage getResizedCopy(int scaledWidth, int scaledHeight, boolean preserveAlpha)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return getResizedCopyOfImage(image, scaledWidth, scaledHeight, preserveAlpha);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public byte[] getByte()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return getByteOfImage(image);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public ImageIcon getImageIcon()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return new ImageIcon(image);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public BufferedImage getCropedImage(int x, int y, int width, int height)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return getCropedImageOfImage(image, x, y, width, height);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public BufferedImage getCropedImageFromCenter(Dimension panelDimension,int clipedWidth, int clipedHeight)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return getCropedImageOfImageFromCenter(image, panelDimension, clipedWidth, clipedHeight);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public BufferedImage getResizedCopyOfImage(BufferedImage originalImage,int scaledWidth, int scaledHeight, boolean preserveAlpha)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int imageType = preserveAlpha ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BufferedImage scaledBI = new BufferedImage(scaledWidth, scaledHeight, imageType);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Graphics2D g = scaledBI.createGraphics();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (preserveAlpha)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&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; g.setComposite(AlphaComposite.Src);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;     RenderingHints.VALUE_INTERPOLATION_BILINEAR);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;     g.setRenderingHint(RenderingHints.KEY_RENDERING,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;     RenderingHints.VALUE_RENDER_QUALITY);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;     g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;     RenderingHints.VALUE_ANTIALIAS_ON);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; g.drawImage(originalImage, 0, 0, scaledWidth, scaledHeight, null);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; g.dispose();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return scaledBI;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public byte[] getByteOfImage(BufferedImage sourceImage)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; try&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&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; ByteArrayOutputStream baos = new ByteArrayOutputStream();&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; ImageIO.write(sourceImage, getImageExtension(), baos);&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; baos.flush();&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; byte[] imageData = baos.toByteArray();&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; baos.close();&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; return imageData;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; catch (IOException ex)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&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; Exceptions.printStackTrace(ex);&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; return null;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public ImageIcon getImageIconFromImage(BufferedImage sourceImage)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return new ImageIcon(sourceImage);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public BufferedImage&amp;nbsp; getCropedImageOfImage(BufferedImage sourceImage, int x, int y, int width, int height)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return sourceImage.getSubimage(x, y, width, height);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public BufferedImage getCropedImageOfImageFromCenter(BufferedImage sourceImage, Dimension panelDimension,int clipedWidth, int clipedHeight)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Rectangle clip = new Rectangle(clipedWidth, clipedHeight);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; clip.x = (panelDimension.width - clip.width) / 2;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; clip.y = (panelDimension.height - clip.height) / 2;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int x0 = (panelDimension.width - sourceImage.getWidth()) / 2;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int y0 = (panelDimension.height - sourceImage.getHeight()) / 2;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int x = clip.x - x0;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int y = clip.y - y0;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return sourceImage.getSubimage(x, y, clip.width, clip.height);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-71690396949767628?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/71690396949767628/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=71690396949767628' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/71690396949767628'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/71690396949767628'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2011/02/java-image-utility.html' title='Java Image Utility'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-3941225200438629222</id><published>2011-01-31T02:25:00.000-08:00</published><updated>2011-01-31T02:39:20.355-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='Abstract Entities'/><category scheme='http://www.blogger.com/atom/ns#' term='JPA'/><title type='text'>Entity Inheritance Using Abstract Entity</title><content type='html'>In my &lt;a href="http://zawoad.blogspot.com/2011/01/entity-inheritance-using-mapped.html" target="_blank"&gt;previous blog&lt;/a&gt; I shared my code re-factoring experience by using Mapped Superclass. Using Abstract Entity was another interesting experience. In our project there are some Entities like Customer, Vendor which have some common attributes like 'First Name', 'Last Name', etc. These attributes were defined&amp;nbsp; in both Customer and Vendor Class. This approach not only produced code duplication but also column duplication in underlying Datastore. JPA Abstract Entity feature inspires me to use a third Entity Class which is abstract to avoid this duplication.&lt;br /&gt;&lt;br /&gt;Let's see how it works. Suppose you have two Entities Student and Teacher, and they have following attributes&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/_MwOzNujvBcI/TUaAtLXpU4I/AAAAAAAAATU/kg-N0wTo7Iw/s1600/student_teacher.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="110" src="http://1.bp.blogspot.com/_MwOzNujvBcI/TUaAtLXpU4I/AAAAAAAAATU/kg-N0wTo7Iw/s200/student_teacher.png" width="200" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Three attributes are common in this case and you can introduce a Person class which is abstract and has these common properties. Student and Teacher class will extend Person and only have their individual properties.&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_MwOzNujvBcI/TUaB2t9c-vI/AAAAAAAAATY/d5nLqQN8QCg/s1600/person_std_teacher.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="223" src="http://3.bp.blogspot.com/_MwOzNujvBcI/TUaB2t9c-vI/AAAAAAAAATY/d5nLqQN8QCg/s320/person_std_teacher.png" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Your&amp;nbsp; Person, Student and Teacher Entity classes will be like this&lt;br /&gt;&lt;br /&gt;&lt;pre class="java" name="code"&gt;@Entity&lt;br /&gt;@Inheritance(strategy=InheritanceType.JOINED)&lt;br /&gt;@Table(name = "persons")&lt;br /&gt;public abstract class Person implements Serializable {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; private static final long serialVersionUID = 1L;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @Id&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @GeneratedValue(strategy = GenerationType.IDENTITY)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @Basic(optional = false)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @Column(name = "id_nr")&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; protected Long idNr;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @Column(name = "first_name")&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; protected String firstName;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @Column(name = "last_name")&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; protected String lastName;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public Person() {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //getter setter of the properties ....&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="java" name="code"&gt;@Entity&lt;br /&gt;@Table(name = "teachers")&lt;br /&gt;public class Teacher extends Person {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; private static final long serialVersionUID = 1L;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @Column(name = "designation")&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; protected String designation;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // constructor, getter setter of the property....&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="java" name="code"&gt;@Entity&lt;br /&gt;@Table(name = "students")&lt;br /&gt;public class Student extends Person {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; private static final long serialVersionUID = 1L;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; @Column(name = "role_number")&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; protected String roleNumber;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; // constructor, getter setter of the property.... &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;For above scenario three tables will be generated in the database, persons, students and teachers. Mapping strategy of @Inheritance annotation has a great impact in table generation process. As we have used &lt;span id="keyword1"&gt;InheritanceType.JOINED&lt;/span&gt; as the mapping strategy, three different tables are created. If we were using default mapping strategy which is &lt;span id="keyword1"&gt;InheritanceType.SINGLE_TABLE&lt;/span&gt;, only persons table will be created with all the attributes. In both cases Persistence provider will also create a discriminator column in the person table called &lt;span id="keyword1"&gt;DTYPE&lt;/span&gt;, which will store the name of the inherited entity used to create the person.&lt;br /&gt;&lt;br /&gt;Now run the following code and see how data is stored in the database in this design.&lt;br /&gt;&lt;/p&gt;&lt;pre class="java" name="code"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @PersistenceContext(unitName = "TaskBoard-ejbPU")&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; EntityManager em;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Teacher teacher = new Teacher();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; teacher.setFirstName("Sarwar");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; teacher.setLastName("Hossain");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; teacher.setDesignation("Associate Proffessor");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; teacher.setIdNr(null);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; em.persist(teacher);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Student student = new Student();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; student.setFirstName("Shams");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; student.setLastName("Zawoad");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; student.setRoleNumber("001525");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; student.setIdNr(null);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; em.persist(student);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; em.flush();&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/_MwOzNujvBcI/TUaFWnx5p3I/AAAAAAAAATg/yNcLeprdXys/s1600/person_std_teacher_db.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/_MwOzNujvBcI/TUaFWnx5p3I/AAAAAAAAATg/yNcLeprdXys/s1600/person_std_teacher_db.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;If you try with &lt;span id="keyword1"&gt;InheritanceType.SINGLE_TABLE&lt;/span&gt; mapping strategy you will get the following output by running the same code&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/_MwOzNujvBcI/TUaG38p3C5I/AAAAAAAAATk/6125Z7AUoRg/s1600/person_db.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/_MwOzNujvBcI/TUaG38p3C5I/AAAAAAAAATk/6125Z7AUoRg/s1600/person_db.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;p&gt;Attractive feature of abstract entities is that they can be queried just like concrete queries, which were not possible in Mapped Superclass. If an abstract entity is the target of a query, the query operates on all the concrete subclasses of the abstract entity.&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-3941225200438629222?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/3941225200438629222/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=3941225200438629222' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/3941225200438629222'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/3941225200438629222'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2011/01/entity-inheritance-using-abstract.html' title='Entity Inheritance Using Abstract Entity'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_MwOzNujvBcI/TUaAtLXpU4I/AAAAAAAAATU/kg-N0wTo7Iw/s72-c/student_teacher.png' height='72' width='72'/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-3166545378028325699</id><published>2011-01-02T08:10:00.000-08:00</published><updated>2011-01-02T08:19:09.127-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='Mapped Superclass'/><category scheme='http://www.blogger.com/atom/ns#' term='JPA'/><title type='text'>Entity Inheritance Using Mapped Superclass</title><content type='html'>When I engaged myself into code re-factoring of our &lt;a href="http://www.commlinkinfotech.com/showDocument.php?documentid=1084" target="_blank"&gt;VELACORE&lt;/a&gt; project, I found that almost all Entities have four common properties &lt;i&gt;createdBy, creationDate, modifiedBy&lt;/i&gt; and &lt;i&gt;modificationDate&lt;/i&gt;.&amp;nbsp; I wanted to reduce this code duplication and found that JPA is providing Mapped Superclass for this type of requirement where state and mapping information are common to multiple Entity classes. It contains persistent state and mapping information, but is not Entitity. That is, it is not decorated with the @Entity annotation and is not mapped as an entity by JPA.&lt;br /&gt;&lt;br /&gt;&lt;span id="keyword1"&gt;Mapped Superclasses do not have any corresponding tables in the underlying Datastore&lt;/span&gt; (that was also my requirement). Entities that inherit from the mapped Superclass define the table mappings. Mapped superclasses are specified by decorating the class with the &lt;span id="keyword1"&gt;javax.persistence.MappedSuperclass&lt;/span&gt; annotation.&lt;br /&gt;&lt;br /&gt;Here is an example of using Mapped Superclass for entity inheritance&lt;br /&gt;&lt;br /&gt;&lt;pre class="java" name="code"&gt;@MappedSuperclass&lt;br /&gt;public class BaseEntity&lt;br /&gt;{&lt;br /&gt;    @Column(name = "created_by")&lt;br /&gt;    private String createdBy;&lt;br /&gt;    @Temporal(TemporalType.TIMESTAMP)&lt;br /&gt;    @Column(name = "creation_date")&lt;br /&gt;    private Calendar creationDate;&lt;br /&gt;    &lt;br /&gt;   //getter setter of the properties ....&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;@Entity&lt;br /&gt;public class Customer extends BaseEntity &lt;br /&gt;{&lt;br /&gt;    @Column(name = "first_name")&lt;br /&gt;    private String firstName;&lt;br /&gt;&lt;br /&gt;    ...&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;@Entity&lt;br /&gt;public class Invoice extends BaseEntity {&lt;br /&gt;    @Column(name = "invoice_no")&lt;br /&gt;    private String invoiceNo;&lt;br /&gt;&lt;br /&gt;    ...&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;In the above code snippet BaseEntity is the MappedSuperclass which contains the mapping information of the common properties. Customer and Invoice are two Entities extending the BaseEntity. In this scenario only CUSTOMER and INVOICE tables will be created in the database not the BASEENTITY. "created_by" and "creation_date" columns will be present in both CUSTOMER and INVOICE tables.&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;script type="text/javascript"&gt;&lt;!--google_ad_client = "pub-3583615898080871";/* 468x60, created 10/2/09 BELOW POST */google_ad_slot = "5516300168";google_ad_width = 468;google_ad_height = 60;//--&gt;&lt;/script&gt;&lt;script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"&gt;&lt;/script&gt;&lt;/div&gt;&lt;br /&gt;&lt;span id="keyword1"&gt;Limitations of using Mapped Superclass :&lt;/span&gt;&lt;br /&gt;-Mapped Superclasses are not queryable, and can’t be used in EntityManager or Query operations.&lt;br /&gt;-Mapped Superclasses can’t be targets of entity relationships.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-3166545378028325699?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/3166545378028325699/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=3166545378028325699' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/3166545378028325699'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/3166545378028325699'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2011/01/entity-inheritance-using-mapped.html' title='Entity Inheritance Using Mapped Superclass'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-5046327500063071508</id><published>2010-12-29T00:53:00.000-08:00</published><updated>2010-12-29T00:59:47.097-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='reCAPTCHA'/><title type='text'>Protect Your Java Application by reCAPTCHA</title><content type='html'>4 months gone since I have post my last blog. Got a very encouraging feedback from my readers in this period but can't manage to write anything. Now feeling glad to start writing again. Hope java developers will find this tutorial useful to protect their application using reCaptcha, a widely used CAPTCHA system in the industry.&lt;br /&gt;&lt;br /&gt;First go to the &lt;a target = "_blank" href="http://www.google.com/recaptcha/whyrecaptcha"&gt;reCAPTCHA website&lt;/a&gt; and create your reCAPTCHA key by providing the domain name of your application. You will get two keys one is Private and another is Public. Public key will be used in the JavaScript code that is served to your users. Private key is required to communicate between your server and the reCAPTCHA server. Be sure to keep the Private key secret.&lt;br /&gt;&lt;br /&gt;Now download the &lt;a target = "_blank" href="http://code.google.com/p/recaptcha/downloads/list?q=label:java-Latest"&gt;recaptcha4j &lt;/a&gt;library from &lt;a href="http://code.google.com/p/recaptcha/downloads/list?q=label:java-Latest" target = "_blank"&gt;here&lt;/a&gt;. And place the jar file in &lt;span id="keyword1"&gt;WEB-INF/lib/&lt;/span&gt; directory. It will make your life easy to display the reCAPTCHA widget, send the user request to reCAPTCHA server and get response from there.&lt;br /&gt;&lt;br /&gt;You are now ready to use reCAPTCHA in your application. First import the required classes in your JSP page.&lt;br /&gt;&lt;pre class="html" name="code"&gt;&amp;lt;%@ page import="net.tanesha.recaptcha.ReCaptcha" %&amp;gt;&lt;br /&gt;&amp;lt;%@ page import="net.tanesha.recaptcha.ReCaptchaFactory" %&amp;gt;&lt;br /&gt;&lt;/pre&gt;Now add the following code in the web page, where you want to put the reCAPTCHA box. Target of using reCAPTCHA is to protect form submission so place this between the form beginning and ending tags.&lt;br /&gt;&lt;pre class="html" name="code"&gt;&amp;lt;%&lt;br /&gt;ReCaptcha c = ReCaptchaFactory.newReCaptcha("your_public_key", "your_private_key", false);&lt;br /&gt;          out.print(c.createRecaptchaHtml(null, null));&lt;br /&gt;%&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;First line of the code will create an instance of reCAPTCHA. Second line will generate and display a reCAPTCHA widget in your page.&lt;br /&gt;&lt;br /&gt;Now come to the server side where you have to validate the submitted form with the reCAPTCHA server.&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;script type="text/javascript"&gt;&lt;!--google_ad_client = "pub-3583615898080871";/* 468x60, created 10/2/09 BELOW POST */google_ad_slot = "5516300168";google_ad_width = 468;google_ad_height = 60;//--&gt;&lt;/script&gt;&lt;script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"&gt;&lt;/script&gt;&lt;/div&gt;&lt;br /&gt;Here is a simple servlet which is used to do the validation job.&lt;br /&gt;&lt;pre class="java" name="code"&gt;import net.tanesha.recaptcha.ReCaptchaImpl;&lt;br /&gt;import net.tanesha.recaptcha.ReCaptchaResponse;&lt;br /&gt;&lt;br /&gt;public class GreetingServlet extends HttpServlet &lt;br /&gt;{&lt;br /&gt;    public void doPost(HttpServletRequest req, HttpServletResponse resp)&lt;br /&gt;            throws IOException {&lt;br /&gt;&lt;br /&gt;        String challenge = req.getParameter("recaptcha_challenge_field");&lt;br /&gt;        String response = req.getParameter("recaptcha_response_field");&lt;br /&gt;        &lt;br /&gt;        String remoteAddr = req.getRemoteAddr();&lt;br /&gt;&lt;br /&gt;        ReCaptchaImpl reCaptcha = new ReCaptchaImpl();&lt;br /&gt;        reCaptcha.setPrivateKey("[write your privatekey here]");&lt;br /&gt;&lt;br /&gt;        ReCaptchaResponse reCaptchaResponse =&lt;br /&gt;                reCaptcha.checkAnswer(remoteAddr, challenge, response);&lt;br /&gt;&lt;br /&gt;        if (reCaptchaResponse.isValid()) {&lt;br /&gt;            //valid do something whatever you want to do&lt;br /&gt;        } &lt;br /&gt;        else&lt;br /&gt;        {&lt;br /&gt;            //not valid do something like send error message to user&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span id="keyword1"&gt;remoteAddr&lt;/span&gt; is the user's IP address which is passed to the reCAPTCHA servers. &lt;span id="keyword1"&gt;response&lt;/span&gt; contains the user's answer to the reCAPTCHA challenge.&lt;br /&gt;&lt;br /&gt;You are done. Visit this &lt;a target = "_blank" href="http://zawoad.appspot.com/index.jsp?documentID=600"&gt;link &lt;/a&gt;to get an example of how it works.&lt;br /&gt;&lt;a target = "_blank" href="http://code.google.com/apis/recaptcha/docs/java.html"&gt;Reference link&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-5046327500063071508?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/5046327500063071508/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=5046327500063071508' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/5046327500063071508'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/5046327500063071508'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2010/12/protect-your-java-application-by.html' title='Protect Your Java Application by reCAPTCHA'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-4256292475526037574</id><published>2010-08-05T03:50:00.000-07:00</published><updated>2010-08-05T03:50:46.665-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ext GWT'/><category scheme='http://www.blogger.com/atom/ns#' term='Ext GWT DnD Framework'/><category scheme='http://www.blogger.com/atom/ns#' term='gxt'/><title type='text'>Working with DnD Framework of Ext GWT (GXT) : A Basic Example of Drag and Drop</title><content type='html'>DnD framework of Ext GWT is extremely powerful framework which supports drag and drop between two container, list view, grid, tree panel, tree grid and more over between heterogeneous components like list view to grid or grid to tree panel, etc. Here I am going to describe how you can drag a Html component and drop to a container.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://zawoad.blogspot.com/2009/06/getting-started-with-gwt-create-your.html" target="_blank"&gt;Create a new project&lt;/a&gt;&amp;nbsp;named &lt;i&gt;BasicDnDExample  &lt;/i&gt;and&amp;nbsp;&lt;a href="http://zawoad.blogspot.com/2009/06/how-to-use-ext-gwt-in-eclipse-34-to.html" target="_blank"&gt;add GXT library&lt;/a&gt;&amp;nbsp;in the project. Now go to the&amp;nbsp;&lt;span id="keyword1"&gt;onModuleLoad&lt;/span&gt;&amp;nbsp;method of &lt;i&gt;BasicDnDExample  &lt;/i&gt;class and remove all the auto generated code of this method.&lt;br /&gt;First create a HorizontalPanel&amp;nbsp; and a LayoutContainer as the source container. Then add source components to the source container.&lt;br /&gt;&lt;br /&gt;&lt;pre class="java" name="code"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; HorizontalPanel hp = new HorizontalPanel();&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;hp.setSpacing(10);&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;final LayoutContainer sourceContainer = new LayoutContainer();&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;sourceContainer.setLayoutOnChange(true);&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;sourceContainer.setWidth(300);&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;List&amp;lt;Employee&amp;gt; employeeList = TestData.getEmployees();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;for(Employee employee : employeeList)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;final Html html = new Html("&amp;lt;div style=\"font-size:11px; border: 1px solid #DDDDDD;float:left;margin:4px 0 4px&amp;nbsp; 4px; padding:2px;width:220px;\"&amp;gt;"+&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "&amp;lt;div style=\"color:#1C3C78;font-weight:bold;padding-bottom:5px;padding-top:2px;text-decoration:underline;\"&amp;gt;"+employee.getName()+"&amp;lt;/div&amp;gt;"+ &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "&amp;lt;div style=\"color:green\"&amp;gt;Department:"+employee.getDepartment()+"&amp;lt;/div&amp;gt;"+ &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "&amp;lt;div style=\"color:blue\"&amp;gt;Designation:"+employee.getDesignation()+"&amp;lt;/div&amp;gt;"+&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "&amp;lt;div style=\"color:black;padding-bottom:2px;\"&amp;gt;Salary:"+employee.getSalary()+"&amp;lt;/div&amp;gt;"+ &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; "&amp;lt;/div&amp;gt;" ); &lt;br /&gt; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;sourceContainer.add(html, new FlowData(3));&amp;nbsp; &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; &lt;br /&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DragSource source = new DragSource(html) {&amp;nbsp; &lt;br /&gt;     &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @Override&amp;nbsp; &lt;br /&gt;     &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; protected void onDragStart(DNDEvent event) {&amp;nbsp; &lt;br /&gt;     &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; event.setData(html);&amp;nbsp; &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; event.getStatus().update(El.fly(html.getElement()).cloneNode(true));&amp;nbsp; &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; &lt;br /&gt;  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; };&amp;nbsp; &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; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Using the employee list I have created a &lt;i&gt;Html &lt;/i&gt;component for each employee and add this to the source container. Then create &lt;i&gt;DragSource &lt;/i&gt;with the component and set this as the Data of the &lt;i&gt;DNDEvent&lt;/i&gt;.&amp;nbsp; You will find the code of Empoyee and TestData classes &lt;a href="http://zawoad.blogspot.com/2009/08/how-to-create-simple-grid-using-gxtext.html" target="_blank"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now create another &lt;i&gt;LayoutContainer &lt;/i&gt;as the target container. Then create a &lt;i&gt;DropTarget &lt;/i&gt;from the target container,&amp;nbsp; which identifies components that can receive data from a drag and drop operations. While the cursor is over a target, the target is responsible for determining if the drop is valid and showing any visual indicators for the drop.&lt;br /&gt;&lt;br /&gt;&lt;pre class="java" name="code"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; final LayoutContainer targetContainer = new LayoutContainer();&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; targetContainer.setLayoutOnChange(true);&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; targetContainer.setBorders(true);&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; targetContainer.setSize(300, 500); &lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; DropTarget target = new DropTarget(targetContainer) {&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @Override&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; protected void onDragDrop(DNDEvent event) {&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; super.onDragDrop(event);&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Html html = event.getData();&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;  &amp;nbsp;&amp;nbsp;&amp;nbsp; targetContainer.add(html);&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; }&amp;nbsp; &lt;br /&gt;&amp;nbsp; };&amp;nbsp; &lt;br /&gt;&amp;nbsp; target.setOverStyle("drag-ok");&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;In the &lt;i&gt;onDragDrop &lt;/i&gt;method you can define what you want to do after the element is dropped on the target. Here I have got the Html component from the DNDEvent and added the component in the target container.&lt;br /&gt;Finally add the source and target container in the HorizontalPanel.&lt;br /&gt;&lt;br /&gt;&lt;pre class="java" name="code"&gt;&amp;nbsp; hp.add(targetContainer);&amp;nbsp; &lt;br /&gt;&amp;nbsp; hp.add(sourceContainer);&amp;nbsp; &lt;br /&gt;&amp;nbsp; RootPanel.get().add(hp);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Output of this tutorial will be like this&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_MwOzNujvBcI/TFqUhDAGleI/AAAAAAAAAQQ/mjvEfT35mw4/s1600/basicDnD.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="328" src="http://3.bp.blogspot.com/_MwOzNujvBcI/TFqUhDAGleI/AAAAAAAAAQQ/mjvEfT35mw4/s400/basicDnD.png" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;script type="text/javascript"&gt;&lt;!--google_ad_client = "pub-3583615898080871";/* 468x60, created 10/2/09 BELOW POST */google_ad_slot = "5516300168";google_ad_width = 468;google_ad_height = 60;//--&gt;&lt;/script&gt;&lt;script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"&gt;&lt;/script&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-4256292475526037574?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/4256292475526037574/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=4256292475526037574' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/4256292475526037574'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/4256292475526037574'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2010/08/working-with-dnd-framework-of-ext-gwt.html' title='Working with DnD Framework of Ext GWT (GXT) : A Basic Example of Drag and Drop'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_MwOzNujvBcI/TFqUhDAGleI/AAAAAAAAAQQ/mjvEfT35mw4/s72-c/basicDnD.png' height='72' width='72'/><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-8495146390492191084</id><published>2010-07-16T22:21:00.000-07:00</published><updated>2011-08-11T19:58:08.050-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ext GWT'/><category scheme='http://www.blogger.com/atom/ns#' term='Remote pagination'/><category scheme='http://www.blogger.com/atom/ns#' term='gxt'/><category scheme='http://www.blogger.com/atom/ns#' term='Grid'/><title type='text'>Working with GXT Grid : Add Remote Pagination Functionality</title><content type='html'>As promised previously today I am going write about adding remote pagination functionality with GXT Grid which was one of most demanded one from my readers. In my &lt;a href="http://zawoad.blogspot.com/2010/06/google-app-engine-jdo-and-gxtext-gwt.html"&gt;previous blog&lt;/a&gt; I have described in detail how you can load data from a remote data store and show them in GXT Grid. In this writing the same &lt;i&gt;&lt;span id="keyword1"&gt;Comments&lt;/span&gt;&lt;/i&gt; entity and &lt;i&gt;&lt;span id="keyword1"&gt;CommentModel&lt;/span&gt; &lt;/i&gt;are used to represent data. You will find the code of these classes &lt;a href="http://zawoad.blogspot.com/2010/06/google-app-engine-jdo-and-gxtext-gwt.html"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;At first in the implementation of your GWT RPC Service add a method to load all the comments from the data store.&lt;br /&gt;&lt;pre class="java" name="code"&gt;public List&amp;lt;Commentmodel&amp;gt; getAllComment()&amp;nbsp;&lt;br /&gt;{&lt;br /&gt;   List&amp;lt;Commentmodel&amp;gt; commentList = new ArrayList&amp;lt;Commentmodel&amp;gt;();&lt;br /&gt;   PersistenceManager pm = PMF.get().getPersistenceManager();&amp;nbsp;&lt;br /&gt;   try {&lt;br /&gt;      String query = "select from " + Comments.class.getName()+" order by  postedDate desc";&amp;nbsp;&lt;br /&gt;      List&amp;lt;Comments&amp;gt; list = (List&amp;lt;Comments&amp;gt;) pm.newQuery(query).execute();&lt;br /&gt;      if (!list.isEmpty()) {&lt;br /&gt;         for (Comments c : list)&lt;br /&gt;         {&lt;br /&gt;            //convert from entity object to DTO&lt;br /&gt;            commentList.add(CommentConverter.entityToModel(c));&lt;br /&gt;         }&lt;br /&gt;      }&lt;br /&gt;   }catch (Exception ex) {}&lt;br /&gt;   finally {&lt;br /&gt;      pm.close();&lt;br /&gt;   }&lt;br /&gt;   return commentList;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now add a method &lt;i&gt;&lt;span id="keyword1"&gt;public PagingLoadResult&amp;lt;Commentmodel&amp;gt; getComments(PagingLoadConfig config)&lt;/span&gt;&lt;/i&gt; in your service which takes a &lt;i&gt;PagingLoadConfig &lt;/i&gt;object to determine the limit and offset value of the request and returns the desired list for the paging loader. Here is the implementation of the method.&lt;br /&gt;&lt;pre class="java" name="code"&gt;@Override&lt;br /&gt;public PagingLoadResult&amp;lt;Commentmodel&amp;gt; getComments(PagingLoadConfig config) {&lt;br /&gt;&lt;br /&gt;//comments is a private variable of the service implementation class&lt;br /&gt;//private List&amp;lt;Commentmodel&amp;gt; comments;&lt;br /&gt;comments = getAllComment();&lt;br /&gt;&lt;br /&gt;//get all the comments from the data store&lt;br /&gt;//and sort this list according to sorting info&lt;br /&gt;&lt;br /&gt;if (config.getSortInfo().getSortField() != null) {&lt;br /&gt;final String sortField = config.getSortInfo().getSortField();&lt;br /&gt;if (sortField != null) {&lt;br /&gt;Collections.sort(comments, config.getSortInfo().getSortDir().comparator(new Comparator&amp;lt;Commentmodel&amp;gt;() {&lt;br /&gt;public int compare(CommentModel c1, CommentModel c2) {&lt;br /&gt;if (sortField.equals("comments")) {&lt;br /&gt;return c1.getComments().compareTo(c2.getComments());&lt;br /&gt;} else if (sortField.equals("postedBy")) {&lt;br /&gt;return c1.getPostedBy().compareTo(c2.getPostedBy());&lt;br /&gt;} else if (sortField.equals("postedDate")) {&lt;br /&gt;return c1.getStartingDate().compareTo(c2.getStartingDate());&lt;br /&gt;}&lt;br /&gt;return 0;&lt;br /&gt;}&lt;br /&gt;}));&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;//Create a sublist and add data to list according&lt;br /&gt;//to the limit and offset value of the config&lt;br /&gt;&lt;br /&gt;ArrayList&amp;lt;Commentmodel&amp;gt; sublist = new ArrayList&amp;lt;Commentmodel&amp;gt;();&lt;br /&gt;int start = config.getOffset();&lt;br /&gt;int limit = comments.size();&lt;br /&gt;if (config.getLimit() &amp;gt; 0) {&lt;br /&gt;limit = Math.min(start + config.getLimit(), limit);&lt;br /&gt;}&lt;br /&gt;for (int i = config.getOffset(); i &amp;lt; limit; i++) {         sublist.add(comments.get(i));       }       &lt;br /&gt;return new BasePagingLoadResult&amp;lt;Commentmodel&amp;gt;&lt;br /&gt;(sublist, config.getOffset(), comments.size());&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Your server side coding is done. Let's come to client side coding and see how to use this service to add remote pagination functionality with GXT Grid.&lt;br /&gt;&lt;br /&gt;First create a &lt;i&gt;&lt;span id="keyword1"&gt;RpcProxy&lt;/span&gt; &lt;/i&gt;object, &lt;i&gt;proxy &lt;/i&gt;to make RPC call using the load configuration. With the &lt;i&gt;proxy&lt;/i&gt; object create a &lt;i&gt;&lt;span id="keyword1"&gt;PagingLoader&lt;/span&gt;, loader&lt;/i&gt; which is required to load page enabled set of data and enable the remote sorting attribute of the &lt;i&gt;loader&lt;/i&gt;.&lt;br /&gt;&lt;br /&gt;&lt;pre class="java" name="code"&gt;RpcProxy&amp;lt;PagingLoadResult&amp;lt;CommentModel&amp;gt;&amp;gt; proxy = new RpcProxy&amp;lt;PagingLoadResult&amp;lt;CommentModel&amp;gt;&amp;gt;() {&lt;br /&gt;@Override&lt;br /&gt;public void load(Object loadConfig,&lt;br /&gt;AsyncCallback&amp;lt;PagingLoadResult&amp;lt;CommentModel&amp;gt;&amp;gt; callback) {&lt;br /&gt;Gxtexamplegalary.greetingService.getComments(&lt;br /&gt;(PagingLoadConfig) loadConfig, callback);&lt;br /&gt;}&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;// loader&lt;br /&gt;final PagingLoader&amp;lt;PagingLoadResult&amp;lt;ModelData&amp;gt;&amp;gt; loader = new BasePagingLoader&amp;lt;PagingLoadResult&amp;lt;ModelData&amp;gt;&amp;gt;(&lt;br /&gt;proxy);&lt;br /&gt;loader.setRemoteSort(true);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now use this &lt;i&gt;loader &lt;/i&gt;to create a &lt;i&gt;ListStore &lt;/i&gt;of &lt;i&gt;CommentModel&lt;/i&gt;&amp;nbsp; and bind the &lt;i&gt;loader &lt;/i&gt;with a &lt;i&gt;PagingToolBar. &lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="java" name="code"&gt;ListStore&amp;lt;CommentModel&amp;gt; commentList = new ListStore&amp;lt;CommentModel&amp;gt;(loader);&lt;br /&gt;&lt;br /&gt;final PagingToolBar toolBar = new PagingToolBar(3);&lt;br /&gt;toolBar.bind(loader);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Create a List of &lt;i&gt;ColumnConfig&lt;/i&gt;&lt;i&gt;&amp;nbsp; &lt;/i&gt;and a &lt;i&gt;ColumnModel&lt;/i&gt; from the ColumnConfig list. &lt;br /&gt;&lt;br /&gt;&lt;pre class="java" name="code"&gt;List&amp;lt;ColumnConfig&amp;gt; configs = new ArrayList&amp;lt;ColumnConfig&amp;gt;();&lt;br /&gt;ColumnConfig column = new ColumnConfig();&lt;br /&gt;column.setId("comments");&lt;br /&gt;column.setHeader("Comments");&lt;br /&gt;column.setWidth(200);&lt;br /&gt;configs.add(column);&lt;br /&gt;&lt;br /&gt;column = new ColumnConfig("postedBy", "Posted By", 150);&lt;br /&gt;column.setAlignment(HorizontalAlignment.LEFT);&lt;br /&gt;configs.add(column);&lt;br /&gt;&lt;br /&gt;column = new ColumnConfig("postedDate", "Posting Date", 100);&lt;br /&gt;column.setAlignment(HorizontalAlignment.RIGHT);&lt;br /&gt;column.setDateTimeFormat(DateTimeFormat.getShortDateFormat());&lt;br /&gt;configs.add(column);&lt;br /&gt;&lt;br /&gt;ColumnModel cm = new ColumnModel(configs);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Finally create a Grid with the &lt;i&gt;commentList &lt;/i&gt;and the column model. Add a Listener with the Grid to handle the remote pagination functionality. In the &lt;i&gt;handleEvent &lt;/i&gt;method of the Listener first create a &lt;i&gt;&lt;span id="keyword1"&gt;PagingLoadConfig&lt;/span&gt;&lt;/i&gt;, &lt;i&gt;config&lt;/i&gt; and set offset, limit, sort field and sort direction value of the &lt;i&gt;config&lt;/i&gt;. Then load data by the &lt;i&gt;loader&lt;/i&gt; with this configuration.&lt;br /&gt;&lt;pre class="java" name="code"&gt;final Grid&amp;lt;CommentModel&amp;gt; grid = new Grid&amp;lt;CommentModel&amp;gt;(commentList, cm);&lt;br /&gt;grid.setStateId("pagingGridExample");&lt;br /&gt;grid.setStateful(true);&lt;br /&gt;grid.addListener(Events.Attach, new Listener&amp;lt;GridEvent&amp;lt;CommentModel&amp;gt;&amp;gt;() {&lt;br /&gt;public void handleEvent(GridEvent&amp;lt;CommentModel&amp;gt; be) {&lt;br /&gt;PagingLoadConfig config = new BasePagingLoadConfig();&lt;br /&gt;config.setOffset(0);&lt;br /&gt;config.setLimit(3);&lt;br /&gt;&lt;br /&gt;Map&amp;lt;String, Object&amp;gt; state = grid.getState();&lt;br /&gt;if (state.containsKey("offset")) {&lt;br /&gt;int offset = (Integer) state.get("offset");&lt;br /&gt;int limit = (Integer) state.get("limit");&lt;br /&gt;config.setOffset(offset);&lt;br /&gt;config.setLimit(limit);&lt;br /&gt;}&lt;br /&gt;if (state.containsKey("sortField")) {&lt;br /&gt;config.setSortField((String) state.get("sortField"));&lt;br /&gt;config.setSortDir(SortDir.valueOf((String) state&lt;br /&gt;.get("sortDir")));&lt;br /&gt;}&lt;br /&gt;loader.load(config);&lt;br /&gt;}&lt;br /&gt;});&lt;br /&gt;grid.setLoadMask(true);&lt;br /&gt;grid.setBorders(true);&lt;br /&gt;grid.setAutoExpandColumn("comments");&lt;br /&gt;grid.setStyleAttribute("borderTop", "none");&lt;br /&gt;grid.setStripeRows(true);&lt;br /&gt;&lt;br /&gt;ContentPanel cp = new ContentPanel();&lt;br /&gt;cp.setBodyBorder(false);&lt;br /&gt;cp.setHeading("Grid with Pagination");&lt;br /&gt;cp.setButtonAlign(HorizontalAlignment.CENTER);&lt;br /&gt;cp.setLayout(new FitLayout());&lt;br /&gt;cp.setSize(700, 300);&lt;br /&gt;cp.add(grid);&lt;br /&gt;cp.setBottomComponent(toolBar);&lt;br /&gt;RootPanel.get().add(cp);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;That's all for today. Enjoy GWT and GXT :-) &lt;br /&gt;&lt;div&gt;&lt;script type="text/javascript"&gt;&lt;!--google_ad_client = "pub-3583615898080871";/* 468x60, created 10/2/09 BELOW POST */google_ad_slot = "5516300168";google_ad_width = 468;google_ad_height = 60;//--&gt;&lt;/script&gt;&lt;script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"&gt;&lt;/script&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-8495146390492191084?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/8495146390492191084/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=8495146390492191084' title='17 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/8495146390492191084'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/8495146390492191084'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2010/07/working-with-gxt-grid-add-remote.html' title='Working with GXT Grid : Add Remote Pagination Functionality'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><thr:total>17</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-7490333537146336733</id><published>2010-06-03T01:13:00.000-07:00</published><updated>2010-06-17T10:20:40.191-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JDO'/><category scheme='http://www.blogger.com/atom/ns#' term='GWT'/><category scheme='http://www.blogger.com/atom/ns#' term='Google App Engine'/><category scheme='http://www.blogger.com/atom/ns#' term='Ext GWT'/><category scheme='http://www.blogger.com/atom/ns#' term='Grid'/><title type='text'>Google App Engine, JDO and GXT(Ext GWT) Grid -  Make All These Working Together</title><content type='html'>Previously I have written some blogs about GXT Grid&amp;nbsp; where the data resides in the client side. But as per the request of my readers I feel the necessity of writing some tutorials with remote data store. And for this purpose I have chosen Google App Engine data store as the back-end with JDO implementation.&lt;br /&gt;&lt;br /&gt;It requires a configuration file in the final WAR named&amp;nbsp; &lt;i&gt;&lt;b&gt;jdoconfig.xml &lt;/b&gt;&lt;/i&gt; which resides in the directory &lt;i&gt;war/WEB-INF/classes/META-INF/&lt;/i&gt;. Eclipse creates this file as &lt;i&gt;src/META-INF/jdoconfig.xml&lt;/i&gt;. This file is automatically copied into &lt;i&gt;war/WEB-INF/classes/META-INF/&lt;/i&gt; when you build your project. This file should contain the following contains.&lt;br /&gt;&lt;br /&gt;&lt;pre class="xml" name="code"&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;&lt;br /&gt;&amp;lt;jdoconfig xmlns="http://java.sun.com/xml/ns/jdo/jdoconfig"&lt;br /&gt;   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&lt;br /&gt;   xsi:noNamespaceSchemaLocation="http://java.sun.com/xml/ns/jdo/jdoconfig"&amp;gt;&lt;br /&gt;&lt;br /&gt;   &amp;lt;persistence-manager-factory name="transactions-optional"&amp;gt;&lt;br /&gt;       &amp;lt;property name="javax.jdo.PersistenceManagerFactoryClass"&lt;br /&gt;           value="org.datanucleus.store.appengine.jdo.DatastoreJDOPersistenceManagerFactory"/&amp;gt;&lt;br /&gt;       &amp;lt;property name="javax.jdo.option.ConnectionURL" value="appengine"/&amp;gt;&lt;br /&gt;       &amp;lt;property name="javax.jdo.option.NontransactionalRead" value="true"/&amp;gt;&lt;br /&gt;       &amp;lt;property name="javax.jdo.option.NontransactionalWrite" value="true"/&amp;gt;&lt;br /&gt;       &amp;lt;property name="javax.jdo.option.RetainValues" value="true"/&amp;gt;&lt;br /&gt;       &amp;lt;property name="datanucleus.appengine.autoCreateDatastoreTxns" value="true"/&amp;gt;&lt;br /&gt;   &amp;lt;/persistence-manager-factory&amp;gt;&lt;br /&gt;&amp;lt;/jdoconfig&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Here I am going to describe the way of loading a comment list from the App Engine data store and making the list viewable in the GXT Grid. So At first I need a POJO class to store and retrieve comments from the App Engine data store using the JDO API. Here is my &lt;i&gt;&lt;b&gt;Comments &lt;/b&gt;&lt;/i&gt;class.&lt;br /&gt;&lt;br /&gt;&lt;pre class="java" name="code"&gt;@PersistenceCapable(identityType = IdentityType.APPLICATION)&lt;br /&gt;public class Comments {&lt;br /&gt;    @PrimaryKey&lt;br /&gt;    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)&lt;br /&gt;    private Long id;&lt;br /&gt;&lt;br /&gt;    @Persistent&lt;br /&gt;    @Column(name="comments")&lt;br /&gt;    private String comments;&lt;br /&gt;&lt;br /&gt;    @Persistent&lt;br /&gt;    @Column(name="posted_by")&lt;br /&gt;    private String postedBy;&lt;br /&gt;    &lt;br /&gt;    @Persistent&lt;br /&gt;    @Column(name="posted_date")&lt;br /&gt;    private Date postedDate;&lt;br /&gt;&lt;br /&gt;    public Comments(String comments, String postedBy, Date date) {&lt;br /&gt;        this.comments = comments;&lt;br /&gt;        this.postedDate = date;&lt;br /&gt;        this.postedBy = postedBy;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;    public Long getId() {&lt;br /&gt;        return id;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt; public String getComments() {&lt;br /&gt;  return comments;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public void setComments(String comments) {&lt;br /&gt;  this.comments = comments;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public Date getPostedDate() {&lt;br /&gt;  return postedDate;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public void setPostedDate(Date postedDate) {&lt;br /&gt;  this.postedDate = postedDate;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public void setId(Long id) {&lt;br /&gt;  this.id = id;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public String getPostedBy() {&lt;br /&gt;  return postedBy;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public void setPostedBy(String postedBy) {&lt;br /&gt;  this.postedBy = postedBy;&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now when you want to transfer data from server to client you need a DTO (Data Transfer Object). As I am going to show the comments in GXT Grid so my DTO has to inherit the properties of GXT's &lt;i&gt;&lt;span id="keyword1"&gt;BaseModel&lt;/span&gt;&lt;/i&gt;. Here is the &lt;b&gt;CommentModel &lt;/b&gt;class which will serve my purposes.&lt;br /&gt;&lt;br /&gt;&lt;pre class="java" name="code"&gt;public class CommentModel extends BaseModel {&lt;br /&gt;&lt;br /&gt;private static final long serialVersionUID = 1L;&lt;br /&gt;&lt;br /&gt;public CommentModel(){}&lt;br /&gt;&lt;br /&gt;public CommentModel(String comments, String postedBy, Date date) {&lt;br /&gt;set("comments", comments);&lt;br /&gt;set("postedDate", date);&lt;br /&gt;set("postedBy",postedBy);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public String getComments() {&lt;br /&gt;return (String) get("comments");&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public String getPostedBy() {&lt;br /&gt;return (String) get("postedBy");&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public Date getStartingDate() {&lt;br /&gt;return ((Date) get("postedDate"));&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;For any operation on data store you have to request the data store for the desired operation. Each request that uses the data store creates a new instance of the &lt;i&gt;&lt;span id="keyword1"&gt;PersistenceManager &lt;/span&gt;&lt;/i&gt;class through the instance of&amp;nbsp; &lt;i&gt;&lt;span id="keyword1"&gt;PersistenceManagerFactory&lt;/span&gt;&lt;/i&gt; class. As creating an instance of &lt;i&gt;PersistenceManagerFactory&lt;/i&gt; class is a very costly process, I have used a Singleton class &lt;i&gt;&lt;b&gt;PMF&lt;/b&gt;&lt;/i&gt; for this purpose.&lt;br /&gt;&lt;br /&gt;&lt;pre class="java" name="code"&gt;public final class PMF {&lt;br /&gt;private static final PersistenceManagerFactory pmfInstance =&lt;br /&gt;JDOHelper.getPersistenceManagerFactory("transactions-optional");&lt;br /&gt;&lt;br /&gt;private PMF() {}&lt;br /&gt;&lt;br /&gt;public static PersistenceManagerFactory get() {&lt;br /&gt;return pmfInstance;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;If you are familiar with GWT RPC Service then create a service named &lt;i&gt;&lt;span id="keyword1"&gt;CommentService&lt;/span&gt;&lt;/i&gt; and add a method &lt;br /&gt;&lt;i&gt;&lt;span id="keyword1"&gt;List&amp;lt;CommentModel&amp;gt; getAllComment();&lt;/span&gt;&lt;/i&gt;. Here is the implementation of the method where JDOQL is used to write a query which returns all the comments from the data store.&lt;br /&gt;&lt;br /&gt;&lt;pre class="java" name="code"&gt;public List&amp;lt;Commentmodel&amp;gt; getAllComment()&amp;nbsp;&lt;br /&gt;{&lt;br /&gt;   List&amp;lt;Commentmodel&amp;gt; commentList = new ArrayList&amp;lt;Commentmodel&amp;gt;();&lt;br /&gt;   PersistenceManager pm = PMF.get().getPersistenceManager();&amp;nbsp;&lt;br /&gt;   try {&lt;br /&gt;      String query = "select from " + Comments.class.getName()+" order by  postedDate desc";&amp;nbsp;&lt;br /&gt;      List&amp;lt;Comments&amp;gt; list = (List&amp;lt;Comments&amp;gt;) pm.newQuery(query).execute();&lt;br /&gt;      if (!list.isEmpty()) {&lt;br /&gt;         for (Comments c : list)&lt;br /&gt;         {&lt;br /&gt;            //convert from entity object to DTO&lt;br /&gt;            commentList.add(CommentConverter.entityToModel(c));&lt;br /&gt;         }&lt;br /&gt;      }&lt;br /&gt;   }catch (Exception ex) {}&lt;br /&gt;   finally {&lt;br /&gt;      pm.close();&lt;br /&gt;   }&lt;br /&gt;   return commentList;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;i&gt;&lt;b&gt;CommentConverter&lt;/b&gt;&lt;/i&gt; is a utility class which converts an object of &lt;i&gt;Comments&lt;/i&gt; class to an object of &lt;i&gt;CommentModel&lt;/i&gt; class.&lt;br /&gt;&lt;br /&gt;&lt;pre class="java" name="code"&gt;public class CommentConverter &lt;br /&gt;{&lt;br /&gt;   public static CommentModel entityToModel(Comments comment)&lt;br /&gt;   {&lt;br /&gt;      CommentModel model = new CommentModel(comment.getComments(), comment.getPostedBy(), comment.getPostedDate());&lt;br /&gt;      return model;&lt;br /&gt;   }&lt;br /&gt;}&amp;nbsp;&lt;/pre&gt;&lt;br /&gt;All the server side coding is done. Let's come to client side.&lt;br /&gt;&lt;br /&gt;First create an instance of &lt;i&gt;CommentServiceAsync&lt;/i&gt;.&lt;br /&gt;&lt;pre class="java" name="code"&gt;public static final CommentServiceAsync commentService = GWT.create(CommentService.class);&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Then create a ListStore of CommentModel, &lt;i&gt;commentStore &lt;/i&gt;and call the &lt;i&gt;getAllComment &lt;/i&gt;method of the &lt;i&gt;commentService&lt;/i&gt;. In the &lt;i&gt;onSuccess &lt;/i&gt;method add the returned list to the &lt;i&gt;commentStore. &lt;/i&gt;&lt;br /&gt;&lt;pre class="java" name="code"&gt;&amp;nbsp;final Label lbError = new Label();&lt;br /&gt;  final ListStore&amp;lt;Commentmodel&amp;gt; commentStore = new ListStore&amp;lt;Commentmodel&amp;gt;();&lt;br /&gt;  commentService.getAllComment(new AsyncCallback&amp;lt;List&amp;lt;Commentmodel&amp;gt;&amp;gt;() {&lt;br /&gt;&lt;br /&gt;   @Override&lt;br /&gt;   public void onFailure(Throwable caught) {&lt;br /&gt;    lbError.setText("data loading failure");&lt;br /&gt;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   @Override&lt;br /&gt;   public void onSuccess(List&amp;lt;Commentmodel&amp;gt; result) {&lt;br /&gt;    commentStore.add(result);&lt;br /&gt;&lt;br /&gt;   }&lt;br /&gt;  });&amp;nbsp;&lt;/pre&gt;&lt;br /&gt;The rest of the tasks are very familiar with the GXT users. Creating a List of ColumnConfig, a Grid with the commentStore and&amp;nbsp; ColumnConfig lists, etc.&lt;br /&gt;&lt;br /&gt;&lt;pre class="java" name="code"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; List&amp;lt;Columnconfig&amp;gt; configs = new ArrayList&amp;lt;Columnconfig&amp;gt;();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ColumnConfig column = new ColumnConfig();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; column.setId("comments");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; column.setHeader("Comments");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; column.setWidth(200);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; configs.add(column);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; column = new ColumnConfig("postedBy", "Posted By", 150);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; column.setAlignment(HorizontalAlignment.LEFT);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; configs.add(column);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; column = new ColumnConfig("postedDate", "Posting Date", 100);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; column.setAlignment(HorizontalAlignment.RIGHT);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; column.setDateTimeFormat(DateTimeFormat.getShortDateFormat());&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; configs.add(column);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ColumnModel cm = new ColumnModel(configs);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; final Grid&amp;lt;Commentmodel&amp;gt; grid = new Grid&amp;lt;Commentmodel&amp;gt;(commentStore, cm);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; grid.setBorders(true);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; grid.setAutoExpandColumn("comments");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; grid.setStyleAttribute("borderTop", "none");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; grid.setStripeRows(true);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ContentPanel cp = new ContentPanel();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; cp.setBodyBorder(false);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; cp.setHeading("Grid with Pagination");&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; cp.setButtonAlign(HorizontalAlignment.CENTER);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; cp.setLayout(new FitLayout());&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; cp.setSize(700, 300);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; cp.add(grid);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;That's all for today. You will get a live example of this tutorial &lt;a href="http://gxtexamplegallery.appspot.com/"&gt;here&lt;/a&gt;.&lt;br /&gt;For more about Google App Engine and JDO &lt;a href="http://code.google.com/appengine/docs/java/gettingstarted/usingdatastore.html"&gt;visit this&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-7490333537146336733?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/7490333537146336733/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=7490333537146336733' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/7490333537146336733'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/7490333537146336733'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2010/06/google-app-engine-jdo-and-gxtext-gwt.html' title='Google App Engine, JDO and GXT(Ext GWT) Grid -  Make All These Working Together'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-4737462300429556683</id><published>2010-05-26T20:58:00.000-07:00</published><updated>2010-05-27T19:21:37.238-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='XTemplate'/><category scheme='http://www.blogger.com/atom/ns#' term='Ext GWT'/><category scheme='http://www.blogger.com/atom/ns#' term='ListView'/><category scheme='http://www.blogger.com/atom/ns#' term='gxt'/><title type='text'>How to Use GXT XTemplate with ListView</title><content type='html'>XTemplate is a very useful class of GXT that supports auto-filling arrays, conditional processing with basic comparison operators, sub-templates, basic math function support, special built-in template variables, inline code execution and more. Here i am going to illustrate how to use XTemplate with a ListView to customize the look and feel of the ListView.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://zawoad.blogspot.com/2009/06/getting-started-with-gwt-create-your.html" target="_blank"&gt;Create a new project&lt;/a&gt;&amp;nbsp;named &lt;span id="keyword1"&gt;&lt;i&gt;XTemplateExample&lt;/i&gt;&lt;/span&gt; and&amp;nbsp;&lt;a href="http://zawoad.blogspot.com/2009/06/how-to-use-ext-gwt-in-eclipse-34-to.html" target="_blank"&gt;add GXT library&lt;/a&gt;&amp;nbsp;in the project. To create a ListView at first you need a base model class and have to generate data for that model. In this tutorial i have used the same &lt;span id="keyword1"&gt;&lt;i&gt;Employee &lt;/i&gt;&lt;/span&gt;model and &lt;span id="keyword1"&gt;&lt;i&gt;TestData &lt;/i&gt;&lt;/span&gt;class for generating data which I have used in my previous blogs.&amp;nbsp;You will find the code of these classes&amp;nbsp;&lt;a href="http://zawoad.blogspot.com/2009/08/how-to-create-simple-grid-using-gxtext.html" target="_blank"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Now go to the&amp;nbsp;&lt;span id="keyword1"&gt;onModuleLoad&lt;/span&gt;&amp;nbsp;method of &lt;i&gt;XTemplateExample &lt;/i&gt;class. Remove all the auto generated code of this method. &lt;br /&gt;First create a ListStore of &lt;span id="keyword1"&gt;&lt;i&gt;Employee&amp;nbsp;&lt;/i&gt;&lt;/span&gt;&lt;i&gt;&lt;/i&gt;model , &lt;i&gt;employeeList &lt;/i&gt;and add data to this store which was generated in the &lt;span id="keyword1"&gt;&lt;i&gt;TestData &lt;/i&gt;&lt;/span&gt;class&lt;br /&gt;&lt;br /&gt;&lt;pre class="java" name="code"&gt;&amp;nbsp;&amp;nbsp;ListStore&amp;lt;Employee&amp;gt; employeeList = new ListStore&amp;lt;Employee&amp;gt;(); &lt;br /&gt;&amp;nbsp;&amp;nbsp; employeeList.add(TestData.getEmployees());&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now Create a ListView of &lt;span id="keyword1"&gt;Employee&lt;/span&gt; type and set the employeeList as the store of the list view.&lt;br /&gt;&lt;pre class="java" name="code"&gt;&amp;nbsp;&amp;nbsp; ListView&amp;lt;Employee&amp;gt; lView = new ListView&amp;lt;Employee&amp;gt;();&lt;br /&gt;&amp;nbsp;&amp;nbsp; //getTemplate() returns the desired template&lt;br /&gt;&amp;nbsp;&amp;nbsp; lView.setTemplate(getTemplate());&lt;br /&gt;&amp;nbsp;&amp;nbsp; lView.setStore(employeeList);&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; ContentPanel cp = new ContentPanel(); &lt;br /&gt;&amp;nbsp;&amp;nbsp; cp.setBodyBorder(false); &lt;br /&gt;&amp;nbsp;&amp;nbsp; cp.setHeading("Using XTemplate"); &lt;br /&gt;&amp;nbsp;&amp;nbsp; cp.setButtonAlign(HorizontalAlignment.CENTER); &lt;br /&gt;&amp;nbsp;&amp;nbsp; cp.setLayout(new FitLayout()); &lt;br /&gt;&amp;nbsp;&amp;nbsp; cp.setSize(500, 420);&lt;br /&gt;&amp;nbsp;&amp;nbsp; cp.add(lView);&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp; RootPanel.get().add(cp);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Here goes the definition of the &lt;span id="keyword1"&gt;getTemplate()&lt;/span&gt; method&lt;br /&gt;&lt;pre class="java" name="code"&gt;private native String getTemplate() /*-{ &lt;br /&gt;       return ['&amp;lt;tpl for="."&amp;gt;', &lt;br /&gt;       '&amp;lt;div style="border: 1px solid #DDDDDD;float:left;margin:4px 0 4px  4px; padding:2px;width:220px;"&amp;gt;',&lt;br /&gt;       '&amp;lt;div style="color:#1C3C78;font-weight:bold;padding-bottom:5px;padding-top:2px;text-decoration:underline;"&amp;gt;{name}&amp;lt;/div&amp;gt;', &lt;br /&gt;       '&amp;lt;div style="color:green"&amp;gt;Department:{department}&amp;lt;/div&amp;gt;', &lt;br /&gt;       '&amp;lt;div style="color:blue"&amp;gt;Designation:{designation}&amp;lt;/div&amp;gt;',&lt;br /&gt;       '&amp;lt;div style="color:black;padding-bottom:2px;"&amp;gt;Salary:{salary}&amp;lt;/div&amp;gt;', &lt;br /&gt;       '&amp;lt;/div&amp;gt;', &lt;br /&gt;       '&amp;lt;/tpl&amp;gt;', &lt;br /&gt;       ''].join(""); &lt;br /&gt;        &lt;br /&gt; }-*/;  &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Properties of the &lt;span id="keyword1"&gt;&lt;i&gt;Employee &lt;/i&gt;&lt;/span&gt;model are placed between {}. The style will be applied on every element of the &lt;i&gt;employeeList&lt;/i&gt;. And the outcome of the work will be like this.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/_MwOzNujvBcI/S_svJn5Q1QI/AAAAAAAAAQE/EXsMQwl932E/s1600/xTemplate.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="316" src="http://4.bp.blogspot.com/_MwOzNujvBcI/S_svJn5Q1QI/AAAAAAAAAQE/EXsMQwl932E/s400/xTemplate.jpg" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;You can give your own look and feel by simply changing the CSS.&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;script type="text/javascript"&gt;&lt;!--google_ad_client = "pub-3583615898080871";/* 468x60, created 10/2/09 BELOW POST */google_ad_slot = "5516300168";google_ad_width = 468;google_ad_height = 60;//--&gt;&lt;/script&gt;&lt;br /&gt;&lt;script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"&gt;&lt;/script&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-4737462300429556683?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/4737462300429556683/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=4737462300429556683' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/4737462300429556683'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/4737462300429556683'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2010/05/how-to-use-gxt-xtemplate-with-listview.html' title='How to Use GXT XTemplate with ListView'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_MwOzNujvBcI/S_svJn5Q1QI/AAAAAAAAAQE/EXsMQwl932E/s72-c/xTemplate.jpg' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-925968421115973243</id><published>2010-05-13T19:32:00.000-07:00</published><updated>2010-05-13T19:45:34.206-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JavaMail API'/><title type='text'>Sending Mail Using JavaMail API and Gmail as SMTP server</title><content type='html'>The JavaMail API provides a platform-independent and protocol-independent framework to build mail and messaging applications. The API defines classes such as &lt;span class="cCode"&gt;Message&lt;/span&gt;, Session, and &lt;span class="cCode"&gt;Transport.&lt;/span&gt; It includes support for the IMAP4, POP3, and SMTP protocols. Here I am going to show you how you can use this API to send mail through SMTP protocol.&lt;br /&gt;&lt;br /&gt;First create a MailUtility class which you can use later from your client code.&lt;br /&gt;&lt;pre class="java" name="code"&gt;public class MailUtility {&lt;br /&gt;&lt;br /&gt;//Set Gmail as SMTP host &lt;br /&gt;private String SMTP_HOST_NAME = "smtp.gmail.com";&lt;br /&gt;private String SMTP_AUTH_USER = "yourgmailid@gmail.com";&lt;br /&gt;private String SMTP_AUTH_PWD = "password";&lt;br /&gt;&lt;br /&gt;public void postMail(String recipients[], String subject,&lt;br /&gt;String message, String from) throws MessagingException {&lt;br /&gt;boolean debug = false;&lt;br /&gt;&lt;br /&gt;//Set the required JavaMail session properties&lt;br /&gt;Properties props = new Properties();&lt;br /&gt;props.put("mail.smtp.starttls.enable", "true");&lt;br /&gt;props.put("mail.smtp.host", SMTP_HOST_NAME);&lt;br /&gt;props.put("mail.smtp.user", SMTP_AUTH_USER);&lt;br /&gt;props.put("mail.smtp.password", SMTP_AUTH_PWD);&lt;br /&gt;props.put("mail.smtp.auth", "true");&lt;br /&gt;props.put("mail.smtp.port", "465");&lt;br /&gt;props.put("mail.smtp.ssl", "true");&lt;br /&gt;&lt;br /&gt;props.put("mail.smtp.socketFactory.port", "465");&lt;br /&gt;props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");&lt;br /&gt;props.put("mail.smtp.socketFactory.fallback", "false");&lt;br /&gt;&lt;br /&gt;//Create an Authenticator. You will find the SMTPAuthenticator class defination later&lt;br /&gt;Authenticator auth = new SMTPAuthenticator();&lt;br /&gt;&lt;br /&gt;//Create a Session from the Properties and the Authenticator&lt;br /&gt;Session session = Session.getInstance(props, auth);&lt;br /&gt;session.setDebug(debug);&lt;br /&gt;&lt;br /&gt;// Create a MimeMessage&lt;br /&gt;MimeMessage msg = new MimeMessage(session);&lt;br /&gt;&lt;br /&gt;// Set the from and to address&lt;br /&gt;InternetAddress addressFrom = new InternetAddress(from);&lt;br /&gt;msg.setFrom(addressFrom);&lt;br /&gt;&lt;br /&gt;InternetAddress[] addressTo = new InternetAddress[recipients.length];&lt;br /&gt;for (int i = 0; i &amp;lt; recipients.length; i++) {&lt;br /&gt;addressTo[i] = new InternetAddress(recipients[i]);&lt;br /&gt;}&lt;br /&gt;msg.setRecipients(Message.RecipientType.TO, addressTo);&lt;br /&gt;&lt;br /&gt;//Set message subject and text&lt;br /&gt;msg.setSubject(subject);&lt;br /&gt;msg.setText(message);&lt;br /&gt;&lt;br /&gt;//Finally now send the message.&lt;br /&gt;try {&lt;br /&gt;Transport.send(msg);&lt;br /&gt;} catch (MessagingException messagingException) {&lt;br /&gt;messagingException.printStackTrace();&lt;br /&gt;} catch (Exception ex) {&lt;br /&gt;ex.printStackTrace();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;//SimpleAuthenticator is used to do simple authentication&lt;br /&gt;//when the SMTP server requires it.&lt;br /&gt;&lt;br /&gt;private class SMTPAuthenticator extends javax.mail.Authenticator {&lt;br /&gt;&lt;br /&gt;@Override&lt;br /&gt;public PasswordAuthentication getPasswordAuthentication() {&lt;br /&gt;String username = SMTP_AUTH_USER;&lt;br /&gt;String password = SMTP_AUTH_PWD;&lt;br /&gt;return new PasswordAuthentication(username, password);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;And here is the client code that uses the MailUtility class for sending mail.&lt;br /&gt;&lt;pre class="java" name="code"&gt;String emailMsgTxt = "Hello, this is a test mail from my mail application.\n";&lt;br /&gt;String emailSubjectTxt = "Test Mail";&lt;br /&gt;String emailFromAddress = "yourgmailid@gmail.com";&lt;br /&gt;String[] receipentList=&lt;br /&gt;&amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "abc@gmail.com",&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "wxx@yahoo.com"&lt;br /&gt;&amp;nbsp;};&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MailUtility smtpMailSender = new MailUtility();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; smtpMailSender.postMail(receipentList, emailSubjectTxt, emailMsgTxt, emailFromAddress);&lt;br /&gt;} catch (MessagingException messagingException)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; messagingException.printStackTrace();&lt;br /&gt;} catch (Exception ex)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ex.printStackTrace();&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;That's all. Another day I will describe how you can send mail asynchronously using this mail API.&lt;br /&gt;&lt;div&gt;&lt;script type="text/javascript"&gt;&lt;!--google_ad_client = "pub-3583615898080871";/* 468x60, created 10/2/09 BELOW POST */google_ad_slot = "5516300168";google_ad_width = 468;google_ad_height = 60;//--&gt;&lt;/script&gt;&lt;br /&gt;&lt;script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"&gt;&lt;/script&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-925968421115973243?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/925968421115973243/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=925968421115973243' title='12 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/925968421115973243'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/925968421115973243'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2010/05/sending-mail-using-javamail-api-and.html' title='Sending Mail Using JavaMail API and Gmail as SMTP server'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><thr:total>12</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-6038679701368698752</id><published>2010-04-18T23:05:00.000-07:00</published><updated>2010-04-18T23:14:33.690-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Servlet'/><category scheme='http://www.blogger.com/atom/ns#' term='GWT'/><title type='text'>How to Call a Servlet in GWT</title><content type='html'>Sometimes you may need a HttpServlet other than GWT Rpc Service in a real life application. If needed then how to call the Servlet from your GWT client? Here you will find the answer.&lt;br /&gt;&lt;br /&gt;Here is a simple &lt;span id="keyword1"&gt;HelloServlet&lt;/span&gt;&lt;br /&gt;&lt;pre class="java" name="code"&gt;public class HelloServlet extends HttpServlet {&lt;br /&gt;@Override&lt;br /&gt;public void doGet(HttpServletRequest request, HttpServletResponse response)&lt;br /&gt;throws ServletException, IOException&lt;br /&gt;{ &lt;br /&gt;String name = request.getParameter("name");&lt;br /&gt;response.getWriter().write("Hello "+name+", Welcome in My Servlet");&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;The Servlet uses a request a parameter 'name' and writes it in the response writer.&lt;br /&gt;&lt;br /&gt;To call the Servlet from the client first configure the &lt;span id="keyword1"&gt;&lt;strong&gt;web.xml&lt;/strong&gt;&lt;/span&gt; (war/WEB-INF/web.xml) file to let your GWT client know about the HelloServlet.&lt;br /&gt;&lt;pre class="xml" name="code"&gt;&lt;servlet&gt;&lt;br /&gt; &lt;servlet-name&gt;HelloServlet&lt;/servlet-name&gt;&lt;br /&gt; &lt;servlet-class&gt;org.ratul.servlettest.server.HelloServlet&lt;/servlet-class&gt;&lt;br /&gt;&lt;/servlet&gt;&lt;br /&gt;&lt;servlet-mapping&gt;&lt;br /&gt; &lt;servlet-name&gt;HelloServlet&lt;/servlet-name&gt;&lt;br /&gt; &lt;url-pattern&gt;/hello&lt;/url-pattern&gt;&lt;br /&gt;&lt;/servlet-mapping&gt;&lt;br /&gt;&lt;/pre&gt;Value of the &lt;span id="keyword1"&gt;url-pattern&lt;/span&gt; node will be used later to call the Servlet. &lt;br /&gt;&lt;br /&gt;Now make a simple UI with a TextBox and a Button.&lt;br /&gt;&lt;pre class="java" name="code"&gt;final Button sendButton = new Button("Send");&lt;br /&gt;final TextBox nameField = new TextBox();&lt;br /&gt;RootPanel.get().add(nameField);&lt;br /&gt;RootPanel.get().add(sendButton);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;In the Click Handler of the sendButton call the Servlet with the 'name' parameter in the following way&lt;br /&gt;&lt;pre class="java" name="code"&gt;sendButton.addClickHandler(new ClickHandler() {&lt;br /&gt;  public void onClick(ClickEvent event) {&lt;br /&gt;    Window.Location.replace("/hello?name="+nameField.getText());&lt;br /&gt;    //the url-pattern value is used here&lt;br /&gt;  }&lt;br /&gt;});&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Thats' all for today. Happy coding with GWT :-) &lt;br /&gt;&lt;div&gt;&lt;script type="text/javascript"&gt;&lt;!--google_ad_client = "pub-3583615898080871";/* 468x60, created 10/2/09 BELOW POST */google_ad_slot = "5516300168";google_ad_width = 468;google_ad_height = 60;//--&gt;&lt;/script&gt;&lt;br /&gt;&lt;script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"&gt;&lt;/script&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-6038679701368698752?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/6038679701368698752/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=6038679701368698752' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/6038679701368698752'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/6038679701368698752'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2010/04/how-to-call-servlet-in-gwt.html' title='How to Call a Servlet in GWT'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-1391330348602837604</id><published>2010-04-10T21:35:00.000-07:00</published><updated>2010-04-10T22:07:13.504-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='flash chart'/><category scheme='http://www.blogger.com/atom/ns#' term='Horizontal Bar Chart'/><category scheme='http://www.blogger.com/atom/ns#' term='Ext GWT'/><category scheme='http://www.blogger.com/atom/ns#' term='GXT Chart'/><category scheme='http://www.blogger.com/atom/ns#' term='gxt'/><category scheme='http://www.blogger.com/atom/ns#' term='GXT Example'/><title type='text'>Getting Started with GXT (Ext GWT) Chart : Crate a Simple Horizontal Bar Chart</title><content type='html'>Ext GWT is providing us a very handy Chart library based on Open Flash Chart. Here you will find a step by step detail description about creating a simple horizontal bar chart using the GXT chart library.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://zawoad.blogspot.com/2009/06/getting-started-with-gwt-create-your.html" target="_blank"&gt;Create a new project&lt;/a&gt; named &lt;b&gt;&lt;i&gt;GXTBascicChart &lt;/i&gt;&lt;/b&gt;and &lt;a href="http://zawoad.blogspot.com/2009/06/how-to-use-ext-gwt-in-eclipse-34-to.html" target="_blank"&gt;add GXT library&lt;/a&gt; in the project. Go to the &lt;span id="keyword1"&gt;&lt;b&gt;GXTBascicChart.gwt.xml&lt;/b&gt;&lt;/span&gt; file and add this line &lt;br /&gt;&lt;pre class="xml" name="code"&gt;&amp;lt;inherits name='com.extjs.gxt.charts.Chart'/&amp;gt;&lt;/pre&gt;&lt;br /&gt;Now go to the directory where you have extracted the GXT library. In the resource folder you will find all the resources for using GXT. Copy the &lt;span id="keyword1"&gt;&lt;b&gt;chart&lt;/b&gt;&lt;/span&gt; and &lt;span id="keyword1"&gt;&lt;b&gt;flash&lt;/b&gt;&lt;/span&gt; folders in the war folder of you application. &lt;br /&gt;&lt;br /&gt;Go to the onModuleLoad method of GXTBascicChart class and remove all the auto generated code of this method. Create a Content Panel to place the chart&lt;br /&gt;&lt;pre class="java" name="code"&gt;ContentPanel cp = new ContentPanel();  &lt;br /&gt;cp.setHeading("Horizontal Bar chart");  &lt;br /&gt;cp.setFrame(true);  &lt;br /&gt;cp.setSize(550, 400);  &lt;br /&gt;cp.setLayout(new FitLayout());&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now create a Chart component by providing the location of the open flash chart Shockwave file which resides in the chart folder.&lt;br /&gt;&lt;pre class="java" name="code"&gt;String url = "chart/open-flash-chart.swf";  &lt;br /&gt;final Chart chart = new Chart(url);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;div&gt;&lt;script type="text/javascript"&gt;&lt;!--google_ad_client = "pub-3583615898080871";/* 468x60, created 10/2/09 BELOW POST */google_ad_slot = "5516300168";google_ad_width = 468;google_ad_height = 60;//--&gt;&lt;/script&gt;&lt;br /&gt;&lt;script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"&gt;&lt;/script&gt;&lt;/div&gt;&lt;br /&gt;Set a Chart Model for the chart object and add this to the Content Panel&lt;br /&gt;&lt;pre class="java" name="code"&gt;chart.setBorders(true);  &lt;br /&gt;chart.setChartModel(getHorizontalBarChartModel());  &lt;br /&gt;cp.add(chart);      &lt;br /&gt;RootPanel.get().add(cp);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The Chart Model is responsible for the chart title, axes, legends, labels, and draw-able elements in your chart. Here is the getHorizontalBarChartModel method&lt;br /&gt;&lt;pre class="java" name="code"&gt;public ChartModel getHorizontalBarChartModel() &lt;br /&gt;{ &lt;br /&gt;  //Create a ChartModel with the Chart Title and some style attributes&lt;br /&gt;  ChartModel cm = new ChartModel("Students by Department", "font-size: 14px; font-family:      Verdana; text-align: center;");&lt;br /&gt; &lt;br /&gt;  XAxis xa = new XAxis();&lt;br /&gt;  //set the maximum, minimum and the step value for the X axis&lt;br /&gt;  xa.setRange(0, 200, 50);  &lt;br /&gt;  cm.setXAxis(xa);&lt;br /&gt;  &lt;br /&gt;  YAxis ya = new YAxis();&lt;br /&gt;  //Add the labels to the Y axis  &lt;br /&gt;  ya.addLabels("CSE", "EEE", "CE", "ME","CHE");  &lt;br /&gt;  ya.setOffset(true);  &lt;br /&gt;  cm.setYAxis(ya);&lt;br /&gt;&lt;br /&gt;  //create a Horizontal Bar Chart object and add bars to the object  &lt;br /&gt;  HorizontalBarChart bchart = new HorizontalBarChart();  &lt;br /&gt;  bchart.setTooltip("#val#Students");  &lt;br /&gt;  bchart.addBars(new HorizontalBarChart.Bar(60, "#ffff00")); &lt;br /&gt;  //different color for different bars &lt;br /&gt;  bchart.addBars(new HorizontalBarChart.Bar(180, "#0000ff"));  &lt;br /&gt;  bchart.addBars(new HorizontalBarChart.Bar(180, "#00ff00"));  &lt;br /&gt;  bchart.addBars(new HorizontalBarChart.Bar(120, "#ff0000"));&lt;br /&gt;  bchart.addBars(new HorizontalBarChart.Bar(120, "#333ccc"));&lt;br /&gt;&lt;br /&gt;  //add the bchart as the Chart Config of the ChartModel&lt;br /&gt;  cm.addChartConfig(bchart);       &lt;br /&gt;  cm.setTooltipStyle(new ToolTip(MouseStyle.FOLLOW));  &lt;br /&gt;  return cm;  &lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;And here is the last step before running your application.&lt;br /&gt;Go to the &lt;span id="keyword1"&gt;&lt;b&gt;GXTBascicChart.html&lt;/b&gt;&lt;/span&gt; file and add the following line in the head section&lt;br /&gt;&lt;pre class="html" name="code"&gt;&amp;lt;script language='javascript' src='flash/swfobject.js'&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;/pre&gt;That's all. Run the application and the output will be like this&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/_MwOzNujvBcI/S8ExhVMlTwI/AAAAAAAAAPE/snFgMFTt42g/s1600/gxtHorizontalBarChart.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="308" src="http://2.bp.blogspot.com/_MwOzNujvBcI/S8ExhVMlTwI/AAAAAAAAAPE/snFgMFTt42g/s400/gxtHorizontalBarChart.jpg" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-1391330348602837604?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/1391330348602837604/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=1391330348602837604' title='23 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/1391330348602837604'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/1391330348602837604'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2010/04/getting-started-with-gxt-ext-gwt-chart.html' title='Getting Started with GXT (Ext GWT) Chart : Crate a Simple Horizontal Bar Chart'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_MwOzNujvBcI/S8ExhVMlTwI/AAAAAAAAAPE/snFgMFTt42g/s72-c/gxtHorizontalBarChart.jpg' height='72' width='72'/><thr:total>23</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-7913881513719536223</id><published>2010-04-08T20:19:00.000-07:00</published><updated>2010-04-08T20:22:45.003-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='GWT'/><category scheme='http://www.blogger.com/atom/ns#' term='Session Bean'/><title type='text'>How to Use Your Session Beans from GWT Client</title><content type='html'>Recently we have finished a project in which we were using EJB3.0 in the business tier and a GWT client for the user interface. Here i will share you how we connected them in a very convenient way.&lt;br /&gt;&lt;br /&gt;Suppose you have an Entity class, Department and a stateless Session Bean named DepartmentBean which implements a remote interface DepartmentBeanRemote. To save a department the bean class&lt;br /&gt;has a create method&lt;br /&gt;&lt;pre class="java" name="code"&gt;public BigInteger create(Department department)&lt;br /&gt;{&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;em.persist(department);&lt;br /&gt;em.flush();&lt;br /&gt;return department.getIdNr();&lt;br /&gt;} catch (InvalidStateException in)&lt;br /&gt;{&lt;br /&gt;in.printStackTrace();&lt;br /&gt;} catch (Exception ex)&lt;br /&gt;{&lt;br /&gt;ex.printStackTrace();&lt;br /&gt;}&lt;br /&gt;return null;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span id="keyword1"&gt;Now how to call this create method from your GWT client?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;First create a GWT RPC Service named DepartmentService and DepartmentServiceImpl is the implementation class of this service interface. &lt;span id="keyword1"&gt;The service implemenltation class will serve as a gateway between client and bean class.&lt;/span&gt; &lt;br /&gt;&lt;br /&gt;Create an instance of DepartmentBeanRemote by dependency injection in DepartmentServiceImpl. &lt;br /&gt;&lt;pre class="java" name="code"&gt;@EJB&lt;br /&gt;private DepartmentBeanRemote departmentBeanRemote;&lt;br /&gt;&lt;/pre&gt;Now use this instance to call the methods of the DepartmentBean in the following way&lt;br /&gt;&lt;br /&gt;&lt;pre class="java" name="code"&gt;public Long create()&lt;br /&gt;{&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;Department department = new Department();&lt;br /&gt;department.setIdNr(null);&lt;br /&gt;department.setDepartmentNameSt("Computer Science");&lt;br /&gt;department.setDepartmentDescriptionSt("Most popular department of the university");&lt;br /&gt;BigInteger returnValue = departmentBeanRemote.create(department);&lt;br /&gt;return new Long(returnValue.toString());&lt;br /&gt;}&lt;br /&gt;catch (Exception e)&lt;br /&gt;{&lt;br /&gt;e.printStackTrace();&lt;br /&gt;return null; &lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;Call the service method from the client. You have just made a complete path between your GWT Client and the Session Beans.&lt;br /&gt;&lt;div&gt;&lt;script type="text/javascript"&gt;&lt;!--google_ad_client = "pub-3583615898080871";/* 468x60, created 10/2/09 BELOW POST */google_ad_slot = "5516300168";google_ad_width = 468;google_ad_height = 60;//--&gt;&lt;/script&gt;&lt;script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"&gt;&lt;/script&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-7913881513719536223?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/7913881513719536223/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=7913881513719536223' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/7913881513719536223'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/7913881513719536223'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2010/04/how-to-use-your-session-beans-from-gwt.html' title='How to Use Your Session Beans from GWT Client'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-8943467165209716626</id><published>2010-02-13T06:37:00.000-08:00</published><updated>2010-05-29T18:21:17.689-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='portbase'/><category scheme='http://www.blogger.com/atom/ns#' term='GlassFish'/><category scheme='http://www.blogger.com/atom/ns#' term='create domain'/><title type='text'>How to Run Multiple Domain of GlassFish Simultaneously (Use --portbase option)</title><content type='html'>In many cases you may need to run multiple domains of GlassFish simultaneously. Few days ago I was in a situation to run 3 domains concurrently. At first I was creating domain with only --adminport option to assign different admin port to different domains. But when I try to run those domains&amp;nbsp;simultaneously I was getting port conflict error. Then I found that there are many other ports in GlassFish for other purposes. Default ports for GlassFish are&lt;br /&gt;&lt;br /&gt;4848 Admin port&lt;br /&gt;8080 HTTP Instance port&lt;br /&gt;7676 JMS port&lt;br /&gt;3700 IIOP port&lt;br /&gt;8181 HTTP_SSL port&lt;br /&gt;3820 IIOP_SSL port&lt;br /&gt;3920 IIOP_MUTUALAUTH port&lt;br /&gt;8686 JMX_ADMIN port&lt;br /&gt;&lt;br /&gt;So to avoid port conflict you have to assign different port numbers in different domains for each purpose. The easy way of doing this is using &lt;b&gt;&lt;span id="keyword1"&gt;portbase&lt;/span&gt;&lt;/b&gt; option in create-domain command. You just have to set a base port number and the values for the  ports  are calculated as follows&lt;br /&gt;&lt;br /&gt;Admin port: portbase + 48&lt;br /&gt;HTTP listener port: portbase  +  80&lt;br /&gt;IIOP  listener  port: portbase + 37&lt;br /&gt;JMX port: portbase + 86&lt;br /&gt;&lt;br /&gt;Here is an example of create-domain command with portbase option&lt;br /&gt;&lt;br /&gt;&lt;span id="keyword1" style="font-size: 14px;"&gt;asadmin create-domain --user admin --portbase 2000 --savemasterpassword=true domain2&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;script type="text/javascript"&gt;&lt;!--google_ad_client = "pub-3583615898080871";/* 468x60, created 10/2/09 BELOW POST */google_ad_slot = "5516300168";google_ad_width = 468;google_ad_height = 60;//--&gt;&lt;/script&gt;&lt;script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"&gt;&lt;/script&gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;&lt;span id="keyword1"&gt;Remember&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;-&amp;gt; Adminport should be between 1 and 65535. So choose&amp;nbsp;a portbase value such that the resulting port number doesn't exceed 65535&lt;br /&gt;&lt;br /&gt;-&amp;gt;The --portbase  option  can't  be  used  with  the  --adminport or the --instanceport option&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-8943467165209716626?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/8943467165209716626/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=8943467165209716626' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/8943467165209716626'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/8943467165209716626'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2010/02/how-to-run-multiple-domain-of-glassfish.html' title='How to Run Multiple Domain of GlassFish Simultaneously (Use --portbase option)'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-8689408123458908877</id><published>2009-12-11T01:45:00.000-08:00</published><updated>2009-12-12T20:04:41.162-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='GWT'/><category scheme='http://www.blogger.com/atom/ns#' term='Session Management'/><title type='text'>Session Management (Set and Get Data from Session) in GWT</title><content type='html'>When you think about the Security of a web application '&lt;b&gt;&lt;i&gt;Session Management&lt;/i&gt;&lt;/b&gt;' is the first thing that strikes in your head. I am now working with an enterprise web application using GWT and you know security is a very vital issue in an enterprise application. And we have ensured the security by managing session data. Here i will describe how to store and retrieve data from session by using GWT RPC.&lt;br /&gt;&lt;br /&gt;Suppose you want to store the user name in session after login to the application and check the session value later. Then what do you do?&lt;br /&gt;&lt;br /&gt;First create a GWT RPC Service named &lt;span id="keyword1"&gt;'SessionManagementService'&lt;/span&gt;. You can give any other name as you like. In SessionManagementService interface add two methods&lt;br /&gt;&lt;pre class="java" name="code"&gt;public void setUserName(String userName);&lt;br /&gt;public String getUserName();&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;And synchronize the methods with &lt;span id="keyword1"&gt;'SessionManagementServiceAsync'&lt;/span&gt;.&lt;br /&gt;&lt;pre class="java" name="code"&gt;public void setUserName(String userName, AsyncCallback&amp;lt;Void&amp;gt; asyncCallback);&lt;br /&gt;public void getUserName(AsyncCallback&amp;lt;String&amp;gt; asyncCallback);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now implement the methods in &lt;span id="keyword1"&gt;'SessionManagementServiceImpl'&lt;/span&gt;. Let's first talk about the setter method.&lt;br /&gt;&lt;pre class="java" name="code"&gt;public void setUserName(String userName)&lt;br /&gt;{&lt;br /&gt;     HttpSession httpSession = getThreadLocalRequest().getSession(true);&lt;br /&gt;     httpSession.setAttribute("userName", userName);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The &lt;span id="keyword1"&gt;&lt;b&gt;getThreadLocalRequest&lt;/b&gt;&lt;/span&gt; method returns you a &lt;span id="keyword1"&gt;HttpServletRequest&lt;/span&gt; object for the current call. For simultaneous invocation you will get different request object. And the &lt;span id="keyword1"&gt;&lt;b&gt;getSession&lt;/b&gt;&lt;/span&gt; method returns you the current &lt;span id="keyword1"&gt;HttpSession&lt;/span&gt; for the associated request. So you can get the current session of the current call by getThreadLocalRequest().getSession(true).&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;script type="text/javascript"&gt;&lt;!--google_ad_client = "pub-3583615898080871";/* 468x60, created 10/2/09 BELOW POST */google_ad_slot = "5516300168";google_ad_width = 468;google_ad_height = 60;//--&gt;&lt;/script&gt;&lt;script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"&gt;&lt;/script&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;The &lt;span id="keyword1"&gt;&lt;b&gt;setAttribute&lt;/b&gt;&lt;/span&gt; method binds an object to the associated session. It stores the object's value as a Name-Value pair. You can put any thing as the value of the object. A String value or List&amp;lt;String&amp;gt; any thing. Here the name of the object is "useName" and the object is bound to this session with this name.&lt;br /&gt;&lt;br /&gt;Now come to the getter method.&lt;br /&gt;&lt;pre class="java" name="code"&gt;public String getUserName()&lt;br /&gt;{&lt;br /&gt;    HttpSession session = getThreadLocalRequest().getSession(true);&lt;br /&gt;    if (session.getAttribute("userName") != null)&lt;br /&gt;    {&lt;br /&gt;        return (String) session.getAttribute("userName");&lt;br /&gt;    }&lt;br /&gt;    else &lt;br /&gt;    {&lt;br /&gt;        return "";&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Get the current session in the same way as described for the setter method. The &lt;span id="keyword1"&gt;&lt;b&gt;getAttribute&lt;/b&gt;&lt;/span&gt; method returns the value of the object which is bound with this session with the specific name. Then simply cast it with your desired type.&lt;br /&gt;&lt;br /&gt;Thats all. Just call the services according to your requirement. Play with GWT and stay in touched. :-D&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-8689408123458908877?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/8689408123458908877/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=8689408123458908877' title='8 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/8689408123458908877'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/8689408123458908877'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2009/12/session-management-set-and-get-data.html' title='Session Management (Set and Get Data from Session) in GWT'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><thr:total>8</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-6408508863382537470</id><published>2009-12-05T20:12:00.000-08:00</published><updated>2009-12-05T20:17:30.639-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='GXT(Ext GWT) Editor TreeGrid Example'/><category scheme='http://www.blogger.com/atom/ns#' term='Ext GWT'/><category scheme='http://www.blogger.com/atom/ns#' term='ColumnConfig'/><category scheme='http://www.blogger.com/atom/ns#' term='gxt'/><title type='text'>How to Create an Editable TreeGrid in GXT(Ext GWT)</title><content type='html'>In our project I need to add the editable functionality with the GXT TreeGrid. Here I am going to share my experience about how to create an editable TreeGrid.&lt;br /&gt;&lt;br /&gt;You may have already known that to build a TreeGrid the tree node objects must possess the functionality of&amp;nbsp;&lt;span id="keyword1"&gt;&lt;b&gt;&lt;i&gt;BaseTreeModel&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&amp;nbsp;of GXT. I have used the same&amp;nbsp;&lt;b&gt;&lt;i&gt;EmployeeTreeNode&amp;nbsp;&lt;/i&gt;&lt;/b&gt;and&amp;nbsp;&lt;span id="keyword1"&gt;&lt;b&gt;&lt;i&gt;Folder&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;i&gt;&amp;nbsp;&lt;/i&gt;&lt;/b&gt;class for leaf and parent nodes that i used in my previous blogs about GXT TreePanel. And in the&amp;nbsp;&lt;span id="keyword1"&gt;&lt;b&gt;&lt;i&gt;TestData&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;i&gt;&amp;nbsp;&lt;/i&gt;&lt;/b&gt;class i have populated the data to build the TreeGrid. You will find the code for these classes&amp;nbsp;&lt;a href="http://zawoad.blogspot.com/2009/09/how-to-create-simple-tree-using-gxtext.html" target="_blank"&gt;here&lt;/a&gt;.&lt;br /&gt;(If you are new in GWT and GXT read my blogs about &lt;a href="http://zawoad.blogspot.com/2009/06/getting-started-with-gwt-create-your.html"&gt;creating a new project in gwt&lt;/a&gt; and&amp;nbsp;&lt;a href="http://zawoad.blogspot.com/2009/06/how-to-use-ext-gwt-in-eclipse-34-to.html"&gt;add GXT library&lt;/a&gt;)&lt;br /&gt;&lt;br /&gt;First create a root object named &lt;span id="keyword1"&gt;model&lt;/span&gt; of the&amp;nbsp;&lt;b&gt;&lt;i&gt;Folder&amp;nbsp;&lt;/i&gt;&lt;/b&gt;class from&amp;nbsp;&lt;span id="keyword1"&gt;TestData.getTreeModel()&lt;/span&gt;&amp;nbsp;method.&lt;br /&gt;&lt;pre class="java" name="code"&gt;Folder model = TestData.getTreeModel();&lt;br /&gt;&lt;/pre&gt;Then create a TreeStore object,&lt;span id="keyword1"&gt;store&lt;/span&gt; from this model and add data to the store&lt;br /&gt;&lt;pre class="java" name="code"&gt;TreeStore&amp;lt;ModelData&amp;gt; store = new TreeStore&amp;lt;ModelData&amp;gt;();&lt;br /&gt;store.add(model.getChildren(), true);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now the time for defining ColumnConfig objects. First create a ColumnConfig, &lt;span id="keyword1"&gt;name&lt;/span&gt; and set a TextField as the editor of this object.&lt;br /&gt;&lt;pre class="java" name="code"&gt;ColumnConfig name = new ColumnConfig("name", "Name", 100);&lt;br /&gt;name.setRenderer(new TreeGridCellRenderer&amp;lt;ModelData&amp;gt;());&lt;br /&gt;TextField&amp;lt;String&amp;gt; text = new TextField&amp;lt;String&amp;gt;();&lt;br /&gt;text.setAllowBlank(false);&lt;br /&gt;name.setEditor(new CellEditor(text));&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The second column is the &lt;span id="keyword1"&gt;salary&lt;/span&gt; column so you can set a NumberField as the editor for this column. &lt;br /&gt;&lt;pre class="java" name="code"&gt;ColumnConfig salary = new ColumnConfig("salary", "Salary", 100);&lt;br /&gt;salary.setEditor(new CellEditor(new NumberField()));&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;In my example the third column is the joining date column. So you have to set a DateField as the editor for this column. For this first create a DateField object &lt;span id="keyword1"&gt;dateField&lt;/span&gt; and set the display format of the field. Then create a ColumnConfig object &lt;span id="keyword1"&gt;date&lt;/span&gt; and set the dateField as the editor of the date.&lt;br /&gt;&lt;pre class="java" name="code"&gt;DateField dateField = new DateField();  &lt;br /&gt;dateField.getPropertyEditor().setFormat(DateTimeFormat.getFormat("MM/dd/y"));&lt;br /&gt;     &lt;br /&gt;ColumnConfig date = new ColumnConfig("joiningdate", "Joining Date", 100); &lt;br /&gt;date.setAlignment(HorizontalAlignment.RIGHT);&lt;br /&gt;date.setEditor(new CellEditor(dateField));  &lt;br /&gt;date.setDateTimeFormat(DateTimeFormat.getMediumDateFormat());&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;div&gt;&lt;script type="text/javascript"&gt;&lt;!--google_ad_client = "pub-3583615898080871";/* 468x60, created 10/2/09 BELOW POST */google_ad_slot = "5516300168";google_ad_width = 468;google_ad_height = 60;//--&gt;&lt;/script&gt;&lt;script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"&gt;&lt;/script&gt;&lt;br /&gt;&lt;/div&gt;Now create a ColumnModel from these three ColumnConfig objects.&lt;br /&gt;&lt;pre class="java" name="code"&gt;ColumnModel cm = new ColumnModel(Arrays.asList(name, salary, date));&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;From the ColumnModel and TreeStore create an EditorTreeGrid object and set some property of the object.&lt;br /&gt;&lt;pre class="java" name="code"&gt;EditorTreeGrid&amp;lt;ModelData&amp;gt; editorTreeGrid = new EditorTreeGrid&amp;lt;ModelData&amp;gt;(store,cm);&lt;br /&gt;editorTreeGrid.setClicksToEdit(ClicksToEdit.TWO);&lt;br /&gt;editorTreeGrid.setBorders(true);&lt;br /&gt;editorTreeGrid.setSize(400, 400);&lt;br /&gt;editorTreeGrid.setAutoExpandColumn("name");&lt;br /&gt;editorTreeGrid.setTrackMouseOver(false);&lt;br /&gt;&lt;/pre&gt;The setter methods are self explanatory.&lt;br /&gt;&lt;br /&gt;Finally create a ContentPanel and add the &lt;span id="keyword1"&gt;editorTreeGrid&lt;/span&gt; in this panel.&lt;br /&gt;&lt;pre class="java" name="code"&gt;ContentPanel cp = new ContentPanel();&lt;br /&gt;cp.setBodyBorder(false);&lt;br /&gt;cp.setHeading("Cell TreeGrid Editing (2-Clicks)");&lt;br /&gt;cp.setButtonAlign(HorizontalAlignment.CENTER);&lt;br /&gt;cp.setLayout(new FitLayout());&lt;br /&gt;cp.setFrame(true);&lt;br /&gt;cp.setSize(600, 300);&lt;br /&gt;cp.add(editorTreeGrid);&lt;br /&gt;RootPanel.get().add(cp);&lt;br /&gt;&lt;/pre&gt;To view the live demo of this tutorial &lt;a href="http://gxtexamplegallery.appspot.com/"&gt;Click here&lt;/a&gt;.&lt;br /&gt;The output will be like this&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/_MwOzNujvBcI/SxssCob1JfI/AAAAAAAAAOY/lzFNDqzaaq8/s1600-h/cellEditorTreeGrid.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/_MwOzNujvBcI/SxssCob1JfI/AAAAAAAAAOY/lzFNDqzaaq8/s400/cellEditorTreeGrid.jpg" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-6408508863382537470?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/6408508863382537470/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=6408508863382537470' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/6408508863382537470'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/6408508863382537470'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2009/12/how-to-create-editable-treegrid-in.html' title='How to Create an Editable TreeGrid in GXT(Ext GWT)'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_MwOzNujvBcI/SxssCob1JfI/AAAAAAAAAOY/lzFNDqzaaq8/s72-c/cellEditorTreeGrid.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-2444181236386634125</id><published>2009-11-03T02:53:00.000-08:00</published><updated>2010-02-19T01:27:26.177-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='GXT(Ext GWT) TreeGrid Example'/><category scheme='http://www.blogger.com/atom/ns#' term='Ext GWT'/><category scheme='http://www.blogger.com/atom/ns#' term='gxt'/><title type='text'>How to Create a Basic TreeGrid using GXT(Ext GWT)</title><content type='html'>When you want to display hierarchical data tree grid will be the right choice for this. GXT TreeGrid is a very powerful UI component which provides us with some wonderful functionality like row editor, row number, widget render etc. Here i present you the way of creating a basic TreeGrid in detail.   &lt;br /&gt;&lt;br /&gt;&lt;a href="http://zawoad.blogspot.com/2009/06/getting-started-with-gwt-create-your.html"&gt;Create a new project&lt;/a&gt; named &lt;b&gt;&lt;i&gt;GxtBasicTreeGrid&lt;/i&gt;&lt;/b&gt; and &lt;a href="http://zawoad.blogspot.com/2009/06/how-to-use-ext-gwt-in-eclipse-34-to.html"&gt;add GXT library&lt;/a&gt; in the project. The tree node objects must possess the functionality of &lt;span id="keyword1"&gt;BaseTreeModel&lt;/span&gt; of GXT. I have used the same&amp;nbsp;&lt;b&gt;&lt;i&gt;EmployeeTreeNode&amp;nbsp;&lt;/i&gt;&lt;/b&gt;and &lt;span id="keyword1"&gt;&lt;b&gt;&lt;i&gt;Folder&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;i&gt; &lt;/i&gt;&lt;/b&gt;class for leaf and parent nodes that i used in my previous blogs about GXT TreePanel. And in the &lt;span id="keyword1"&gt;&lt;b&gt;&lt;i&gt;TestData&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;i&gt; &lt;/i&gt;&lt;/b&gt;class i have populated the data to build the TreeGrid. You will find the code for these classes &lt;a href="http://zawoad.blogspot.com/2009/09/how-to-create-simple-tree-using-gxtext.html" target="_blank"&gt;here&lt;/a&gt;.   &lt;br /&gt;&lt;br /&gt;First create a root object named &lt;span id="keyword1"&gt;model&lt;/span&gt; of the &lt;b&gt;&lt;i&gt;Folder &lt;/i&gt;&lt;/b&gt;class from &lt;span id="keyword1"&gt;TestData.getTreeModel()&lt;/span&gt; method and create a TreeStore object,&lt;span id="keyword1"&gt;store&lt;/span&gt; from this model.   &lt;br /&gt;&lt;span style="font-family: monospace; white-space: pre;"&gt;Folder model = TestData.getTreeModel();&lt;/span&gt;&lt;br /&gt;&lt;pre class="java" name="code"&gt;TreeStore&amp;lt;ModelData&amp;gt; store = new TreeStore&amp;lt;ModelData&amp;gt;();&lt;br /&gt;store.add(model.getChildren(), true);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;div&gt;&lt;script type="text/javascript"&gt;&lt;!--google_ad_client = "pub-3583615898080871";/* 468x60, created 10/2/09 BELOW POST */google_ad_slot = "5516300168";google_ad_width = 468;google_ad_height = 60;//--&gt;&lt;/script&gt;&lt;script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"&gt;&lt;/script&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Now define three ColumnConfig objects and create a ColumnModel from these objects. &lt;br /&gt;&lt;span style="font-family: monospace; white-space: pre;"&gt;ColumnConfig name = new ColumnConfig("name", "Name", 100);&lt;/span&gt;&lt;br /&gt;&lt;pre class="java" name="code"&gt;name.setRenderer(new TreeGridCellRenderer&amp;lt;ModelData&amp;gt;());&lt;br /&gt;&lt;br /&gt; ColumnConfig salary = new ColumnConfig("salary", "Salary", 100);&lt;br /&gt;&lt;br /&gt; ColumnConfig date = new ColumnConfig("joiningdate", "Joining Date", 100);&lt;br /&gt;&lt;br /&gt; ColumnModel cm = new ColumnModel(Arrays.asList(name, salary, date));&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Create a TreeGrid, &lt;span id="keyword1"&gt;treeGrid&lt;/span&gt; from the TreeStore, &lt;span id="keyword1"&gt;store&lt;/span&gt; and ColumnModel, &lt;span id="keyword1"&gt;cm&lt;/span&gt;. Then set some property of the treeGrid. Finally create a ContentPanel and add the treeGrid to this panel.&lt;br /&gt;&lt;span style="font-family: monospace; white-space: pre;"&gt;TreeGrid&amp;lt;ModelData&amp;gt; treeGrid = new TreeGrid&amp;lt;ModelData&amp;gt;(store, cm);&lt;/span&gt;&lt;br /&gt;&lt;pre class="java" name="code"&gt;treeGrid.setBorders(true);&lt;br /&gt; treeGrid.getStyle().setLeafIcon(ICONS.user_add());&lt;br /&gt; treeGrid.setSize(400, 400); &lt;br /&gt; treeGrid.setAutoExpandColumn("name");&lt;br /&gt; treeGrid.setTrackMouseOver(false);&lt;br /&gt;&lt;br /&gt; ContentPanel cp = new ContentPanel();&lt;br /&gt; cp.setBodyBorder(false);&lt;br /&gt; cp.setHeading("TreeGrid");&lt;br /&gt; cp.setButtonAlign(HorizontalAlignment.CENTER);&lt;br /&gt; cp.setLayout(new FitLayout());&lt;br /&gt; cp.setFrame(true);&lt;br /&gt; cp.setSize(600, 300);&lt;br /&gt; cp.add(treeGrid);&lt;br /&gt; RootPanel.get().add(cp);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Run the application and the output will be like this.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://lh3.ggpht.com/_MwOzNujvBcI/SvAJIXjN-0I/AAAAAAAAAOQ/zNnCT_1K43A/s1600-h/basicTreeGrid%5B10%5D.jpg"&gt;&lt;img alt="basicTreeGrid" border="0" height="293" src="http://lh6.ggpht.com/_MwOzNujvBcI/SvAJJJmxP3I/AAAAAAAAAOU/SnGefkpwVVU/basicTreeGrid_thumb%5B8%5D.jpg?imgmax=800" style="border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline;" title="basicTreeGrid" width="463" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;To view the live demo of this tutorial &lt;a href="http://gxtexamplegallery.appspot.com/"&gt;Click here&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-2444181236386634125?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/2444181236386634125/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=2444181236386634125' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/2444181236386634125'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/2444181236386634125'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2009/11/how-to-create-basic-treegrid-using.html' title='How to Create a Basic TreeGrid using GXT(Ext GWT)'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh6.ggpht.com/_MwOzNujvBcI/SvAJJJmxP3I/AAAAAAAAAOU/SnGefkpwVVU/s72-c/basicTreeGrid_thumb%5B8%5D.jpg?imgmax=800' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-1134705390508233656</id><published>2009-10-27T07:19:00.000-07:00</published><updated>2009-10-27T07:19:40.052-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JDO'/><category scheme='http://www.blogger.com/atom/ns#' term='Google App Engine'/><category scheme='http://www.blogger.com/atom/ns#' term='Ext GWT'/><category scheme='http://www.blogger.com/atom/ns#' term='gxt'/><category scheme='http://www.blogger.com/atom/ns#' term='GXT Example'/><title type='text'>An Example Gallery of GXT(Ext GWT)</title><content type='html'>After written some blogs about GXT Grid and Tree I planned for merging all those in a single application. Beside this I want to test JDO in Google App Engine. As a result of this I have made a tiny application and deployed in the Google App Engine. &lt;a href="http://gxtexamplegallery.appspot.com/"&gt;Ext GWT (GXT) Example Gallery&lt;/a&gt;. I will be very pleased if you visit the site and give your valuable comment.&lt;br /&gt;&lt;br /&gt;You can also check out the latest code of the project from Google svn by running this command&lt;br /&gt;&lt;br /&gt;&lt;span id="keyword1"&gt; svn checkout http://gxtexamplegallery.googlecode.com/svn/trunk/ gxtexamplegallery-read-only&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;script type="text/javascript"&gt;&lt;!--google_ad_client = "pub-3583615898080871";/* 468x60, created 10/2/09 BELOW POST */google_ad_slot = "5516300168";google_ad_width = 468;google_ad_height = 60;//--&gt;&lt;/script&gt;&lt;br /&gt;&lt;script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"&gt;&lt;/script&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-1134705390508233656?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/1134705390508233656/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=1134705390508233656' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/1134705390508233656'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/1134705390508233656'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2009/10/example-gallery-of-gxtext-gwt.html' title='An Example Gallery of GXT(Ext GWT)'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-4281433832755593506</id><published>2009-10-02T03:31:00.000-07:00</published><updated>2010-02-19T01:29:02.890-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Context Menu'/><category scheme='http://www.blogger.com/atom/ns#' term='Ext GWT'/><category scheme='http://www.blogger.com/atom/ns#' term='GXT(Ext GWT) Context Menu With TreePanel Example'/><category scheme='http://www.blogger.com/atom/ns#' term='gxt'/><category scheme='http://www.blogger.com/atom/ns#' term='GXT(Ext GWT) Tree example'/><title type='text'>Add Context Menu with GXT(Ext GWT) TreePanel</title><content type='html'>Context Menu is frequently used with tree if you want to present a very user friendly interface to user like add,delete or enable,disable a tree node. Here i show you how you can add a context menu with add and delete menu items with GXT TreePanel very easily.&lt;br /&gt;&lt;a href="http://zawoad.blogspot.com/2009/06/getting-started-with-gwt-create-your.html" target="_blank"&gt;Create a new project&lt;/a&gt; named &lt;i&gt;&lt;b&gt;GxtContextMenuTree &lt;/b&gt;&lt;/i&gt;and &lt;a href="http://zawoad.blogspot.com/2009/06/how-to-use-ext-gwt-in-eclipse-34-to.html" target="_blank"&gt;add GXT library&lt;/a&gt; in the project. The tree node objects must possess the functionality of &lt;b&gt;&lt;i&gt;BaseTreeModel&lt;/i&gt;&lt;/b&gt; of GXT. I have used the same&amp;nbsp;&lt;b&gt;&lt;i&gt;EmployeeTreeNode&amp;nbsp;&lt;/i&gt;&lt;/b&gt;and &lt;b&gt;&lt;i&gt;Folder&lt;/i&gt;&lt;/b&gt; class for leaf and parent nodes that i used in my previous blogs related to GXT TreePanel. And in the &lt;b&gt;&lt;i&gt;TestData&lt;/i&gt;&lt;/b&gt; class i have populated the data to build the tree. You will find the code for these classes &lt;a href="http://zawoad.blogspot.com/2009/09/how-to-create-simple-tree-using-gxtext.html" target="_blank"&gt;here&lt;/a&gt;.&amp;nbsp; Create a new package &lt;b&gt;&lt;i&gt;model &lt;/i&gt;&lt;/b&gt;under the client package and place the EmployeeTreeNode and Folder class there. &lt;br /&gt;&lt;div&gt;&lt;script type="text/javascript"&gt;&lt;!--google_ad_client = "pub-3583615898080871";/* 468x60, created 10/2/09 BELOW POST */google_ad_slot = "5516300168";google_ad_width = 468;google_ad_height = 60;//--&gt;&lt;/script&gt;&lt;br /&gt;&lt;script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"&gt;&lt;/script&gt;&lt;br /&gt;&lt;/div&gt;Now remove all the auto generated code from the GxtContextMenuTree class which is the entry point class of your project.&amp;nbsp; Go to the &lt;i&gt;&lt;b&gt;onModuleLoad&amp;nbsp; &lt;/b&gt;&lt;/i&gt;method of the class and first create a root node of the tree. Then create a &lt;b&gt;&lt;i&gt;TreeStore, store&lt;/i&gt;&lt;/b&gt; and add data to this store from the root node. Now create a &lt;b&gt;&lt;i&gt;TreePanel, tree &lt;/i&gt;&lt;/b&gt;from this store and set some property of the tree. &lt;br /&gt;&lt;pre class="java" name="code"&gt;final Folder rootNode = TestData.getTreeModel();&lt;br /&gt;&lt;br /&gt;final TreeStore&amp;lt;ModelData&amp;gt; store = new TreeStore&amp;lt;ModelData&amp;gt;();&lt;br /&gt;store.add((List) rootNode.getChildren(), true);&lt;br /&gt;&lt;br /&gt;final TreePanel&amp;lt;ModelData&amp;gt; tree = new TreePanel&amp;lt;ModelData&amp;gt;(store);&lt;br /&gt;tree.setDisplayProperty("name");&lt;br /&gt;tree.getStyle().setLeafIcon(ICONS.user_add());&lt;br /&gt;tree.setWidth(250);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now create a gxt &lt;b&gt;&lt;i&gt;Menu&lt;/i&gt;&lt;/b&gt; and add two &lt;b&gt;&lt;i&gt;MenuItem&lt;/i&gt;&lt;/b&gt; &lt;b&gt;&lt;i&gt;insert&lt;/i&gt;&lt;/b&gt; and &lt;b&gt;&lt;i&gt;remove &lt;/i&gt;&lt;/b&gt;with the menu.&lt;br /&gt;&lt;pre class="java" name="code"&gt;Menu contextMenu = new Menu();&lt;br /&gt;contextMenu.setWidth(140);&lt;br /&gt;&lt;br /&gt;MenuItem insert = new MenuItem();&lt;br /&gt;insert.setText("Insert Item");&lt;br /&gt;insert.setIcon(ICONS.add());&lt;br /&gt;contextMenu.add(insert);&lt;br /&gt;&lt;br /&gt;MenuItem remove = new MenuItem();&lt;br /&gt;remove.setText("Remove Selected");&lt;br /&gt;remove.setIcon(ICONS.delete());&lt;br /&gt;contextMenu.add(remove);&lt;/pre&gt;&lt;br /&gt;What you want to do by clicking on these menu items, just write them in the &lt;b&gt;&lt;i&gt;addSelectionListener&lt;/i&gt;&lt;/b&gt; method of the MenuItem. Then set the menu to the tree as a context menu by &lt;b&gt;&lt;i&gt;setContextMenu&lt;/i&gt;&lt;/b&gt; method of the TreePanel.&lt;br /&gt;&lt;pre class="java" name="code"&gt;insert.addSelectionListener(new SelectionListener&amp;lt;MenuEvent&amp;gt;() {&lt;br /&gt;public void componentSelected(MenuEvent ce) {&lt;br /&gt;ModelData folder = tree.getSelectionModel().getSelectedItem();&lt;br /&gt;if (folder != null) {&lt;br /&gt;Folder child = new Folder("Add Child " + count++);&lt;br /&gt;store.add(folder, child, false);&lt;br /&gt;tree.setExpanded(folder, true);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;});&lt;br /&gt;&lt;br /&gt;remove.addSelectionListener(new SelectionListener&amp;lt;MenuEvent&amp;gt;() {&lt;br /&gt;public void componentSelected(MenuEvent ce) {&lt;br /&gt;List&amp;lt;ModelData&amp;gt; selected = tree.getSelectionModel().getSelectedItems();&lt;br /&gt;for (ModelData sel : selected) &lt;br /&gt;{&lt;br /&gt;store.remove(sel);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;});&lt;br /&gt;&lt;br /&gt;tree.setContextMenu(contextMenu);&lt;br /&gt;RootPanel.get().add(tree);&lt;/pre&gt;&lt;br /&gt;In the addSelectionListener method of the insert menu item i have written the code for adding a Folder node with the selected node and in the same method of the remove menu item code for removing a list of selected nodes.&amp;nbsp;To view the live demo of this tutorial&amp;nbsp;&lt;a href="http://gxtexamplegallery.appspot.com/"&gt;Click here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://lh4.ggpht.com/_MwOzNujvBcI/SsXVYkog3PI/AAAAAAAAAOI/ErPGd34p9vE/s1600-h/contextMenuTree%5B11%5D.jpg"&gt;&lt;img alt="contextMenuTree" border="0" height="378" src="http://lh5.ggpht.com/_MwOzNujvBcI/SsXVaJFXuOI/AAAAAAAAAOM/Fl_A0pV28wA/contextMenuTree_thumb%5B9%5D.jpg?imgmax=800" style="border: 0px none; display: inline;" title="contextMenuTree" width="520" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-4281433832755593506?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/4281433832755593506/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=4281433832755593506' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/4281433832755593506'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/4281433832755593506'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2009/09/add-context-menu-with-gxtext-gwt.html' title='Add Context Menu with GXT(Ext GWT) TreePanel'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh5.ggpht.com/_MwOzNujvBcI/SsXVaJFXuOI/AAAAAAAAAOM/Fl_A0pV28wA/s72-c/contextMenuTree_thumb%5B9%5D.jpg?imgmax=800' height='72' width='72'/><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-1082602066416705490</id><published>2009-09-26T02:46:00.000-07:00</published><updated>2010-02-19T01:30:36.632-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ext GWT'/><category scheme='http://www.blogger.com/atom/ns#' term='GXT Tree Filter'/><category scheme='http://www.blogger.com/atom/ns#' term='gxt'/><category scheme='http://www.blogger.com/atom/ns#' term='GXT(Ext GWT) Tree example'/><title type='text'>Add Filter Functionality with GXT(Ext GWT) TreePanel</title><content type='html'>In my &lt;a href="http://zawoad.blogspot.com/2009/09/how-to-create-simple-tree-using-gxtext.html" target="_blank"&gt;previous blog&lt;/a&gt; i have articulated how you can create a basic tree using the GXT TreePanel. In the next few blogs i will try to write about some marvelous features which can be easily integrated with TreePanel. Here i state how to add filter functionality with TreePanel.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://zawoad.blogspot.com/2009/06/getting-started-with-gwt-create-your.html"&gt;Create a new project&lt;/a&gt; named &lt;b&gt;&lt;i&gt;GxtFilterTree&lt;/i&gt;&lt;/b&gt; and &lt;a href="http://zawoad.blogspot.com/2009/06/how-to-use-ext-gwt-in-eclipse-34-to.html"&gt;add GXT library&lt;/a&gt; in the project. The tree node objects must possess the functionality of &lt;span id="keyword1"&gt;BaseTreeModel&lt;/span&gt; of GXT. I have used the same&amp;nbsp;EmployeeTreeNode&amp;nbsp;and &lt;span id="keyword1"&gt;Folder&lt;/span&gt; class for leaf and parent nodes that i used in my previous blog. And in the &lt;span id="keyword1"&gt;TestData&lt;/span&gt; class i have populated the data to build the tree. You will find the code for these classes &lt;a href="http://zawoad.blogspot.com/2009/09/how-to-create-simple-tree-using-gxtext.html" target="_blank"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Go to the &lt;span id="keyword1"&gt;onModuleLoad&lt;/span&gt; method of &lt;span id="keyword1"&gt;GxtFilterTree&lt;/span&gt; class. Remove all the auto generated code of this method. Now create a TreeLoader, &lt;span id="keyword1"&gt;loader&lt;/span&gt;. &lt;br /&gt;&lt;pre class="java" name="code"&gt;TreeLoader&amp;lt;ModelData&amp;gt; loader = new BaseTreeLoader&amp;lt;ModelData&amp;gt;(&lt;br /&gt;  new TreeModelReader&amp;lt;List&amp;lt;ModelData&amp;gt;&amp;gt;());&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span id="keyword1"&gt;BaseTreeLoader&lt;/span&gt; is default implementation of the TreeLoader interface which also extends the functionality of &lt;span id="keyword1"&gt;BaseLoader&lt;/span&gt;. Then create TreeStore, &lt;span id="keyword1"&gt;store&lt;/span&gt; by using the loader and create a TreePanel, &lt;span id="keyword1"&gt;tree&lt;/span&gt; with the store. Pass the root of the tree to the &lt;span id="keyword1"&gt;loader.load&lt;/span&gt; method as a load configuration which loads data using the configuration. You can get the root node from &lt;span id="keyword1"&gt;getTreeModel&lt;/span&gt; method of &lt;span id="keyword1"&gt;TestData&lt;/span&gt; class.&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;script type="text/javascript"&gt;&lt;!--google_ad_client = "pub-3583615898080871";/* 468x60, created 10/2/09 BELOW POST */google_ad_slot = "5516300168";google_ad_width = 468;google_ad_height = 60;//--&gt;&lt;/script&gt;&lt;br /&gt;&lt;script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"&gt;&lt;/script&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;pre class="java" name="code"&gt;TreeStore&amp;lt;ModelData&amp;gt; store = new TreeStore&amp;lt;ModelData&amp;gt;(loader);&lt;br /&gt;TreePanel&amp;lt;ModelData&amp;gt; tree = new TreePanel&amp;lt;ModelData&amp;gt;(store);&lt;br /&gt;tree.setAutoLoad(true);&lt;br /&gt;tree.setDisplayProperty("name");&lt;br /&gt;tree.setWidth(250);&lt;br /&gt;tree.setIconProvider(new ModelIconProvider&amp;lt;ModelData&amp;gt;() {&lt;br /&gt;  public AbstractImagePrototype getIcon(ModelData model) {&lt;br /&gt;    if (((TreeModel) model).isLeaf()) {&lt;br /&gt;      return ICONS.user_add();&lt;br /&gt;    }&lt;br /&gt;    return null;&lt;br /&gt;  }&lt;br /&gt;});&lt;br /&gt;loader.load(TestData.getTreeModel());&lt;/pre&gt;&lt;br /&gt;&lt;span id="keyword1"&gt;setAutoLoad&lt;/span&gt; method sets whether all children should automatically be loaded recursively. Other setter methods of TreePanel are self explanatory. &lt;br /&gt;&lt;br /&gt;Now the time for creating a &lt;span id="keyword1"&gt;StoreFilterField&lt;/span&gt; and bind this to the &lt;span id="keyword1"&gt;store&lt;/span&gt;.&lt;br /&gt;&lt;pre class="java" name="code"&gt;StoreFilterField&amp;lt;ModelData&amp;gt; filter = new StoreFilterField&amp;lt;ModelData&amp;gt;() {&lt;br /&gt;  @Override&lt;br /&gt;  protected boolean doSelect(Store&amp;lt;ModelData&amp;gt; store,&lt;br /&gt;  ModelData parent, ModelData record, String property,&lt;br /&gt;  String filter) {&lt;br /&gt;    // only match leaf nodes&lt;br /&gt;    if (record instanceof Folder) { &lt;br /&gt;      return false;&lt;br /&gt;    }&lt;br /&gt;    String name = record.get("name");&lt;br /&gt;    name = name.toLowerCase();&lt;br /&gt;    if (name.startsWith(filter.toLowerCase())) {&lt;br /&gt;      return true;&lt;br /&gt;    }&lt;br /&gt;    return false;&lt;br /&gt;  }&lt;br /&gt;};&lt;br /&gt;filter.bind(store);&lt;/pre&gt;&lt;br /&gt;StoreFilterField can filter any &lt;span id="keyword1"&gt;Store&lt;/span&gt; implementation. You just have to implement the &lt;span id="keyword1"&gt;doSelect&lt;/span&gt; method this class. Here i have matched only the leaf node.&lt;br /&gt;&lt;br /&gt;You are just one step behind to run the application. Create a panel to add the filter and the tree and add that panel to the RootPanel. That’s all. Run the application and check the filter functionality.&lt;br /&gt;&lt;pre class="java" name="code"&gt;VerticalPanel panel = new VerticalPanel();&lt;br /&gt;panel.addStyleName("x-small-editor");&lt;br /&gt;panel.setSpacing(8);&lt;br /&gt;panel.add(new Html("&amp;lt;span class=text&amp;gt;Enter a search string such as 'dirk'&amp;lt;/span&amp;gt;"));&lt;br /&gt;panel.add(filter);&lt;br /&gt;panel.add(tree);&lt;br /&gt;RootPanel.get().add(panel);&lt;br /&gt;&lt;br /&gt;}&lt;/pre&gt;To view the live demo of this tutorial&amp;nbsp;&lt;a href="http://gxtexamplegallery.appspot.com/"&gt;Click here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://lh5.ggpht.com/_MwOzNujvBcI/Srxnp1wZ5SI/AAAAAAAAANA/a_y4A7Na_KI/s1600-h/treeWithFilterFunc%5B9%5D.jpg"&gt;&lt;img alt="treeWithFilterFunc" border="0" height="444" src="http://lh3.ggpht.com/_MwOzNujvBcI/SrxnrqlcphI/AAAAAAAAANE/EjAvMPZ4qg4/treeWithFilterFunc_thumb%5B7%5D.jpg?imgmax=800" style="border-width: 0px; display: inline;" title="treeWithFilterFunc" width="509" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-1082602066416705490?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/1082602066416705490/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=1082602066416705490' title='9 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/1082602066416705490'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/1082602066416705490'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2009/09/add-filter-functionality-with-gxtext.html' title='Add Filter Functionality with GXT(Ext GWT) TreePanel'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh3.ggpht.com/_MwOzNujvBcI/SrxnrqlcphI/AAAAAAAAANE/EjAvMPZ4qg4/s72-c/treeWithFilterFunc_thumb%5B7%5D.jpg?imgmax=800' height='72' width='72'/><thr:total>9</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-4861268154875011861</id><published>2009-09-23T01:29:00.000-07:00</published><updated>2010-02-19T01:31:51.798-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='TreePanel'/><category scheme='http://www.blogger.com/atom/ns#' term='Ext GWT'/><category scheme='http://www.blogger.com/atom/ns#' term='gxt'/><category scheme='http://www.blogger.com/atom/ns#' term='GXT(Ext GWT) Tree example'/><title type='text'>How to Create a Simple Tree Using GXT(Ext GWT) TreePanel</title><content type='html'>TreePanel is another powerful UI tools provide by GXT. &amp;nbsp;It has expand-collapse functionality. You can add context menu or can add filter functionality with the TreePanel very easily.&amp;nbsp;Here i describe every steps of creating a simple basic Tree using GXT in detail.&lt;br /&gt;&lt;br /&gt;First&amp;nbsp;&lt;a href="http://zawoad.blogspot.com/2009/06/getting-started-with-gwt-create-your.html" target="_blank"&gt;create a new project&lt;/a&gt;&amp;nbsp;named&amp;nbsp;&lt;b&gt;GxtBasicTree&amp;nbsp;&lt;/b&gt;and&amp;nbsp;&lt;a href="http://zawoad.blogspot.com/2009/06/how-to-use-ext-gwt-in-eclipse-34-to.html" target="_blank"&gt;add GXT library&lt;/a&gt;&amp;nbsp;in the project. The tree node objects must possess the functionality of &lt;i&gt;&lt;b&gt;BaseTreeModel &lt;/b&gt;&lt;/i&gt;of GXT. In my example the leaf node objects are of &lt;i&gt;&lt;b&gt;EmployeeTreeNode&amp;nbsp;&lt;/b&gt;&lt;/i&gt;class and parent node objects are of &lt;i&gt;&lt;b&gt;Folder &lt;/b&gt;&lt;/i&gt;class. Both of the classes extend&amp;nbsp;BaseTreeModel class.&amp;nbsp;Here is the code for the Employee class.&lt;br /&gt;&lt;pre class="java" name="code"&gt;package com.ratul.GxtBasicTree.client.model;&lt;br /&gt;&lt;br /&gt;import java.util.Date;&lt;br /&gt;&lt;br /&gt;import com.extjs.gxt.ui.client.data.BaseTreeModel;&lt;br /&gt;&lt;br /&gt;public class EmployeeTreeNode extends BaseTreeModel {&lt;br /&gt; private static final long serialVersionUID = 1L;&lt;br /&gt;&lt;br /&gt;public EmployeeTreeNode() {&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  public EmployeeTreeNode(String name, double salary, Date joiningdate) {&lt;br /&gt;    set("name", name);&lt;br /&gt;    set("salary", salary);&lt;br /&gt;    set("joiningdate", joiningdate);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  public Date getJoiningdate() {&lt;br /&gt;    return (Date) get("joiningdate");&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  public String getName() {&lt;br /&gt;    return (String) get("name");&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  public double getSalary() {&lt;br /&gt;    Double salary = (Double) get("salary");&lt;br /&gt;    return salary.doubleValue();&lt;br /&gt;  }&lt;br /&gt;  public String toString() {&lt;br /&gt;    return getName();&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;As i have said previously the objects of the Folder class can be parent node for the Tree. So this class should have the functionality of adding children nodes. The constructor with a String and an Array of BaseTreeModel object serves the purpose. Here is the code for the Folder class.&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;script type="text/javascript"&gt;&lt;!--google_ad_client = "pub-3583615898080871";/* 468x60, created 10/2/09 BELOW POST */google_ad_slot = "5516300168";google_ad_width = 468;google_ad_height = 60;//--&gt;&lt;/script&gt; &lt;script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"&gt;&lt;/script&gt; &lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;pre class="java" name="code"&gt;package com.ratul.GxtBasicTree.client.model;&lt;br /&gt;&lt;br /&gt;import java.io.Serializable;&lt;br /&gt;&lt;br /&gt;import com.extjs.gxt.ui.client.data.BaseTreeModel;&lt;br /&gt;&lt;br /&gt;public class Folder extends BaseTreeModel implements Serializable {&lt;br /&gt; private static final long serialVersionUID = 1L;&lt;br /&gt;private static int ID = 0;&lt;br /&gt;  &lt;br /&gt;  public Folder() {&lt;br /&gt;    set("id", ID++);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  public Folder(String name) {&lt;br /&gt;    set("id", ID++);&lt;br /&gt;    set("name", name);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  public Folder(String name, BaseTreeModel[] children) {&lt;br /&gt;    this(name);&lt;br /&gt;    for (int i = 0; i &amp;lt; children.length; i++) {&lt;br /&gt;      add(children[i]);&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  public Integer getId() {&lt;br /&gt;    return (Integer) get("id");&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  public String getName() {&lt;br /&gt;    return (String) get("name");&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  public String toString() {&lt;br /&gt;    return getName();&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now populate a root node containing all the child nodes by using the above two classes in the &lt;span id="keyword1"&gt;getTreeModel&lt;/span&gt; methodh of the &lt;span id="keyword1"&gt;TestData&lt;/span&gt; class.&lt;br /&gt;&lt;pre class="java" name="code"&gt;package com.ratul.GxtBasicTree.client;&lt;br /&gt;&lt;br /&gt;import com.google.gwt.i18n.client.DateTimeFormat;&lt;br /&gt;import com.ratul.GxtBasicTree.client.model.Employee;&lt;br /&gt;import com.ratul.GxtBasicTree.client.model.Folder;&lt;br /&gt;&lt;br /&gt;public class TestData {&lt;br /&gt;&lt;br /&gt;  public static Folder getTreeModel() &lt;br /&gt;  {&lt;br /&gt;     DateTimeFormat f = DateTimeFormat.getFormat("yyyy-mm-dd");&lt;br /&gt;  Folder[] folders = new Folder[] {&lt;br /&gt;   new Folder("General Administration", new Folder[] {&lt;br /&gt;    new Folder("General Manager", new EmployeeTreeNode[] {&lt;br /&gt;     new EmployeeTreeNode("Hollie Voss", 150000, f.parse("2006-05-01")),&lt;br /&gt;     new EmployeeTreeNode("Heriberto Rush", 150000,f.parse("2007-08-01")), }),&lt;br /&gt;    new Folder("Executive", new EmployeeTreeNode[] {&lt;br /&gt;     new EmployeeTreeNode("Christina Blake", 45000,f.parse("2008-11-01")),&lt;br /&gt;     new EmployeeTreeNode("Chad Andrews", 45000, f.parse("2008-07-01")), }), }),&lt;br /&gt; &lt;br /&gt;   new Folder("Information Technology",new Folder[] {&lt;br /&gt;    new Folder("Senior S/W Engineer",new EmployeeTreeNode[] {&lt;br /&gt;     new EmployeeTreeNode("Dirk Newman", 70000,f.parse("2007-08-21")),&lt;br /&gt;     new EmployeeTreeNode("Emerson Milton",72000,f.parse("2009-05-07")),&lt;br /&gt;     new EmployeeTreeNode("Gail Horton", 680000,f.parse("2008-05-01")), }),&lt;br /&gt;    new Folder("S/W Engineer",new EmployeeTreeNode[] {&lt;br /&gt;     new EmployeeTreeNode("Claudio Engle", 50000,f.parse("2007-02-01")),&lt;br /&gt;     new EmployeeTreeNode("Buster misjenou",52000,f.parse("2009-06-10")),&lt;br /&gt;     new EmployeeTreeNode("Bell Snedden", 50000,f.parse("2008-12-01")),&lt;br /&gt;     new EmployeeTreeNode("Benito Meeks", 55000,f.parse("2006-05-01")), }), }),&lt;br /&gt; &lt;br /&gt;   new Folder("Marketing", new Folder[] { &lt;br /&gt;    new Folder("Executive",new EmployeeTreeNode[] {&lt;br /&gt;     new EmployeeTreeNode("Candice Carson", 50000, f.parse("2007-08-21")),&lt;br /&gt;     new EmployeeTreeNode("Mildred Starnes", 50000,f.parse("2008-05-01")),&lt;br /&gt;     new EmployeeTreeNode("Claudio Engle", 50000, f.parse("2009-06-15")), }), }), &lt;br /&gt;  };&lt;br /&gt;&lt;br /&gt;  Folder root = new Folder("root");&lt;br /&gt;  for (int i = 0; i &amp;lt; folders.length; i++) {&lt;br /&gt;   root.add((Folder) folders[i]);&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  return root;&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;You data is now ready to create a simple Tree.&amp;nbsp;Go to the&amp;nbsp;&lt;span id="keyword1"&gt;onModuleLoad&lt;/span&gt;&amp;nbsp;method of &lt;span id="keyword1"&gt;GxtBasicTree&lt;/span&gt; class. Remove all the auto generated code of this method. Now first create a root object named &lt;span id="keyword1"&gt;model&lt;/span&gt; of the Folder class from &lt;span id="keyword1"&gt;TestData.getTreeModel()&lt;/span&gt; method and create a TreeStore object,&lt;span id="keyword1"&gt;store&lt;/span&gt; from this model. &lt;br /&gt;&lt;pre class="java" name="code"&gt;public static final ExampleIcons ICONS = GWT.create(ExampleIcons.class);&lt;br /&gt;public void onModuleLoad() &lt;br /&gt;{&lt;br /&gt;       Folder model = TestData.getTreeModel();  &lt;br /&gt;     &lt;br /&gt;       TreeStore&amp;lt;ModelData&amp;gt; store = new TreeStore&amp;lt;ModelData&amp;gt;();  &lt;br /&gt;       store.add(model.getChildren(), true);  &lt;br /&gt; &lt;/pre&gt;Now create a TreePanel, &lt;span id="keyword1"&gt;tree&lt;/span&gt; from this store and set display name, width and style of the tree.  &lt;br /&gt;&lt;pre class="java" name="code"&gt;final TreePanel&amp;lt;ModelData&amp;gt; tree = new TreePanel&amp;lt;ModelData&amp;gt;(store);  &lt;br /&gt;       tree.setDisplayProperty("name");  &lt;br /&gt;       tree.setWidth(250);  &lt;br /&gt;       tree.getStyle().setLeafIcon(ICONS.user_add());&lt;br /&gt;&lt;/pre&gt;The two button &lt;span id="keyword1"&gt;expand&lt;/span&gt; and &lt;span id="keyword1"&gt;collapse&lt;/span&gt; provide the expand and collapse functionality by simple calling the &lt;span id="keyword1"&gt;tree.expandAll()&lt;/span&gt; and &lt;span id="keyword1"&gt;tree.collapseAll()&lt;/span&gt; method.  &lt;br /&gt;&lt;pre class="java" name="code"&gt;ButtonBar buttonBar = new ButtonBar();  &lt;br /&gt;       Button expand = new Button("Expand All"); &lt;br /&gt;       Button collapse = new Button("Collapse All"); &lt;br /&gt;       expand.addSelectionListener(new SelectionListener&amp;lt;ButtonEvent&amp;gt;() {  &lt;br /&gt;       public void componentSelected(ButtonEvent ce) {  &lt;br /&gt;           tree.expandAll();  &lt;br /&gt;         }  &lt;br /&gt;       });&lt;br /&gt;       &lt;br /&gt;       collapse.addSelectionListener(new SelectionListener&amp;lt;ButtonEvent&amp;gt;() {  &lt;br /&gt;        public void componentSelected(ButtonEvent ce) {  &lt;br /&gt;            tree.collapseAll();  &lt;br /&gt;          }  &lt;br /&gt;        });&lt;br /&gt;       buttonBar.add(expand);&lt;br /&gt;       buttonBar.add(collapse);&lt;br /&gt;        &lt;br /&gt;       RootPanel.get().add(buttonBar);&lt;br /&gt;       RootPanel.get().add(tree);&lt;br /&gt;       &lt;br /&gt; }&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;That's all. Run it and check the functionality of the simple tree.&amp;nbsp;To view the live demo of this tutorial&amp;nbsp;&lt;a href="http://gxtexamplegallery.appspot.com/"&gt;Click here&lt;/a&gt;.&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/_MwOzNujvBcI/Srnb4twjRqI/AAAAAAAAAMw/kJCYi3p-cDc/s1600-h/basicTree.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/_MwOzNujvBcI/Srnb4twjRqI/AAAAAAAAAMw/kJCYi3p-cDc/s400/basicTree.jpg" /&gt;&lt;/a&gt; &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-4861268154875011861?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/4861268154875011861/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=4861268154875011861' title='28 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/4861268154875011861'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/4861268154875011861'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2009/09/how-to-create-simple-tree-using-gxtext.html' title='How to Create a Simple Tree Using GXT(Ext GWT) TreePanel'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_MwOzNujvBcI/Srnb4twjRqI/AAAAAAAAAMw/kJCYi3p-cDc/s72-c/basicTree.jpg' height='72' width='72'/><thr:total>28</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-5600594986237281911</id><published>2009-09-05T09:47:00.000-07:00</published><updated>2010-02-19T01:32:51.895-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='GWT'/><category scheme='http://www.blogger.com/atom/ns#' term='GXT Editable Grid'/><category scheme='http://www.blogger.com/atom/ns#' term='GXT(Ext GWT) Grid example'/><category scheme='http://www.blogger.com/atom/ns#' term='gxt'/><category scheme='http://www.blogger.com/atom/ns#' term='Grid'/><title type='text'>Working with GXT(Ext GWT) Grid : Create an Editable Grid</title><content type='html'>Last week i was so busy that i can not afford to manage time on writing. And i am afraid that whether i can keep my promise on writing a series of tutorials about GXT and GWT or not. In the upcoming days i have to work in six! projects simultaneously. Good thing is that there will be a lot of new things that i can learn and surely i will share those here whenever i get time. Now i will show you how you can make a GXT Grid editable with TextField, ComboBox and Date Picker.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://zawoad.blogspot.com/2009/06/getting-started-with-gwt-create-your.html"&gt;Create a new project&lt;/a&gt; named GxtEditableGrid and &lt;a href="http://zawoad.blogspot.com/2009/06/how-to-use-ext-gwt-in-eclipse-34-to.html"&gt;add GXT library&lt;/a&gt; in the project. As like my previous blogs about GXT Grid i have used the same &lt;b&gt;&lt;i&gt;Employee &lt;/i&gt;&lt;/b&gt;model and &lt;b&gt;&lt;i&gt;TestData &lt;/i&gt;&lt;/b&gt;class for generating data. You will find the code of these classes &lt;a href="http://zawoad.blogspot.com/2009/08/how-to-create-simple-grid-using-gxtext.html"&gt;here&lt;/a&gt;. Go to the onModuleLoad method of GxtEditableGrid class and remove all the auto generated code of this method. &lt;br /&gt;&lt;br /&gt;Starting with creating a list of ColumnConfig and a ColumnConfig instance named column. Configure this column to show and edit Employee Name first. To add the editing functionality create a TextField and a CellEditor with this TextField. Then set the CellEditor as the editor of the column.&lt;br /&gt;&lt;br /&gt;&lt;pre class="java" name="code"&gt;List&amp;lt;ColumnConfig&amp;gt; configs = new ArrayList&amp;lt;ColumnConfig&amp;gt;();&lt;br /&gt;ColumnConfig column = new ColumnConfig();&lt;br /&gt;column.setId("name");&lt;br /&gt;column.setHeader("Employee Name");&lt;br /&gt;column.setWidth(200);&lt;br /&gt;TextField&amp;lt;String&amp;gt; text = new TextField&amp;lt;String&amp;gt;();  &lt;br /&gt;text.setAllowBlank(false);  &lt;br /&gt;text.setAutoValidate(true);  &lt;br /&gt;column.setEditor(new CellEditor(text));&lt;br /&gt;configs.add(column);&amp;nbsp;&lt;br /&gt;&lt;/pre&gt;&lt;div&gt;&lt;script type="text/javascript"&gt;&lt;!--google_ad_client = "pub-3583615898080871";/* 468x60, created 10/2/09 BELOW POST */google_ad_slot = "5516300168";google_ad_width = 468;google_ad_height = 60;//--&gt;&lt;/script&gt;&lt;br /&gt;&lt;script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"&gt;&lt;/script&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;For the Department column rather than using a TextField we are going to use a ComboBox to edit this field. First create a SimpleComboBox and add the possible values to it.&lt;br /&gt;&lt;br /&gt;&lt;pre class="java" name="code"&gt;final SimpleComboBox&amp;lt;String&amp;gt; combo = new SimpleComboBox&amp;lt;String&amp;gt;();  &lt;br /&gt;combo.setTriggerAction(TriggerAction.ALL);  &lt;br /&gt;combo.add("General Administration");  &lt;br /&gt;combo.add("Information Technology");  &lt;br /&gt;combo.add("Marketing");  &lt;br /&gt;combo.add("Accounts");&amp;nbsp;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Then create a CellEditor with the SimpleComboBox and set it as the editor of the department column.&lt;br /&gt;&lt;br /&gt;&lt;pre class="java" name="code"&gt;CellEditor editor = new CellEditor(combo) {  &lt;br /&gt;@Override  &lt;br /&gt;public Object preProcessValue(Object value) {  &lt;br /&gt;if (value == null) {  &lt;br /&gt;return value;  &lt;br /&gt;}  &lt;br /&gt;return combo.findModel(value.toString());  &lt;br /&gt;}  &lt;br /&gt;&lt;br /&gt;@Override  &lt;br /&gt;public Object postProcessValue(Object value) {  &lt;br /&gt;if (value == null) {  &lt;br /&gt;return value;  &lt;br /&gt;}  &lt;br /&gt;return ((ModelData) value).get("value");  &lt;br /&gt;}  &lt;br /&gt;};  &lt;br /&gt;&lt;br /&gt;column = new ColumnConfig("department", "Department", 150);&lt;br /&gt;column.setAlignment(HorizontalAlignment.LEFT);&lt;br /&gt;column.setEditor(editor);  &lt;br /&gt;configs.add(column);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;For the Designation column configure it like the Employee Name column and for the Salary column set a cell editor with NumberField. That is this field will only accept numeric values.&lt;br /&gt;&lt;br /&gt;&lt;pre class="java" name="code"&gt;column = new ColumnConfig("designation", "Designation", 150);&lt;br /&gt;column.setAlignment(HorizontalAlignment.LEFT);&lt;br /&gt;TextField&amp;lt;String&amp;gt; text2 = new TextField&amp;lt;String&amp;gt;();  &lt;br /&gt;text2.setAllowBlank(false);  &lt;br /&gt;text2.setAutoValidate(true);  &lt;br /&gt;column.setEditor(new CellEditor(text2));&lt;br /&gt;configs.add(column);&lt;br /&gt;&lt;br /&gt;column = new ColumnConfig("salary", "Slary", 100);  &lt;br /&gt;column.setAlignment(HorizontalAlignment.RIGHT);  &lt;br /&gt;final NumberFormat number = NumberFormat.getFormat("0.00");  &lt;br /&gt;GridCellRenderer&amp;lt;Employee&amp;gt; checkSalary = new GridCellRenderer&amp;lt;Employee&amp;gt;() {  &lt;br /&gt;public String render(Employee model, String property, ColumnData config, int rowIndex,  &lt;br /&gt;int colIndex, ListStore&amp;lt;Employee&amp;gt; employeeList, Grid&amp;lt;Employee&amp;gt; grid) {  &lt;br /&gt;double val = (Double) model.get(property);  &lt;br /&gt;String style = val &amp;lt; 70000 ? "red" : "green";  &lt;br /&gt;return "&amp;lt;span style='color:" + style + "'&amp;gt;" + number.format(val) + "&amp;lt;/span&amp;gt;";&lt;br /&gt;}  &lt;br /&gt;};  &lt;br /&gt;column.setRenderer(checkSalary); &lt;br /&gt;column.setEditor(new CellEditor(new NumberField()));  &lt;br /&gt;configs.add(column);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;To change date field in a Grid with date picker create a DateField, set a date fomat for the DateField and finally set this as the editor for the ColumnConfig.&lt;br /&gt;&lt;br /&gt;&lt;pre class="java" name="code"&gt;DateField dateField = new DateField();  &lt;br /&gt;dateField.getPropertyEditor().setFormat(DateTimeFormat.getFormat("MM/dd/y"));&lt;br /&gt;&lt;br /&gt;column = new ColumnConfig("joiningdate", "Joining Date", 100);&lt;br /&gt;column.setAlignment(HorizontalAlignment.RIGHT);&lt;br /&gt;column.setEditor(new CellEditor(dateField));  &lt;br /&gt;column.setDateTimeFormat(DateTimeFormat.getMediumDateFormat());&lt;br /&gt;configs.add(column);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;To enable the editable functionality of grid you have to create an instance of EditorGrid class instead of a Grid class now. Other things are described in my previous tutorials about GXT Grid. &lt;br /&gt;&lt;br /&gt;&lt;pre class="java" name="code"&gt;ListStore&amp;lt;Employee&amp;gt; employeeList = new ListStore&amp;lt;Employee&amp;gt;();&lt;br /&gt;employeeList.add(TestData.getEmployees());&lt;br /&gt;ColumnModel cm = new ColumnModel(configs);&lt;br /&gt;&lt;br /&gt;final EditorGrid&amp;lt;Employee&amp;gt; grid = new EditorGrid&amp;lt;Employee&amp;gt;(employeeList, cm);&lt;br /&gt;grid.setStyleAttribute("borderTop", "none");&lt;br /&gt;grid.setAutoExpandColumn("name");&lt;br /&gt;grid.setBorders(true);&lt;br /&gt;grid.setStripeRows(true);&lt;br /&gt;&lt;br /&gt;ContentPanel cp = new ContentPanel();&lt;br /&gt;cp.setBodyBorder(false);&lt;br /&gt;cp.setHeading("Employee List");&lt;br /&gt;cp.setButtonAlign(HorizontalAlignment.CENTER);&lt;br /&gt;cp.setLayout(new FitLayout());&lt;br /&gt;cp.setSize(700, 300);&lt;br /&gt;cp.add(grid);&lt;br /&gt;RootPanel.get().add(cp);&lt;/pre&gt;&lt;br /&gt;That's all. Run the application check the magic GXT.&amp;nbsp;To view the live demo of this tutorial&amp;nbsp;&lt;a href="http://gxtexamplegallery.appspot.com/"&gt;Click here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://lh4.ggpht.com/_MwOzNujvBcI/SpTnlpd9nYI/AAAAAAAAAMo/hMxt5O-kJnw/s1600-h/editableGrid%5B11%5D.jpg"&gt;&lt;img alt="editableGrid" border="0" height="416" src="http://lh4.ggpht.com/_MwOzNujvBcI/SpTnpv7BKkI/AAAAAAAAAMs/nX7O0jkJ74w/editableGrid_thumb%5B9%5D.jpg?imgmax=800" style="border: 0px none; display: inline;" title="editableGrid" width="590" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-5600594986237281911?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/5600594986237281911/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=5600594986237281911' title='43 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/5600594986237281911'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/5600594986237281911'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2009/09/working-with-gxtext-gwt-grid-create.html' title='Working with GXT(Ext GWT) Grid : Create an Editable Grid'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh4.ggpht.com/_MwOzNujvBcI/SpTnpv7BKkI/AAAAAAAAAMs/nX7O0jkJ74w/s72-c/editableGrid_thumb%5B9%5D.jpg?imgmax=800' height='72' width='72'/><thr:total>43</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-993616234379484251</id><published>2009-08-26T21:47:00.000-07:00</published><updated>2009-11-03T02:49:43.577-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='GWT'/><category scheme='http://www.blogger.com/atom/ns#' term='GXT Grid Grouping'/><category scheme='http://www.blogger.com/atom/ns#' term='GXT(Ext GWT) Grid example'/><category scheme='http://www.blogger.com/atom/ns#' term='gxt'/><category scheme='http://www.blogger.com/atom/ns#' term='Grid'/><title type='text'>Working with GXT(Ext GWT) Grid : Add Grouping Funtionality</title><content type='html'>Grouping is very helpful when you view a large set of data. It creates a more readable view for the user. GXT provides us with a very easy way of adding grouping functionality with a grid. Here i describe how to add grouping functionality with GXT grid.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://zawoad.blogspot.com/2009/06/getting-started-with-gwt-create-your.html" target="_blank"&gt;Create a new project&lt;/a&gt;&amp;nbsp;named&amp;nbsp;&lt;b&gt;GxtGridGrouping&amp;nbsp;&lt;/b&gt;and&amp;nbsp;&lt;a href="http://zawoad.blogspot.com/2009/06/how-to-use-ext-gwt-in-eclipse-34-to.html" target="_blank"&gt;add GXT library&lt;/a&gt;&amp;nbsp;in the project. As like my previous blogs about GXT Grid&amp;nbsp;i have used the same &lt;b&gt;&lt;i&gt;Employee &lt;/i&gt;&lt;/b&gt;model and &lt;b&gt;&lt;i&gt;TestData &lt;/i&gt;&lt;/b&gt;class for generating data.&amp;nbsp;You will find the code of these classes&amp;nbsp;&lt;a href="http://zawoad.blogspot.com/2009/08/how-to-create-simple-grid-using-gxtext.html"&gt;here&lt;/a&gt;. Go to the&amp;nbsp;&lt;span id="keyword1"&gt;onModuleLoad&lt;/span&gt;&amp;nbsp;method of&amp;nbsp;GxtGridGrouping class and remove all the auto generated code of this method.&lt;br /&gt;&lt;br /&gt;First create an instance of GroupingStore, a specialized store implementation which extends the ListStore that provides for grouping models by one of the available fields.&lt;br /&gt;&lt;pre class="java" name="code"&gt;GroupingStore&amp;lt;Employee&amp;gt; employeeList = new GroupingStore&amp;lt;Employee&amp;gt;();  &lt;br /&gt;employeeList.add(TestData.getEmployees());  &lt;br /&gt;employeeList.groupBy("department");   &lt;/pre&gt;&lt;br /&gt;The &lt;b&gt;&lt;i&gt;groupBy &lt;/i&gt;&lt;/b&gt;method takes a property of your model by which you want to group your grid. In the example i have grouped the grid by 'department' property. You can change it to 'designation' property and see how it works.&lt;br /&gt;&lt;br /&gt;Now define a list of ColumnConfig and a ColumnModel by using this list&amp;nbsp;as before.&lt;br /&gt;&lt;pre class="java" name="code"&gt;List&amp;lt;Columnconfig&amp;gt; configs = new ArrayList&amp;lt;Columnconfig&amp;gt;();&lt;br /&gt;&lt;br /&gt;ColumnConfig column = new ColumnConfig();  &lt;br /&gt;column.setId("name");  &lt;br /&gt;column.setHeader("Employee Name");  &lt;br /&gt;column.setWidth(200);  &lt;br /&gt;configs.add(column);&lt;br /&gt;&lt;br /&gt;column = new ColumnConfig("department", "Department", 150);  &lt;br /&gt;column.setAlignment(HorizontalAlignment.LEFT);  &lt;br /&gt;configs.add(column);&lt;br /&gt;&lt;br /&gt;column = new ColumnConfig("designation", "Designation", 150);   &lt;br /&gt;column.setAlignment(HorizontalAlignment.LEFT);  &lt;br /&gt;configs.add(column);&lt;br /&gt;&lt;br /&gt;column = new ColumnConfig("salary", "Slary", 100);  &lt;br /&gt;column.setAlignment(HorizontalAlignment.RIGHT);  &lt;br /&gt;final NumberFormat number = NumberFormat.getFormat("0.00");  &lt;br /&gt;GridCellRenderer&amp;lt;Employee&amp;gt; checkSalary = new GridCellRenderer&amp;lt;Employee&amp;gt;() {  &lt;br /&gt;public String render(Employee model, String property, ColumnData config, int rowIndex,  &lt;br /&gt;int colIndex, ListStore&amp;lt;Employee&amp;gt; employeeList, Grid&amp;lt;Employee&amp;gt; grid) {  &lt;br /&gt;double val = (Double) model.get(property);  &lt;br /&gt;String style = val &amp;lt; 70000 ? "red" : "green";  &lt;br /&gt;return "&amp;lt;span style='color:" + style + "'&amp;gt;" + number.format(val) + "&amp;lt;/span&amp;gt;"; &lt;br /&gt;}  &lt;br /&gt;};  &lt;br /&gt;column.setRenderer(checkSalary);  &lt;br /&gt;configs.add(column);&lt;br /&gt;&lt;br /&gt;column = new ColumnConfig("joiningdate", "Joining Date", 100);  &lt;br /&gt;column.setAlignment(HorizontalAlignment.RIGHT);  &lt;br /&gt;column.setDateTimeFormat(DateTimeFormat.getShortDateFormat());  &lt;br /&gt;configs.add(column);&lt;br /&gt;&lt;br /&gt;final ColumnModel cm = new ColumnModel(configs); &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Create an instance of GroupView which groups the data based on the GroupStore. Then set it as the view of the Grid.&lt;br /&gt;&lt;br /&gt;&lt;pre class="java" name="code"&gt;GroupingView view = new GroupingView();  &lt;br /&gt;view.setForceFit(true);  &lt;br /&gt;view.setGroupRenderer(new GridGroupRenderer() {  &lt;br /&gt;public String render(GroupColumnData data) {  &lt;br /&gt;String f = cm.getColumnById(data.field).getHeader();  &lt;br /&gt;String l = data.models.size() == 1 ? "Item" : "Items";  &lt;br /&gt;return f + ": " + data.group + " (" + data.models.size() + " " + l + ")";  &lt;br /&gt;}  &lt;br /&gt;});  &lt;br /&gt;&lt;br /&gt;Grid&amp;lt;Employee&amp;gt; grid = new Grid&amp;lt;Employee&amp;gt;(employeeList, cm);  &lt;br /&gt;grid.setView(view);  &lt;br /&gt;grid.setBorders(true);&lt;/pre&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-weight: normal;"&gt;Here&amp;nbsp;&lt;/span&gt;&lt;em&gt;setForceFit &lt;/em&gt;&lt;span style="font-weight: normal;"&gt;is&amp;nbsp;&lt;/span&gt;&lt;/strong&gt;set true to auto expand the columns to fit the grid width and&amp;nbsp;&lt;b&gt;&lt;i&gt;setGroupRenderer &lt;/i&gt;&lt;span style="font-weight: normal;"&gt;is used to create a heading for the groups.&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Finally add the grid to the content panel.&lt;br /&gt;&lt;br /&gt;&lt;pre class="java" name="code"&gt;ContentPanel cp = new ContentPanel();  &lt;br /&gt;cp.setBodyBorder(false);  &lt;br /&gt;cp.setHeading("Employee List");  &lt;br /&gt;cp.setButtonAlign(HorizontalAlignment.CENTER);  &lt;br /&gt;cp.setLayout(new FitLayout());  &lt;br /&gt;cp.setSize(700, 420); &lt;br /&gt;cp.add(grid);  &lt;br /&gt;RootPanel.get().add(cp);&lt;/pre&gt;&lt;div&gt;&lt;script type="text/javascript"&gt;&lt;!--google_ad_client = "pub-3583615898080871";/* 468x60, created 10/2/09 BELOW POST */google_ad_slot = "5516300168";google_ad_width = 468;google_ad_height = 60;//--&gt;&lt;/script&gt;&lt;br /&gt;&lt;script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"&gt;&lt;/script&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Run the application and see how readable the grid is now.&amp;nbsp;To view the live demo of this tutorial&amp;nbsp;&lt;a href="http://gxtexamplegallery.appspot.com/"&gt;Click here&lt;/a&gt;.&lt;br /&gt;&lt;a href="http://lh5.ggpht.com/_MwOzNujvBcI/SpTD_KOA8uI/AAAAAAAAAMg/5GVFQ4HC5oA/s1600-h/gxtGridGrouping%5B10%5D.jpg"&gt;&lt;img alt="gxtGridGrouping" border="0" height="499" src="http://lh4.ggpht.com/_MwOzNujvBcI/SpTEAVa2onI/AAAAAAAAAMk/7EYlJqHeIOU/gxtGridGrouping_thumb%5B8%5D.jpg?imgmax=800" style="border-bottom: 0px; border-left: 0px; border-right: 0px; border-top: 0px; display: inline;" title="gxtGridGrouping" width="623" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-993616234379484251?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/993616234379484251/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=993616234379484251' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/993616234379484251'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/993616234379484251'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2009/08/working-with-gxtext-gwt-grid-add.html' title='Working with GXT(Ext GWT) Grid : Add Grouping Funtionality'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh4.ggpht.com/_MwOzNujvBcI/SpTEAVa2onI/AAAAAAAAAMk/7EYlJqHeIOU/s72-c/gxtGridGrouping_thumb%5B8%5D.jpg?imgmax=800' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-1904630576125594136</id><published>2009-08-24T22:48:00.000-07:00</published><updated>2010-02-19T01:34:26.552-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Local Paging'/><category scheme='http://www.blogger.com/atom/ns#' term='GWT'/><category scheme='http://www.blogger.com/atom/ns#' term='Ext GWT'/><category scheme='http://www.blogger.com/atom/ns#' term='GXT(Ext GWT) Grid example'/><category scheme='http://www.blogger.com/atom/ns#' term='gxt'/><title type='text'>Working with GXT(Ext GWT) Grid : Add Local Pagination Functionality</title><content type='html'>&lt;div style="text-align: justify;"&gt;In &lt;a href="http://zawoad.blogspot.com/2009/08/how-to-create-simple-grid-using-gxtext.html"&gt;my previous blog&lt;/a&gt;&amp;nbsp;i have described how to create a simple Grid of GXT. &amp;nbsp;I have a plan to write a series of blog about other useful functionalities which can be added to the Grid. Here i write down the way of adding local pagination functionality with the Grid.&lt;/div&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;a href="http://zawoad.blogspot.com/2009/06/getting-started-with-gwt-create-your.html" target="_blank"&gt;Create a new project&lt;/a&gt;&amp;nbsp;named&amp;nbsp;&lt;b&gt;GxtPagingExample&amp;nbsp;&lt;/b&gt;and&amp;nbsp;&lt;a href="http://zawoad.blogspot.com/2009/06/how-to-use-ext-gwt-in-eclipse-34-to.html" target="_blank"&gt;add GXT library&lt;/a&gt;&amp;nbsp;in the project. To create a grid at first you need a base model class and have to generate data for that model. In this tutorial i have used the same Employee model and TestData class for generating data which i used in&amp;nbsp;&lt;a href="http://zawoad.blogspot.com/2009/08/how-to-create-simple-grid-using-gxtext.html"&gt;my previous blog&lt;/a&gt;.&amp;nbsp;You will find the code of these classes&amp;nbsp;&lt;a href="http://zawoad.blogspot.com/2009/08/how-to-create-simple-grid-using-gxtext.html"&gt;there&lt;/a&gt;.&lt;/div&gt;&lt;br /&gt;Now go to the&amp;nbsp;&lt;span id="keyword1"&gt;onModuleLoad&lt;/span&gt;&amp;nbsp;method of&amp;nbsp;GxtPagingExample class. Remove all the auto generated code of this method. First create an instance of &lt;b&gt;&lt;i&gt;PagingModelMemoryProxy &lt;/i&gt;&lt;/b&gt;which is a specialized &lt;b&gt;&lt;i&gt;DataProxy &lt;/i&gt;&lt;/b&gt;that supports paging when the entire data set is in the memory.&lt;br /&gt;&lt;br /&gt;&lt;pre class="java" name="code"&gt;PagingModelMemoryProxy proxy = new PagingModelMemoryProxy(TestData.getEmployees());&lt;br /&gt;   PagingLoader loader = new BasePagingLoader(proxy);&lt;br /&gt;   loader.setRemoteSort(true);&lt;br /&gt;   ListStore&amp;lt;Employee&amp;gt; employeeList = new ListStore&amp;lt;Employee&amp;gt;(loader);  &lt;br /&gt;&lt;/pre&gt;&lt;div style="text-align: justify;"&gt;&lt;b&gt;&lt;i&gt;BasePagingLoader &lt;/i&gt;&lt;/b&gt;is an implementation of the &lt;b&gt;&lt;i&gt;PagingLoader &lt;/i&gt;&lt;/b&gt;interface which loads data using the proxy.If remote sort is enable then it will allow you to sort between the whole data set otherwise the sorting will be done only between the viewable data set. Then create a ListStore of Employee type.&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;script type="text/javascript"&gt;&lt;!--google_ad_client = "pub-3583615898080871";/* 468x60, created 10/2/09 BELOW POST */google_ad_slot = "5516300168";google_ad_width = 468;google_ad_height = 60;//--&gt;&lt;/script&gt;&lt;br /&gt;&lt;script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"&gt;&lt;/script&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Now create a PagingToolBar widget then bind it with the loader. It takes the page size in the constructor.&lt;br /&gt;&lt;pre class="java" name="code"&gt;final PagingToolBar toolBar = new PagingToolBar(5);&lt;br /&gt;   toolBar.bind(loader);&lt;br /&gt;   loader.load(0, 5);&lt;br /&gt;&lt;/pre&gt;The arguments of the load method of PagingLoader are the begin index and page size.&lt;br /&gt;&lt;br /&gt;Create a list of ColumnConfig and define each column. Then create a grid and add the grid and the PagingToolBar in a panel.&lt;br /&gt;&lt;br /&gt;&lt;pre class="java" name="code"&gt;List&amp;lt;Columnconfig&amp;gt; configs = new ArrayList&amp;lt;Columnconfig&amp;gt;();&lt;br /&gt;&lt;br /&gt;ColumnConfig column = new ColumnConfig();  &lt;br /&gt;column.setId("name");  &lt;br /&gt;column.setHeader("Employee Name");  &lt;br /&gt;column.setWidth(200);  &lt;br /&gt;configs.add(column);&lt;br /&gt;&lt;br /&gt;column = new ColumnConfig("department", "Department", 150);  &lt;br /&gt;column.setAlignment(HorizontalAlignment.LEFT);  &lt;br /&gt;configs.add(column);&lt;br /&gt;&lt;br /&gt;column = new ColumnConfig("designation", "Designation", 150);  &lt;br /&gt;column.setAlignment(HorizontalAlignment.LEFT);  &lt;br /&gt;configs.add(column);&lt;br /&gt;&lt;br /&gt;column = new ColumnConfig("salary", "Slary", 100);  &lt;br /&gt;column.setAlignment(HorizontalAlignment.RIGHT);  &lt;br /&gt;final NumberFormat number = NumberFormat.getFormat("0.00");  &lt;br /&gt;GridCellRenderer&amp;lt;Employee&amp;gt; checkSalary = new GridCellRenderer&amp;lt;Employee&amp;gt;() {  &lt;br /&gt;public String render(Employee model, String property, ColumnData config, int rowIndex,  &lt;br /&gt;int colIndex, ListStore&amp;lt;Employee&amp;gt; employeeList, Grid&amp;lt;Employee&amp;gt; grid) {  &lt;br /&gt;double val = (Double) model.get(property);  &lt;br /&gt;String style = val &amp;lt; 70000 ? "red" : "green";  &lt;br /&gt;return "&amp;lt;span style='color:" + style + "'&amp;gt;" + number.format(val) + "&amp;lt;/span&amp;gt;"; &lt;br /&gt;}  &lt;br /&gt;};  &lt;br /&gt;column.setRenderer(checkSalary);  &lt;br /&gt;configs.add(column);&lt;br /&gt;&lt;br /&gt;column = new ColumnConfig("joiningdate", "Joining Date", 100);  &lt;br /&gt;column.setAlignment(HorizontalAlignment.RIGHT);  &lt;br /&gt;column.setDateTimeFormat(DateTimeFormat.getShortDateFormat());  &lt;br /&gt;configs.add(column);&lt;br /&gt;&lt;br /&gt;ColumnModel cm = new ColumnModel(configs);&lt;br /&gt;Grid&amp;lt;Employee&amp;gt; grid = new Grid&amp;lt;Employee&amp;gt;(employeeList, cm); &lt;br /&gt;grid.setStyleAttribute("borderTop", "none"); &lt;br /&gt;grid.setAutoExpandColumn("name"); &lt;br /&gt;grid.setBorders(true); &lt;br /&gt;grid.setStripeRows(true);&lt;br /&gt;&lt;br /&gt;ContentPanel cp = new ContentPanel();  &lt;br /&gt;cp.setBodyBorder(false);  &lt;br /&gt;cp.setHeading("Employee List");  &lt;br /&gt;cp.setButtonAlign(HorizontalAlignment.CENTER);  &lt;br /&gt;cp.setLayout(new FitLayout());  &lt;br /&gt;cp.setSize(700, 300); &lt;br /&gt;cp.add(grid);  &lt;br /&gt;cp.setBottomComponent(toolBar);&lt;br /&gt;RootPanel.get().add(cp);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Explanation of the above code is written &lt;a href="http://zawoad.blogspot.com/2009/08/how-to-create-simple-grid-using-gxtext.html"&gt;here&lt;/a&gt;.&lt;br /&gt;That's all. Run the application and test the pagination functionality.&amp;nbsp;To view the live demo of this tutorial&amp;nbsp;&lt;a href="http://gxtexamplegallery.appspot.com/"&gt;Click here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_MwOzNujvBcI/SpN5mlCr_1I/AAAAAAAAAMY/CT0dLhwmuLA/s1600-h/localPaging.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/_MwOzNujvBcI/SpN5mlCr_1I/AAAAAAAAAMY/CT0dLhwmuLA/s400/localPaging.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-1904630576125594136?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/1904630576125594136/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=1904630576125594136' title='20 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/1904630576125594136'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/1904630576125594136'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2009/08/working-with-gxtext-gwt-grid-add-local.html' title='Working with GXT(Ext GWT) Grid : Add Local Pagination Functionality'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_MwOzNujvBcI/SpN5mlCr_1I/AAAAAAAAAMY/CT0dLhwmuLA/s72-c/localPaging.JPG' height='72' width='72'/><thr:total>20</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-4158957364734390242</id><published>2009-08-21T22:41:00.000-07:00</published><updated>2009-11-03T02:49:00.021-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ext GWT'/><category scheme='http://www.blogger.com/atom/ns#' term='GXT(Ext GWT) Grid example'/><category scheme='http://www.blogger.com/atom/ns#' term='gxt'/><category scheme='http://www.blogger.com/atom/ns#' term='Grid'/><title type='text'>How to create a simple Grid using GXT(Ext GWT)</title><content type='html'>&lt;div align="justify"&gt;GXT provides us with many powerful UI tools. One of this is the Grid. You can select which column you want to see or which you want to discard from the Grid at run time. Can sort the Grid by any column in both ascending and descending order. More over with the GridCellRenderer you can customized the look and feel of a cell. This tutorial describes every steps of creating a simple Grid using GXT in detail. &lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;First &lt;a href="http://zawoad.blogspot.com/2009/06/getting-started-with-gwt-create-your.html" target="_blank"&gt;create a new project&lt;/a&gt; named &lt;b&gt;GxtGridExample &lt;/b&gt;and &lt;a href="http://zawoad.blogspot.com/2009/06/how-to-use-ext-gwt-in-eclipse-34-to.html" target="_blank"&gt;add GXT library&lt;/a&gt; in the project.&amp;nbsp; To show a list of data in the Grid you have to prepare the data first. In this tutorial i am going to show you a list of employee. So i need a &lt;b&gt;&lt;i&gt;Employee&lt;/i&gt;&lt;/b&gt; class which extends the BaseModel class of the GXT. Here is the code for the Employee class.&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;/div&gt;&lt;pre class="java" name="code"&gt;package com.ratul.GxtGridExample.client.model;&lt;br /&gt;import java.util.Date;&lt;br /&gt;import com.extjs.gxt.ui.client.data.BaseModel;&lt;br /&gt;&lt;br /&gt;public class Employee extends BaseModel {&lt;br /&gt;private static final long serialVersionUID = 1L;&lt;br /&gt;&lt;br /&gt;public Employee() {&lt;br /&gt;}&lt;br /&gt;public Employee(String name, String department, String designation,double salary, Date joiningdate) {&lt;br /&gt;set("name", name);&lt;br /&gt;set("department", department);&lt;br /&gt;set("designation", designation);&lt;br /&gt;set("salary", salary);&lt;br /&gt;set("joiningdate", joiningdate);&lt;br /&gt;}&lt;br /&gt;public Date getJoiningdate() {&lt;br /&gt;return (Date) get("joiningdate");&lt;br /&gt;}&lt;br /&gt;public String getName() {&lt;br /&gt;return (String) get("name");&lt;br /&gt;}&lt;br /&gt;public String getDepartment() {&lt;br /&gt;return (String) get("department");&lt;br /&gt;}&lt;br /&gt;public String getDesignation() {&lt;br /&gt;return (String) get("designation");&lt;br /&gt;}&lt;br /&gt;public double getSalary() {&lt;br /&gt;Double salary = (Double) get("salary");&lt;br /&gt;return salary.doubleValue();&lt;br /&gt;}&lt;br /&gt;public String toString() {&lt;br /&gt;return getName();&lt;br /&gt;}&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;div align="justify"&gt;Employee has 5 properties and to set the value of a property the &lt;b&gt;&lt;i&gt;set&lt;/i&gt;&lt;/b&gt; method is used. First parameter of the method is the property name and second is the value of that property. The class has also the getter method for each property. &lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;Now populate a list of Employee in the &lt;b&gt;&lt;i&gt;TestData&lt;/i&gt;&lt;/b&gt; class. &lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;/div&gt;&lt;pre class="java" name="code"&gt;package com.ratul.GxtGridExample.client;&lt;br /&gt;&lt;br /&gt;import java.util.ArrayList;&lt;br /&gt;import java.util.List;&lt;br /&gt;import com.google.gwt.i18n.client.DateTimeFormat;&lt;br /&gt;import com.ratul.GxtGridExample.client.model.Employee;&lt;br /&gt;&lt;br /&gt;public class TestData {&lt;br /&gt;&lt;br /&gt;public static List&amp;lt;Employee&amp;gt; getEmployees()&lt;br /&gt;{&lt;br /&gt;  List&amp;lt;Employee&amp;gt; employees = new ArrayList&amp;lt;Employee&amp;gt;();&lt;br /&gt;DateTimeFormat f = DateTimeFormat.getFormat("yyyy-mm-dd");&lt;br /&gt;  employees.add(new Employee("Hollie Voss","General Administration","Executive Dir  ector",150000,f.parse("2006-05-01")));&lt;br /&gt;  employees.add(new Employee("Emerson Milton","Information Technology","CTO",12000  0,f.parse("2007-03-01")));&lt;br /&gt;  employees.add(new Employee("Christina Blake","Information Technology","Project M  anager",90000,f.parse("2008-08-01")));&lt;br /&gt;  employees.add(new Employee("Heriberto Rush","Information Technology","Senior S/W  Engineer",70000,f.parse("2009-02-07")));&lt;br /&gt;  employees.add(new Employee("Candice Carson","Information Technology","S/W Engine  er",60000,f.parse("2007-11-01")));&lt;br /&gt;  employees.add(new Employee("Chad Andrews","Information Technology","Senior S/W E  ngineer",70000,f.parse("2008-02-01")));&lt;br /&gt;  employees.add(new Employee("Dirk Newman","Information Technology","S/W Engineer"  ,62000,f.parse("2009-03-01")));&lt;br /&gt;  employees.add(new Employee("Bell Snedden","Information Technology","S/W Engineer  ",73000,f.parse("2007-07-07")));&lt;br /&gt;  employees.add(new Employee("Benito Meeks","Marketing","General Manager",105000,f  .parse("2008-02-01")));&lt;br /&gt;  employees.add(new Employee("Gail Horton","Marketing","Executive",55000,f.parse("  2009-05-01")));&lt;br /&gt;  employees.add(new Employee("Claudio Engle","Marketing","Executive",58000,f.parse  ("2008-09-03")));&lt;br /&gt;  employees.add(new Employee("Buster misjenou","Accounts","Executive",52000,f.pars  e("2008-02-07")));&lt;br /&gt;&lt;br /&gt;return employees;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;You data is prepared now to place in a GXT Grid.&lt;br /&gt;&lt;div align="justify"&gt;Go to the &lt;span id="keyword1"&gt;onModuleLoad&lt;/span&gt; method of GxtGridExample class. Remove all the auto generated code of this method. &lt;br /&gt;&lt;/div&gt;First create a list of ColumnConfig and configure each column.&lt;br /&gt;&lt;br /&gt;&lt;pre class="java" name="code"&gt;List&amp;lt;Columnconfig&amp;gt; configs = new ArrayList&amp;lt;Columnconfig&amp;gt;();&lt;br /&gt;&lt;br /&gt;ColumnConfig column = new ColumnConfig();  &lt;br /&gt;column.setId("name");  &lt;br /&gt;column.setHeader("Employee Name");  &lt;br /&gt;column.setWidth(200);  &lt;br /&gt;configs.add(column);&lt;br /&gt;&lt;br /&gt;column = new ColumnConfig("department", "Department", 150);  &lt;br /&gt;column.setAlignment(HorizontalAlignment.LEFT);  &lt;br /&gt;configs.add(column);&lt;br /&gt;&lt;br /&gt;column = new ColumnConfig("designation", "Designation", 150);  &lt;br /&gt;column.setAlignment(HorizontalAlignment.LEFT);  &lt;br /&gt;configs.add(column);&lt;br /&gt;&lt;br /&gt;column = new ColumnConfig("salary", "Slary", 100);  &lt;br /&gt;column.setAlignment(HorizontalAlignment.RIGHT);  &lt;br /&gt;final NumberFormat number = NumberFormat.getFormat("0.00");  &lt;br /&gt;GridCellRenderer&amp;lt;Employee&amp;gt; checkSalary = new GridCellRenderer&amp;lt;Employee&amp;gt;() {  &lt;br /&gt;public String render(Employee model, String property, ColumnData config, int rowIndex,  &lt;br /&gt;int colIndex, ListStore&amp;lt;Employee&amp;gt; employeeList, Grid&amp;lt;Employee&amp;gt; grid) {  &lt;br /&gt;double val = (Double) model.get(property);  &lt;br /&gt;String style = val &amp;lt; 70000 ? "red" : "green";  &lt;br /&gt;return "&amp;lt;span style='color:" + style + "'&amp;gt;" + number.format(val) + "&amp;lt;/span&amp;gt;";   &lt;br /&gt;}  &lt;br /&gt;};  &lt;br /&gt;column.setRenderer(checkSalary);  &lt;br /&gt;configs.add(column);&lt;br /&gt;&lt;br /&gt;column = new ColumnConfig("joiningdate", "Joining Date", 100);  &lt;br /&gt;column.setAlignment(HorizontalAlignment.RIGHT);  &lt;br /&gt;column.setDateTimeFormat(DateTimeFormat.getShortDateFormat());  &lt;br /&gt;configs.add(column);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;div align="justify"&gt;The &lt;i&gt;&lt;b&gt;setId&lt;/b&gt;&lt;/i&gt; method bind the column with a property of the model and the &lt;i&gt;&lt;b&gt;setHeader&lt;/b&gt;&lt;/i&gt; method set the column header. You can also set this property of the ColumnConfig by using the constructor.&amp;nbsp; For the salary column here i define a custom GridCellRenderer&amp;lt;Employee&amp;gt; and set it with the &lt;b&gt;&lt;i&gt;setRenderer&lt;/i&gt;&lt;/b&gt; method which set the color of the salary value either green or red by checking its value. The other methods are self explanatory.&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;Create a ListStore of Employee type and add the employee list created in the TestData class.&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="java" name="code"&gt;ListStore&amp;lt;Employee&amp;gt; employeeList = new ListStore&amp;lt;Employee&amp;gt;();  &lt;br /&gt;employeeList.add(TestData.getEmployees());&lt;/pre&gt;&lt;br /&gt;Now create a ColumnModel with the column configurations defined above and a Grid of Type Employee.&lt;br /&gt;&lt;br /&gt;&lt;pre class="java" name="code"&gt;ColumnModel cm = new ColumnModel(configs);&lt;br /&gt;Grid&amp;lt;Employee&amp;gt; grid = new Grid&amp;lt;Employee&amp;gt;(employeeList, cm); &lt;br /&gt;grid.setStyleAttribute("borderTop", "none"); &lt;br /&gt;grid.setAutoExpandColumn("name"); &lt;br /&gt;grid.setBorders(true); &lt;br /&gt;grid.setStripeRows(true);&lt;/pre&gt;&lt;br /&gt;&lt;div align="justify"&gt;The &lt;b&gt;&lt;i&gt;setAutoExpandColumn &lt;/i&gt;&lt;/b&gt;is used to defined which column will be expanded automatically when you hide a column. Other methods are self identifying. &lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;You are just one step away from running the code. Create a ContentPanel and add the Grid to the panel.&lt;br /&gt;&lt;/div&gt;&lt;div align="justify"&gt;&lt;/div&gt;&lt;pre class="java" name="code"&gt;ContentPanel cp = new ContentPanel();  &lt;br /&gt;cp.setBodyBorder(false);  &lt;br /&gt;cp.setHeading("Employee List");  &lt;br /&gt;cp.setButtonAlign(HorizontalAlignment.CENTER);  &lt;br /&gt;cp.setLayout(new FitLayout());  &lt;br /&gt;cp.setSize(700, 300); &lt;br /&gt;cp.add(grid);  &lt;br /&gt;RootPanel.get().add(cp);&lt;/pre&gt;&lt;div&gt;&lt;script type="text/javascript"&gt;&lt;!--google_ad_client = "pub-3583615898080871";/* 468x60, created 10/2/09 BELOW POST */google_ad_slot = "5516300168";google_ad_width = 468;google_ad_height = 60;//--&gt;&lt;/script&gt;&lt;br /&gt;&lt;script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"&gt;&lt;/script&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Run the application and check the magic of GXT Grid.&amp;nbsp;To view the live demo of this tutorial&amp;nbsp;&lt;a href="http://gxtexamplegallery.appspot.com/"&gt;Click here&lt;/a&gt;.&lt;br /&gt;&lt;a href="http://lh6.ggpht.com/_MwOzNujvBcI/SpDXKNwZqZI/AAAAAAAAAMM/IePGmClWAZw/s1600-h/employeeList%5B13%5D.jpg"&gt;&lt;img alt="employeeList" border="0" height="377" src="http://lh4.ggpht.com/_MwOzNujvBcI/SpDXL7i4SGI/AAAAAAAAAMQ/HDMYXPbW9wo/employeeList_thumb%5B11%5D.jpg?imgmax=800" style="border-width: 0px; display: inline;" title="employeeList" width="579" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-4158957364734390242?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/4158957364734390242/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=4158957364734390242' title='25 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/4158957364734390242'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/4158957364734390242'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2009/08/how-to-create-simple-grid-using-gxtext.html' title='How to create a simple Grid using GXT(Ext GWT)'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh4.ggpht.com/_MwOzNujvBcI/SpDXL7i4SGI/AAAAAAAAAMQ/HDMYXPbW9wo/s72-c/employeeList_thumb%5B11%5D.jpg?imgmax=800' height='72' width='72'/><thr:total>25</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-6899790927374321345</id><published>2009-08-21T09:39:00.001-07:00</published><updated>2009-08-21T09:45:22.802-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='GWT'/><category scheme='http://www.blogger.com/atom/ns#' term='Google App Engine'/><category scheme='http://www.blogger.com/atom/ns#' term='Ext GWT'/><category scheme='http://www.blogger.com/atom/ns#' term='gxt'/><title type='text'>Keep yourself updated with the latest GWT technologies (gwt , app engine and gxt)</title><content type='html'>&lt;p&gt;It’s been long since i have worked with GWT. I have been very busy with my scheduled tasks and can not afford to spend time on investing the features of this outstanding web technology.&amp;#160; Today i have sit with it and found that everything is required to be updated. The SDK for GWT, Google App Engine and the Ext GWT Library (The world is running fast?huh). I have updated all these and&amp;#160; here i write down the procedure for eclipse 3.4.&lt;/p&gt;  &lt;p&gt;Download GWT version 1.7 from &lt;a href="http://code.google.com/webtoolkit/download.html"&gt;here&lt;/a&gt; and Google App Engine SDK 1.2.2 from &lt;a href="http://code.google.com/appengine/downloads.html"&gt;here.&lt;/a&gt; Unzip the folders then open the &lt;span id="keyword1"&gt;Window-&amp;gt;Preference&lt;/span&gt; window of eclipse.&lt;/p&gt;  &lt;p&gt;Expand the Google menu from the left tree menu.&amp;#160; Select the Web Toolkit menu and it will show you the previous version of GWT. Click on the Add Button and select the unzipped folder as the installation directory.&amp;#160; Now check the latest SDK so that it will be the default SDK for the newly created projects.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh6.ggpht.com/_MwOzNujvBcI/So7Olaqu9GI/AAAAAAAAAME/JIJyDYzz1J4/s1600-h/gwtupdate1%5B25%5D.jpg"&gt;&lt;img title="gwtupdate1" style="border-right: 0px; border-top: 0px; display: block; float: none; margin-left: auto; border-left: 0px; margin-right: auto; border-bottom: 0px" height="488" alt="gwtupdate1" src="http://lh4.ggpht.com/_MwOzNujvBcI/So7OnmjruPI/AAAAAAAAAMI/InJt-LZddQY/gwtupdate1_thumb%5B21%5D.jpg?imgmax=800" width="520" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Now select the App Engine menu and follow the steps stated above to add the latest version of the SDK.&lt;/p&gt;  &lt;p&gt;You are now ready to use the latest version of GWT and Google App Engine SDK.&lt;/p&gt;  &lt;p&gt;To use the latest version of Ext GWT library download this from &lt;a href="http://extjs.com/products/gxt/download.php"&gt;here&lt;/a&gt; and follow &lt;a href="http://zawoad.blogspot.com/2009/06/how-to-use-ext-gwt-in-eclipse-34-to.html"&gt;my previous blog&lt;/a&gt; about how to use it in your GWT project.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-6899790927374321345?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/6899790927374321345/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=6899790927374321345' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/6899790927374321345'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/6899790927374321345'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2009/08/keep-yourself-updated-with-latest-gwt.html' title='Keep yourself updated with the latest GWT technologies (gwt , app engine and gxt)'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh4.ggpht.com/_MwOzNujvBcI/So7OnmjruPI/AAAAAAAAAMI/InJt-LZddQY/s72-c/gwtupdate1_thumb%5B21%5D.jpg?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-8471268829835696156</id><published>2009-06-12T17:14:00.000-07:00</published><updated>2009-10-02T03:59:09.618-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ext GWT'/><category scheme='http://www.blogger.com/atom/ns#' term='set up GXT'/><category scheme='http://www.blogger.com/atom/ns#' term='set up Ext GWT'/><category scheme='http://www.blogger.com/atom/ns#' term='gxt'/><title type='text'>How to use Ext GWT(GXT) in Eclipse 3.4 to create a rich internet application</title><content type='html'>Ext GWT is a Java library for building rich internet applications with the Google Web Toolkit (GWT). If you have started working with GWT you will find the Ext GWT library very helpful for its high performance and customizable UI widgets. Here I describe you how to use this library in your GWT project.&lt;br /&gt;&lt;br /&gt;First of all download &lt;a href="http://extjs.com/products/gxt/download.php" target="_blank"&gt;Ext GWT 1.2.4 SDK&lt;/a&gt;, the latest stable version of this library and extract it.&lt;br /&gt;&lt;br /&gt;Now Create a GWT project by following the steps I have described in my &lt;a href="http://zawoad.blogspot.com/2009/06/getting-started-with-gwt-create-your.html" target="_blank"&gt;previous blog&lt;/a&gt;. Follow the steps to add &lt;span id="keyword1"&gt;gxt.jar&lt;/span&gt; to the project.&lt;br /&gt;&lt;br /&gt;-&gt;Right click on project and select the properties menu..&lt;br /&gt;-&gt;Select Java Build Path.&lt;br /&gt;-&gt;Select Libraries tab.&lt;br /&gt;-&gt;Click on Add External JARS and select gxt.jar. (You will find this jar file inside the folder where you have extracted the library previously. )&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_MwOzNujvBcI/SjL8CS9-III/AAAAAAAAAKY/VkF2qTFgeI8/s1600-h/gwt-ext.png"&gt;&lt;img style="cursor: pointer; width: 400px; height: 302px;" src="http://4.bp.blogspot.com/_MwOzNujvBcI/SjL8CS9-III/AAAAAAAAAKY/VkF2qTFgeI8/s400/gwt-ext.png" alt="" id="BLOGGER_PHOTO_ID_5346612824023900290" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Now change the &lt;span id="keyword1"&gt;your_project_name.gwt.xml&lt;/span&gt; file. Add the following line in this file.&lt;br /&gt;&lt;pre name="code" class="xml"&gt;&amp;lt;inherits name='com.extjs.gxt.ui.GXT'/&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;div&gt;&lt;script type="text/javascript"&gt;&lt;!--google_ad_client = "pub-3583615898080871";/* 468x60, created 10/2/09 BELOW POST */google_ad_slot = "5516300168";google_ad_width = 468;google_ad_height = 60;//--&gt;&lt;/script&gt;&lt;br /&gt;&lt;script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;&lt;/script&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Here goes the tricky part. You will find a folder named &lt;span id="keyword1"&gt;resources&lt;/span&gt; in the extracted folder. This contains the css and images used in this library. Copy the &lt;span id="keyword1"&gt;css&lt;/span&gt; and &lt;span id="keyword1"&gt;images&lt;/span&gt; folder in the &lt;span id="keyword1"&gt;war&lt;/span&gt; folder of your application. Now add the following stylesheet to your host page.&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="html"&gt;&amp;lt;link rel="stylesheet" type="text/css" href="css/ext-all.css" /&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;And remember Ext GWT requires no doctype or the following doctype (quirksmode).&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="html"&gt;&amp;lt!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;That's all. You are now ready to use the Ext GWT library to enhance your application.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-8471268829835696156?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/8471268829835696156/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=8471268829835696156' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/8471268829835696156'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/8471268829835696156'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2009/06/how-to-use-ext-gwt-in-eclipse-34-to.html' title='How to use Ext GWT(GXT) in Eclipse 3.4 to create a rich internet application'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_MwOzNujvBcI/SjL8CS9-III/AAAAAAAAAKY/VkF2qTFgeI8/s72-c/gwt-ext.png' height='72' width='72'/><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-1101924783199208304</id><published>2009-06-06T04:07:00.000-07:00</published><updated>2011-04-23T19:38:47.431-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='GWT'/><category scheme='http://www.blogger.com/atom/ns#' term='first gwt application'/><title type='text'>Getting started with GWT : Create your first GWT application in Eclipse 3.4</title><content type='html'>To my mind GWT is going to take the lead among the web application development tools. So this is the high time to start learning about GWT. Here I describe you how to create your first GWT application in Eclipse 3.4 (Ganymede).&lt;br /&gt;&lt;br /&gt;If you have not installed Google plugin and SDK for eclipse please go to &lt;a href="http://code.google.com/eclipse/docs/install-eclipse-3.4.html" target="_blank"&gt;this page&lt;/a&gt; and follow the instructions.&lt;br /&gt;&lt;br /&gt;&lt;span id="keyword2"&gt;Create your project&lt;/span&gt;&lt;br /&gt;Select File-&gt; New-&gt; Web Application project. Enter &lt;span id="keyword1"&gt;"FirstGwtApp"&lt;/span&gt; for your project name and &lt;span id="keyword1"&gt;"com.ratul.FirstGwtApp"&lt;/span&gt; for the package name.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_MwOzNujvBcI/SipSqACTsKI/AAAAAAAAAJg/ayeKMwPlj48/s1600-h/gwt1.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 355px; height: 400px;" src="http://4.bp.blogspot.com/_MwOzNujvBcI/SipSqACTsKI/AAAAAAAAAJg/ayeKMwPlj48/s400/gwt1.png" alt="" id="BLOGGER_PHOTO_ID_5344174789346177186" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="keyword2"&gt;Create GWT entry point&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now you have to create an Entry point class which is similar to the main method in Java.&lt;br /&gt;Right click on the "com.ratul.FirstGwtApp.client" and select New-&gt; Class. Enter &lt;span id="keyword1"&gt;"HelloWorld"&lt;/span&gt; as the name of the class.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_MwOzNujvBcI/SisyhdO_RMI/AAAAAAAAAKQ/DAFnQer1Ckk/s1600-h/gwt2.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 500px; height: 380px;" src="http://2.bp.blogspot.com/_MwOzNujvBcI/SisyhdO_RMI/AAAAAAAAAKQ/DAFnQer1Ckk/s400/gwt2.png" alt="" id="BLOGGER_PHOTO_ID_5344420933169792194" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;This class must implement the interface &lt;span id="keyword1"&gt;"com.google.gwt.core.client.EntryPoint"&lt;/span&gt;.&lt;br /&gt;So click on the Add button and write &lt;span id="keyword1"&gt;"entrypoint"&lt;/span&gt; in the choose interface text field.&lt;br /&gt;Select the matching item.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_MwOzNujvBcI/SipWY9hiSYI/AAAAAAAAAJw/1O4gKgXbk0o/s1600-h/gwt3.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 368px; height: 328px;" src="http://2.bp.blogspot.com/_MwOzNujvBcI/SipWY9hiSYI/AAAAAAAAAJw/1O4gKgXbk0o/s400/gwt3.png" alt="" id="BLOGGER_PHOTO_ID_5344178894660585858" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Here is the code of the HelloWorld class&lt;br /&gt;&lt;pre name="code" class="java"&gt;package com.ratul.FirstGwtApp.client;&lt;br /&gt;&lt;br /&gt;import com.google.gwt.core.client.EntryPoint;&lt;br /&gt;&lt;br /&gt;import com.google.gwt.event.dom.client.ClickEvent;&lt;br /&gt;import com.google.gwt.event.dom.client.ClickHandler;&lt;br /&gt;import com.google.gwt.user.client.Window;&lt;br /&gt;import com.google.gwt.user.client.ui.Button;&lt;br /&gt;import com.google.gwt.user.client.ui.Label;&lt;br /&gt;import com.google.gwt.user.client.ui.TextBox;&lt;br /&gt;import com.google.gwt.user.client.ui.RootPanel;&lt;br /&gt;&lt;br /&gt;public class HelloWorld implements EntryPoint {&lt;br /&gt;&lt;br /&gt;@Override&lt;br /&gt;public void onModuleLoad() {&lt;br /&gt;Label label = new Label("Enter your name:");&lt;br /&gt;final TextBox textBox = new TextBox();&lt;br /&gt;Button button = new Button("Click Here");&lt;br /&gt;button.addClickHandler(new ClickHandler() {&lt;br /&gt;@Override&lt;br /&gt;public void onClick(ClickEvent event) {&lt;br /&gt;Window.alert("Hello "+ textBox.getText());&lt;br /&gt;}&lt;br /&gt;});&lt;br /&gt;&lt;br /&gt;RootPanel.get().add(label);&lt;br /&gt;RootPanel.get().add(textBox);&lt;br /&gt;RootPanel.get().add(button);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now change the &lt;span id="keyword1"&gt;FirstGwtApp.gwt.xml&lt;/span&gt; in package &lt;span id="keyword1"&gt;com.ratul.FirstGwtApp&lt;/span&gt; to set the HelloWorld class as the entry point class of your application.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_MwOzNujvBcI/SisBPcBY1XI/AAAAAAAAAJ4/b33xeVSu6No/s1600-h/gwt4.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 400px; height: 181px;" src="http://3.bp.blogspot.com/_MwOzNujvBcI/SisBPcBY1XI/AAAAAAAAAJ4/b33xeVSu6No/s400/gwt4.png" alt="" id="BLOGGER_PHOTO_ID_5344366747536905586" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="keyword2"&gt;Create a Start HTML page&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In the war folder you will find a file, named &lt;span id="keyword1"&gt;FirstGwtApp.html&lt;/span&gt;. Between the body tag write the following code&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="html"&gt;&amp;lt;!-- OPTIONAL: include this if you want history support --&amp;gt;&lt;br /&gt;&amp;lt;iframe src="javascript:''" id="__gwt_historyFrame" tabindex="-1" style="border: 0pt none ; position: absolute; width: 0pt; height: 0pt;"&amp;gt;&amp;lt;/iframe&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;h1&amp;gt;Welcome to my first GWT Application&amp;lt;/h1&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="keyword2"&gt;Configure the web.xml&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Go to war-&gt; WEB-INF folder and there you will find a web.xml file. The Google Plug-in created this configuration file and placed a reference to a servlet.&lt;br /&gt;Set the FirstGwtApp.html as the welcome file of your application.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_MwOzNujvBcI/SisEBa_g-MI/AAAAAAAAAKA/nRUQLjKaqSg/s1600-h/gwt5.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 400px; height: 192px;" src="http://3.bp.blogspot.com/_MwOzNujvBcI/SisEBa_g-MI/AAAAAAAAAKA/nRUQLjKaqSg/s400/gwt5.png" alt="" id="BLOGGER_PHOTO_ID_5344369805277329602" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;You are only one step away from running your first GWT application.&lt;br /&gt;&lt;br /&gt;&lt;span id="keyword2"&gt;Run GWT application&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;To run your application right-click the project and select Run As -&gt; "Web application".&lt;br /&gt;&lt;br /&gt;The result will be like this.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_MwOzNujvBcI/SisExhUaOeI/AAAAAAAAAKI/UP_3RYetgAY/s1600-h/gwt7.png"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 400px; height: 301px;" src="http://2.bp.blogspot.com/_MwOzNujvBcI/SisExhUaOeI/AAAAAAAAAKI/UP_3RYetgAY/s400/gwt7.png" alt="" id="BLOGGER_PHOTO_ID_5344370631609301474" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Enter your name in the text field and click on the button. Your name will be appeared in the alert window :).&lt;br /&gt;&lt;div&gt;&lt;script type="text/javascript"&gt;&lt;!--google_ad_client = "pub-3583615898080871";/* 468x60, created 10/2/09 BELOW POST */google_ad_slot = "5516300168";google_ad_width = 468;google_ad_height = 60;//--&gt;&lt;/script&gt;&lt;br /&gt;&lt;script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;&lt;/script&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-1101924783199208304?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/1101924783199208304/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=1101924783199208304' title='18 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/1101924783199208304'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/1101924783199208304'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2009/06/getting-started-with-gwt-create-your.html' title='Getting started with GWT : Create your first GWT application in Eclipse 3.4'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_MwOzNujvBcI/SipSqACTsKI/AAAAAAAAAJg/ayeKMwPlj48/s72-c/gwt1.png' height='72' width='72'/><thr:total>18</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-3978558247253274061</id><published>2009-05-26T07:07:00.002-07:00</published><updated>2009-06-13T09:42:37.252-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Strategy pattern'/><category scheme='http://www.blogger.com/atom/ns#' term='Design pattern'/><title type='text'>Implementing Strategy pattern to support different fingerprint device login system</title><content type='html'>In our ERP project one of the features of Human resource module is managing daily attendance of the employee using biometric authentication.  Our client wants to use &lt;a href = "http://www.bioenabletech.com/fast_time_attendance_fingerprint_system.htm" target = "_blank"&gt;NAC 3000&lt;/a&gt; as a fingerprint verification device.&lt;br /&gt;&lt;br /&gt;The task is simple. The software of that device writes data in an access database and in a log file whenever an employee place finger on it. We just have to pull the data from the access file or the log file after certain interval. The problem is that as our ERP is generalized and can be customizable for any type of organization so we have to think about other devices that serve the same purpose.&lt;br /&gt;&lt;br /&gt;We analyze that all the devices vary in one point and that is the format of the log file or the database file.  That is only the file parsing algorithm varies from device to device. This motivates me to use Strategy pattern here as the Strategy pattern defines a family o algorithms, encapsulate each one and makes them interchangeable.&lt;br /&gt;&lt;br /&gt;&lt;span id="keyword2"&gt;Class diagram&lt;/span&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_MwOzNujvBcI/Shv4VIv9oxI/AAAAAAAAAJU/Hu3ygkVm_oA/s1600-h/class_diagram.jpg"&gt;&lt;img style="cursor: pointer; width: 400px; height: 400px;" src="http://3.bp.blogspot.com/_MwOzNujvBcI/Shv4VIv9oxI/AAAAAAAAAJU/Hu3ygkVm_oA/s400/class_diagram.jpg" alt="" id="BLOGGER_PHOTO_ID_5340134825187451666" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id="keyword2"&gt;Details&lt;/span&gt;&lt;br /&gt;&lt;span id="keyword1"&gt;LogInDevice&lt;/span&gt; is an abstract class which has an instance &lt;span id="keyword1"&gt;fileParser&lt;/span&gt; as the interface type not a concrete class implementation type.  The LogInDevice objects will set the variable polymorphically to reference the specific  file parser.&lt;br /&gt;&lt;br /&gt;The &lt;span id="keyword1"&gt;FileParser&lt;/span&gt; is an interface which has four mehthods. The NAC300Parser, NAC2500Parser implements this interface. When we need to integrate a new device we just have to create a new class that will implement this interface. The code of parsing the logfile will be written in the &lt;span id="keyword1"&gt;parseFile()&lt;/span&gt; method.&lt;br /&gt;&lt;br /&gt;Implementation of the &lt;span id="keyword1"&gt;doParsing()&lt;/span&gt; method of LogInDevice class&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;  &lt;br /&gt;   public void doParsing()&lt;br /&gt;   {&lt;br /&gt;       this.fileParser.parseFile();&lt;br /&gt;       userId = this.fileParser.getUserId();&lt;br /&gt;       purpose = this.fileParser.getPurpose();&lt;br /&gt;       time = this.fileParser.getTime();&lt;br /&gt;      //Code block for saving the data to database goes here.&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;In this part of the code we don't care about what kind of file parser it is.&lt;br /&gt; &lt;br /&gt;Are you thinking of setting the fileParser instance variable? Let’s take a look at the &lt;span id="keyword1"&gt;NAC3000&lt;/span&gt; class&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;   public class NAC3000 extends LogInDevice&lt;br /&gt;   {&lt;br /&gt;     public NAC3000()&lt;br /&gt;     {&lt;br /&gt;       this.fileParser = new NAC3000Parser();&lt;br /&gt;     }&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The NAC3000 uses the &lt;span id="keyword1"&gt;NAC3000Parser&lt;/span&gt; to handle its file parsing. So when the doParsing() is called the responsibility for the parsing is delegated to the &lt;span id="keyword1"&gt;NAC3000Parser object&lt;/span&gt; and we got our desired data.&lt;br /&gt;&lt;br /&gt;&lt;span id="keyword2"&gt;Change the FileParser dynamically&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;To change the parsing algorithm dynamically you just need a setter method in &lt;span id="keyword1"&gt;LogInDevice&lt;/span&gt; class&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;   public void setFileParser(FileParser fileParser)&lt;br /&gt;   {&lt;br /&gt;       this.fileParser = fileParser;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;We can call this method anytime we want  to change the file parsing algorithm on the fly.&lt;br /&gt;&lt;br /&gt;With this design we can integrate a new Fingerprint or any other authentication device very easily in our system and obviously without modifying the existing code.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-3978558247253274061?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/3978558247253274061/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=3978558247253274061' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/3978558247253274061'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/3978558247253274061'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2009/05/implementing-strategy-pattern-to.html' title='Implementing Strategy pattern to support different fingerprint device login system'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_MwOzNujvBcI/Shv4VIv9oxI/AAAAAAAAAJU/Hu3ygkVm_oA/s72-c/class_diagram.jpg' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-1384890661974796760</id><published>2009-05-09T17:25:00.000-07:00</published><updated>2009-06-13T17:44:32.254-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='invoke method by name'/><category scheme='http://www.blogger.com/atom/ns#' term='call method dynamically'/><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='Reflection'/><title type='text'>How to call a method dynamically using Java Reflection</title><content type='html'>In my &lt;a href = "http://zawoad.blogspot.com/2009/05/how-to-create-instance-of-class-at.html"&gt;previous post&lt;/a&gt; i have shown you how to create an instance dynamically using java reflection. Here i will show you how to call a method dynamically using reflection.&lt;br /&gt;&lt;br /&gt;Let us start with a simple example. Assume that the method name is&lt;b&gt; refreshForm &lt;/b&gt; and it has no argument. You can get the method using &lt;span id="keyword1"&gt; class.getMethod(methodName)&lt;/span&gt; method and then call the method using &lt;span id="keyword1"&gt; method.invoke(instance of the class)&lt;/span&gt; method.&lt;br /&gt; &lt;br /&gt;&lt;pre name="code" class="java"&gt; &lt;br /&gt;String className = "com.commlink.cbs.appclient.gl.ChartsOfAccount"&lt;br /&gt;String methodName = "refreshForm";&lt;br /&gt;&lt;br /&gt;//get the Class&lt;br /&gt;Class class = Class.forName(className);&lt;br /&gt;&lt;br /&gt;// get the instance&lt;br /&gt;Object obj = class.newInstance();&lt;br /&gt;&lt;br /&gt;// get the method&lt;br /&gt;Method method = class.getMethod(methodName );&lt;br /&gt;&lt;br /&gt;//call the method&lt;br /&gt;method.invoke(obj);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Things will be little complex if the method has some arguments. Suppose the refreshForm method takes two String values. To call this method using reflection first create an array of Class and then an array of Object. Use the class array in &lt;span id="keyword1"&gt;getMethod&lt;/span&gt; method and the Object array in &lt;span id="keyword1"&gt;invoke&lt;/span&gt; method in the following way.&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;String className = "com.commlink.cbs.appclient.gl.ChartsOfAccount"&lt;br /&gt;String methodName = "refreshForm";&lt;br /&gt;Class class = Class.forName(className );&lt;br /&gt;&lt;br /&gt;Object obj = class.newInstance();&lt;br /&gt;&lt;br /&gt;//create the class array &lt;br /&gt;Class[] types = new Class[] { String.class,String.class};&lt;br /&gt;&lt;br /&gt;//get the method&lt;br /&gt;Method method = class.getMethod(methodName ,types);&lt;br /&gt;&lt;br /&gt;//create the object array&lt;br /&gt;Object[] args = new Object[]{new String("Hello"), new String("World")};&lt;br /&gt;&lt;br /&gt;//call the method&lt;br /&gt;method.invoke(obj,args);&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-1384890661974796760?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/1384890661974796760/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=1384890661974796760' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/1384890661974796760'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/1384890661974796760'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2009/05/how-to-call-method-dynamically-using.html' title='How to call a method dynamically using Java Reflection'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-6917496950906081905</id><published>2009-05-09T17:03:00.000-07:00</published><updated>2009-06-13T17:46:26.835-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='Creat instance at runtime'/><category scheme='http://www.blogger.com/atom/ns#' term='Reflection'/><title type='text'>How to create an instance of a class at runtime using Java Reflection</title><content type='html'>Java Reflection gives us the facility of creating an instance of any class at run time. In our ERP project it helps us a lot to solve some critical problems. &lt;br /&gt;&lt;br /&gt;First create a class using the class name then use the &lt;span id="keyword1"&gt; class.newInstance&lt;/span&gt; method&lt;br /&gt;to create an instance of that class.&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;javax.swing.JPanel newPanel = null;&lt;br /&gt;&lt;br /&gt;String className= "com.commlinkinfotech.cbs.appclient.gl.ChartsOfAccount";&lt;br /&gt;&lt;br /&gt;Class class = Class.forName(className);&lt;br /&gt;&lt;br /&gt;//we know that the ChartsOfAccount is a JPanel class so cast this to JPanel&lt;br /&gt;newPanel = (JPanel) class.newInstance();&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;But if the constructor of your class takes some parameters then what will you do?&lt;br /&gt;&lt;br /&gt;You have to create an array of your argument class. Use this to create a constructor of your class using the &lt;span id="keyword1"&gt;class.getConstructor&lt;/span&gt; method. Now call the &lt;span id="keyword1"&gt;constructor.newInstance&lt;/span&gt; method with the value of the arguments and it gives you an instance of the class. &lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;javax.swing.JPanel newPanel = null;&lt;br /&gt;&lt;br /&gt;String className= "com.commlinkinfotech.cbs.appclient.gl.ChartsOfAccount";&lt;br /&gt;&lt;br /&gt;//create an array of parameter classes&lt;br /&gt;Class[] types = new Class[] { String.class };&lt;br /&gt;&lt;br /&gt;Class class = Class.forName(className);&lt;br /&gt;//create a constructor with the types array&lt;br /&gt;Constructor constructor = class.getConstructor(types);&lt;br /&gt;&lt;br /&gt;//create an array of argument values&lt;br /&gt;Object[] args = new Object[] {new String("Hello")};&lt;br /&gt;&lt;br /&gt;//now use ther args array to create an instance&lt;br /&gt;newPanel = (JPanel) constructor .newInstance(args);&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-6917496950906081905?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/6917496950906081905/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=6917496950906081905' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/6917496950906081905'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/6917496950906081905'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2009/05/how-to-create-instance-of-class-at.html' title='How to create an instance of a class at runtime using Java Reflection'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-8749937860602282310</id><published>2009-04-17T03:06:00.000-07:00</published><updated>2009-06-13T17:50:12.934-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='GroupLayout'/><title type='text'>Understanding GroupLayout in Java</title><content type='html'>GroupLayout is one of the most effective layout managers  in Java to place the GUI elements in a very organized way. Here I show you how to use Group Layout to build your GUI.&lt;br /&gt;&lt;br /&gt;GroupLayout works with the &lt;span id="keyword1"&gt;horizontal&lt;/span&gt; and &lt;span id="keyword1"&gt;vertical&lt;/span&gt; layouts separately. The layout is defined for each dimension independently and it uses two types of arrangements -- &lt;span id="keyword1"&gt;sequential&lt;/span&gt; and &lt;span id="keyword1"&gt;parallel&lt;/span&gt;, combined with hierarchical composition. Usually, components placed in parallel in one dimension are in a sequence in the other, so that they do not overlap.&lt;br /&gt;&lt;br /&gt;Let’s start with a very simple example to understand this layout.&lt;br /&gt;&lt;br /&gt;Suppose you have to put one JLabel and one JTextField component in a row within a container named jpTestGroupLayout&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_MwOzNujvBcI/SehbKh5GxAI/AAAAAAAAAIM/UHulKKRpxns/s1600-h/UGrpLayout1.jpg"&gt;&lt;img style="cursor: pointer; width: 264px; height: 41px;" src="http://3.bp.blogspot.com/_MwOzNujvBcI/SehbKh5GxAI/AAAAAAAAAIM/UHulKKRpxns/s200/UGrpLayout1.jpg" alt="" id="BLOGGER_PHOTO_ID_5325606795820319746" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;You have to put these comonents both in a Horizontal sequential group and in a Vertical sequential group. But how?&lt;br /&gt;&lt;br /&gt;To add the components in a horizontal sequential group at first you need to create two parallel groups. Add the JLable and the JTextField in the parallel groups then add these groups sequentially in the Horizontal sequential group.&lt;br /&gt;&lt;br /&gt;And to add the components in a Vertical sequential group, create one parallel group and add the components in the group. Then add this parallel group to your vertical sequential group.&lt;br /&gt;&lt;br /&gt;Now let’s look at the code to create the layout described above.&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;//declare the two component&lt;br /&gt;JLabel label = new javax.swing.JLabel();&lt;br /&gt;label.setText("JLabel");&lt;br /&gt;label.setBorder(null);&lt;br /&gt;JTextField jtfValue = new javax.swing.JTextField();&lt;br /&gt;jtfValue.setText("JTextField");&lt;br /&gt;&lt;br /&gt;//create a GroupLayout object associate with the panel&lt;br /&gt;GroupLayout grpLayout = new GroupLayout(jpTestGroupLayout); jpTestGroupLayout.setLayout(grpLayout);&lt;br /&gt;grpLayout.setAutoCreateGaps(true);      // specify automatic gap insertion&lt;br /&gt;grpLayout.setAutoCreateContainerGaps(true);&lt;br /&gt;&lt;br /&gt;//create the Horizontal and Vertical and sequential group&lt;br /&gt;GroupLayout.SequentialGroup horizontalSeqGrp = grpLayout.createSequentialGroup();&lt;br /&gt;GroupLayout.SequentialGroup verticalSeqGrp = grpLayout.createSequentialGroup();&lt;br /&gt;&lt;br /&gt;//create two parallel group for adding the components in the horizontal sequential group&lt;br /&gt;GroupLayout.ParallelGroup hParallelGroup1 = grpLayout.createParallelGroup(GroupLayout.Alignment.LEADING);&lt;br /&gt;GroupLayout.ParallelGroup hParallelGroup2 = grpLayout.createParallelGroup(GroupLayout.Alignment.LEADING);&lt;br /&gt;&lt;br /&gt;//add the components&lt;br /&gt;hParallelGroup1.addComponent(label);&lt;br /&gt;hParallelGroup2.addComponent(textField);&lt;br /&gt;&lt;br /&gt;//add two parallel groups sequentially in the horizontal sequential group&lt;br /&gt;horizontalSeqGrp.addGroup(hParallelGroup1);&lt;br /&gt;horizontalSeqGrp.addGroup(hParallelGroup2);&lt;br /&gt;&lt;br /&gt;//create one parallel group for adding the components in the vertical sequential group&lt;br /&gt;GroupLayout.ParallelGroup vparallelGroup1 = grpLayout.createParallelGroup(GroupLayout.Alignment.BASELINE);&lt;br /&gt;&lt;br /&gt;//add the components&lt;br /&gt;vparallelGroup1.addComponent(label);&lt;br /&gt;vparallelGroup1.addComponent(textField);&lt;br /&gt;&lt;br /&gt;//add this parallel group in the vertical sequential group&lt;br /&gt;verticalSeqGrp.addGroup(vparallelGroup1);&lt;br /&gt;&lt;br /&gt;//finally set the both sequential group to the grpLayout object&lt;br /&gt;grpLayout.setHorizontalGroup(horizontalSeqGrp);&lt;br /&gt;grpLayout.setVerticalGroup(verticalSeqGrp);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;If you want to add another JLabel in the same row then what will you do?&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_MwOzNujvBcI/SehcXRLs9nI/AAAAAAAAAIU/JHkb6eXDyQ0/s1600-h/UGrpLayout2.jpg"&gt;&lt;img style="cursor: pointer; width: 200px; height: 38px;" src="http://4.bp.blogspot.com/_MwOzNujvBcI/SehcXRLs9nI/AAAAAAAAAIU/JHkb6eXDyQ0/s200/UGrpLayout2.jpg" alt="" id="BLOGGER_PHOTO_ID_5325608114184844914" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;It is very simple now. Just create another parallel group to add the new JLable in the Horizontal sequential group and to add this to the Vertical sequential group add this in the existing vertical parallel group.&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;JLabel label2 = new javax.swing.JLabel();&lt;br /&gt;label2.setText("JLabel2");&lt;br /&gt;label2.setBorder(null);&lt;br /&gt;GroupLayout.ParallelGroup hParallelGroup3 = lout.createParallelGroup(GroupLayout.Alignment.LEADING);&lt;br /&gt;hParallelGroup3.addComponent(label2);&lt;br /&gt;&lt;br /&gt;//add the new parallel group to the horizontal sequential group&lt;br /&gt;horizontalSeqGrp.addGroup(hParallelGroup3); &lt;br /&gt;vparallelGroup1.addComponent(labe2l);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now I describe another scenario. Suppose you want to add the second JLable in the following way.&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_MwOzNujvBcI/SehcpdeqTXI/AAAAAAAAAIc/toyDG7MTf-I/s1600-h/UGrpLayout3.jpg"&gt;&lt;img style="cursor: pointer; width: 200px; height: 71px;" src="http://2.bp.blogspot.com/_MwOzNujvBcI/SehcpdeqTXI/AAAAAAAAAIc/toyDG7MTf-I/s200/UGrpLayout3.jpg" alt="" id="BLOGGER_PHOTO_ID_5325608426723233138" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The code will be like this&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;//add the new component in the hParallelGroup1&lt;br /&gt;hParallelGroup1.addComponent(label2);&lt;br /&gt;&lt;br /&gt;//create a new parallel group to add the new component in the vertical Sequential group&lt;br /&gt;GroupLayout.ParallelGroup vparallelGroup2 = grpLayout.createParallelGroup(GroupLayout.Alignment.BASELINE);&lt;br /&gt;&lt;br /&gt;//add the component to the new group&lt;br /&gt;vparallelGroup2.addComponent(label2);&lt;br /&gt;&lt;br /&gt;//add the new parallel group to the vertical sequential group&lt;br /&gt;verticalSeqGrp.addGroup(vparallelGroup2);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Try the above examples yourself and definitely you will find this layout very easy to manage. For more information &lt;a href="http://java.sun.com/docs/books/tutorial/uiswing/layout/group.html" target="_blank"&gt;visit this link.&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-8749937860602282310?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/8749937860602282310/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=8749937860602282310' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/8749937860602282310'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/8749937860602282310'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2009/04/understanding-grouplayout-in-java.html' title='Understanding GroupLayout in Java'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_MwOzNujvBcI/SehbKh5GxAI/AAAAAAAAAIM/UHulKKRpxns/s72-c/UGrpLayout1.jpg' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-6499042567178163564</id><published>2009-02-12T20:36:00.000-08:00</published><updated>2009-06-13T20:30:09.709-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JTable'/><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='filtering row'/><category scheme='http://www.blogger.com/atom/ns#' term='filter JTable Row'/><category scheme='http://www.blogger.com/atom/ns#' term='row filter with JTextfield'/><title type='text'>Filter a JTable row with input in a text field</title><content type='html'>In an enterprise application when there is huge amount data in a table&lt;br /&gt;users feel comfortable if you provide them a option for filtering the &lt;br /&gt;table. Here I show you an example of how to filter a JTable row with &lt;br /&gt;input in a JTextField.&lt;br /&gt;&lt;br /&gt;Declare a JTable and your own table model&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;private MyTableModel tableModel;&lt;br /&gt;private javax.swing.JTable jtblSampleTable;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now declare a table row sorter for that table model&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;private TableRowSorter&lt;MyTableModel&gt; sorter ;&lt;br /&gt;//&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Initialize all the above three declared variables&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;jtblSampleTable  = new javax.swing.JTable();&lt;br /&gt;tableModel  = new MyTableModel();&lt;br /&gt;sorter = new TableRowSorter&lt;MyTableModel&gt;(tableModel);&lt;br /&gt;//&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Bind the model with the table&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;jtblSampleTable.setModel(tableModel);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Set the sorter as the row sorter for the table&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;jtblSampleTable.setRowSorter(sorter);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now declare a JTextField &lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;jtfSearch = new javax.swing.JTextField();&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Add a document listener for the search text field.&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;jtfSearch.getDocument().addDocumentListener(&lt;br /&gt;   new DocumentListener()&lt;br /&gt;   {&lt;br /&gt;      public void changedUpdate(DocumentEvent e)&lt;br /&gt;      {&lt;br /&gt;          newFilter();&lt;br /&gt;      }&lt;br /&gt;      public void insertUpdate(DocumentEvent e)&lt;br /&gt;      {&lt;br /&gt;          newFilter();&lt;br /&gt;      }&lt;br /&gt;      public void removeUpdate(DocumentEvent e)&lt;br /&gt;      {&lt;br /&gt;         newFilter();&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;Here is the newFilter method&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="java"&gt;&lt;br /&gt;private void newFilter()&lt;br /&gt;{&lt;br /&gt;    RowFilter&lt; MyTableModel  , Object&gt; rf = null; &lt;br /&gt;    //declare a row filter for your table model&lt;br /&gt;    Try&lt;br /&gt;    {&lt;br /&gt;        rf = RowFilter.regexFilter("^" + jtfSearch.getText(), 0);  &lt;br /&gt;        //initialize with a regular expression&lt;br /&gt;    }&lt;br /&gt;    catch (java.util.regex.PatternSyntaxException e)&lt;br /&gt;    {&lt;br /&gt;        return;&lt;br /&gt;    }&lt;br /&gt;    sorter.setRowFilter(rf);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br&gt;&lt;br /&gt;The above example is able to filter JTable for its first column.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-6499042567178163564?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/6499042567178163564/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=6499042567178163564' title='13 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/6499042567178163564'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/6499042567178163564'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2009/02/filter-jtable-row-with-input-in-text.html' title='Filter a JTable row with input in a text field'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><thr:total>13</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-3372503637556156814</id><published>2009-02-02T01:04:00.000-08:00</published><updated>2009-06-13T20:33:40.854-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='video'/><category scheme='http://www.blogger.com/atom/ns#' term='YouTube'/><category scheme='http://www.blogger.com/atom/ns#' term='show video from YouTube'/><title type='text'>Show video from YouTube in your own website</title><content type='html'>To show a video from your website, first upload the video in YouTube.&lt;br /&gt;After uploading the vidio add the following code in your website.&lt;br /&gt;&lt;br /&gt;&lt;pre name = "code" class = "html"&gt;&lt;br /&gt;&amp;lt;object style="width: 360; height: 250; margin-top: auto; margin-bottom: auto; vertical-align: middle;"&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;param name="movie" value="http://www.youtube.com/v/r-gDDUcaVqI&amp;amp;hl=en&amp;amp;fs=1&amp;gt; &lt;br /&gt;&amp;lt;/param&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;param name="allowFullScreen" value="true"&amp;gt; &amp;lt;/param&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;embed src="http://www.youtube.com/v/r-gDDUcaVqI&amp;amp;hl=en&amp;amp;fs=1 type="application/x-shockwave-flash" allowfullscreen="true" width="360" height="250"&amp;gt;&lt;br /&gt;&amp;lt;/embed&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/object&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;In the param tag the value attribute holds the url of your video.&lt;br /&gt;To change the display screen size simply change the width and height attribute&lt;br /&gt;of the embed tag.&lt;br /&gt;&lt;br /&gt;This is very simplet just copy and paste the code in your site and test it..&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-3372503637556156814?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/3372503637556156814/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=3372503637556156814' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/3372503637556156814'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/3372503637556156814'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2009/02/show-video-from-youtube-in-your-own.html' title='Show video from YouTube in your own website'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-5568820466029918180</id><published>2009-01-28T19:04:00.000-08:00</published><updated>2009-06-13T20:38:55.018-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rounded corner'/><category scheme='http://www.blogger.com/atom/ns#' term='rounded div'/><title type='text'>Creating a colorful rounded cornered Div</title><content type='html'>Rounded corner is one of the hottest topics in today’s web designing. Here you find a nice way of creating different colored rounded div. In my example, I have created one green and one yellow div.&lt;br /&gt;&lt;br /&gt;The required css is&lt;br /&gt;&lt;pre name = "code" class = "css"&gt;&lt;br /&gt;b.r1{margin: 0 5px}&lt;br /&gt;b.r2{margin: 0 3px}&lt;br /&gt;b.r3{margin: 0 2px}&lt;br /&gt;h4,p{margin: 0 10px}&lt;br /&gt;&lt;br /&gt;/*for yellow div*/&lt;br /&gt;div#yellow_div{&lt;br /&gt;margin: 0 5%;&lt;br /&gt;background: #F7FC62;           &lt;br /&gt;/*change color here to get a different color div */&lt;br /&gt;}&lt;br /&gt;b.rtop_yellow, b.rbottom_yellow{display:block;background: #FFF}&lt;br /&gt;b.rtop_yellow b, b.rbottom_yellow b{display:block;height: 1px;&lt;br /&gt;overflow: hidden; background: #F7FC62}                                      &lt;br /&gt;/*change color here to get a different colored div */&lt;br /&gt;b.rtop_yellow b.r4, b.rbottom_yellow b.r4{margin: 0 1px;&lt;br /&gt;height: 2px}&lt;br /&gt;&lt;br /&gt;/*for green div*/&lt;br /&gt;div# green_div{&lt;br /&gt;margin: 0 5%;&lt;br /&gt;background: #8FFF63;                 &lt;br /&gt;/*color changed  */&lt;br /&gt;}&lt;br /&gt;b.rtop_green, b.rbottom_green{display:block;background: #FFF}&lt;br /&gt;b.rtop_green b, b.rbottom_green b{display:block;height: 1px;&lt;br /&gt;overflow: hidden; background: #8FFF63}                                   &lt;br /&gt;/*color changed */&lt;br /&gt;b.rtop_green b.r4, b.rbottom_green b.r4{margin: 0 1px;&lt;br /&gt;height: 2px}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now you will find how to use this css to create two colorful div&lt;br /&gt;&lt;pre name = "code" class = "html"&gt;&lt;br /&gt;&amp;lt;div id=" yellow_div " style="width:250px; "&amp;gt;&lt;br /&gt;&amp;lt;b class="rtop_yellow"&amp;gt;&amp;lt;b class="r1"&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;b class="r2"&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;b class="r3"&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;&amp;lt;b class="r4"&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;  &amp;nbsp;&amp;nbsp;place your content here&amp;lt;br&amp;gt;&lt;br /&gt; &amp;nbsp;&amp;nbsp;place your content here&amp;lt;br&amp;gt;&lt;br /&gt; &amp;nbsp;&amp;nbsp;place your content here&amp;lt;br&amp;gt;&lt;br /&gt;&amp;lt;b class="rbottom_yellow"&amp;gt;&amp;lt;b class="r4"&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;b class="r3"&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;b class="r2"&amp;gt;&lt;br /&gt;&amp;lt;/b&amp;gt;&amp;lt;b class="r1"&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;br&amp;gt;&lt;br /&gt;&amp;lt;div id=" green_div " style="width:250px; "&amp;gt;&lt;br /&gt;&amp;lt;b class="rtop_green"&amp;gt;&amp;lt;b class="r1"&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;b class="r2"&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;b class="r3"&amp;gt;&lt;br /&gt;&amp;lt;/b&amp;gt;&amp;lt;b class="r4"&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt; &amp;nbsp;&amp;nbsp;place your content here&amp;lt;br&amp;gt;&lt;br /&gt; &amp;nbsp;&amp;nbsp;place your content here&amp;lt;br&amp;gt;&lt;br /&gt; &amp;nbsp;&amp;nbsp;place your content here&amp;lt;br&amp;gt;&lt;br /&gt;&amp;lt;b class="rbottom_green"&amp;gt;&amp;lt;b class="r4"&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;b class="r3"&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;b class="r2"&amp;gt;&lt;br /&gt;&amp;lt;/b&amp;gt;&amp;lt;b class="r1"&amp;gt;&amp;lt;/b&amp;gt;&amp;lt;/b&amp;gt;&lt;br /&gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The result will be like this.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_MwOzNujvBcI/SYEd92gMzsI/AAAAAAAAAG4/NLZU1rB1W-c/s1600-h/yellow_rounded.bmp"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 263px; height: 82px;" src="http://3.bp.blogspot.com/_MwOzNujvBcI/SYEd92gMzsI/AAAAAAAAAG4/NLZU1rB1W-c/s320/yellow_rounded.bmp" alt="" id="BLOGGER_PHOTO_ID_5296547585204211394" border="0" /&gt;&lt;/a&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_MwOzNujvBcI/SYEeE_8YlQI/AAAAAAAAAHA/IUuezu95FXM/s1600-h/green_rounded.bmp"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 263px; height: 82px;" src="http://3.bp.blogspot.com/_MwOzNujvBcI/SYEeE_8YlQI/AAAAAAAAAHA/IUuezu95FXM/s320/green_rounded.bmp" alt="" id="BLOGGER_PHOTO_ID_5296547707997426946" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;You can easily create you own color div just by changing the color in css I mentioned above&lt;br /&gt;and use that name in div id and class attribute of b tag.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-5568820466029918180?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/5568820466029918180/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=5568820466029918180' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/5568820466029918180'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/5568820466029918180'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2009/01/creating-colorful-rounded-cornered-div.html' title='Creating a colorful rounded cornered Div'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_MwOzNujvBcI/SYEd92gMzsI/AAAAAAAAAG4/NLZU1rB1W-c/s72-c/yellow_rounded.bmp' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-7312346229054282394</id><published>2008-09-22T20:16:00.000-07:00</published><updated>2009-06-13T20:42:17.815-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='custom dialog'/><title type='text'>Showing your own custom dialog box in java</title><content type='html'>While developing our ERP application we need to show a list of &lt;br /&gt;all accounts in a dialog box and upon selecting an account the&lt;br /&gt;base form will be updated. For this we need our custom dialog &lt;br /&gt;box to show the list of accounts. Here i give an example of how&lt;br /&gt;can you show your own custom dialog box and get desired value on&lt;br /&gt;closing the dialog.&lt;br /&gt;&lt;br /&gt;At first i like to describe the custom dialog class.&lt;br /&gt;&lt;br /&gt;&lt;pre name = "code" class = "java"&gt;&lt;br /&gt;&lt;br /&gt;import javax.swing.JDialog;&lt;br /&gt;import javax.swing.JFrame;&lt;br /&gt;&lt;br /&gt;/**&lt;br /&gt;* @author  ratul&lt;br /&gt;*/&lt;br /&gt;public class CustomDialog extends JDialog {&lt;br /&gt;&lt;br /&gt;   private javax.swing.JLabel jLabel1;&lt;br /&gt;   private javax.swing.JButton jbtOK;&lt;br /&gt;   private javax.swing.JTextField jtfInput;&lt;br /&gt;   private String inputString = "";&lt;br /&gt;&lt;br /&gt;   public CustomDialog(JFrame frame, boolean modal) {&lt;br /&gt;       super(frame, modal);&lt;br /&gt;       initComponents();&lt;br /&gt;       pack();&lt;br /&gt;       setLocationRelativeTo(frame);&lt;br /&gt;       setVisible(true);&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   private void initComponents() {&lt;br /&gt;&lt;br /&gt;       jbtOK = new javax.swing.JButton();&lt;br /&gt;       jtfInput = new javax.swing.JTextField();&lt;br /&gt;       jLabel1 = new javax.swing.JLabel();&lt;br /&gt;&lt;br /&gt;       setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());&lt;br /&gt;&lt;br /&gt;       jbtOK.setText("OK");&lt;br /&gt;       jbtOK.addActionListener(new java.awt.event.ActionListener() {&lt;br /&gt;           public void actionPerformed(java.awt.event.ActionEvent evt) {&lt;br /&gt;               jbtOKActionPerformed(evt);&lt;br /&gt;           }&lt;br /&gt;       });&lt;br /&gt;       add(jbtOK, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 190,&lt;br /&gt;           -1,-1));&lt;br /&gt;&lt;br /&gt;       jtfInput.addKeyListener(new java.awt.event.KeyAdapter() {&lt;br /&gt;           public void keyReleased(java.awt.event.KeyEvent evt) {&lt;br /&gt;               jtfInputKeyReleased(evt);&lt;br /&gt;           }&lt;br /&gt;       });&lt;br /&gt;       add(jtfInput, new org.netbeans.lib.awtextra.AbsoluteConstraints(180, 120,&lt;br /&gt;           160, 20));&lt;br /&gt;&lt;br /&gt;       jLabel1.setText("Input some text here:");&lt;br /&gt;       add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 120,&lt;br /&gt;           -1, -1));&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   private void jbtOKActionPerformed(java.awt.event.ActionEvent evt) &lt;br /&gt;   {&lt;br /&gt;      this.dispose();&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   private void jtfInputKeyReleased(java.awt.event.KeyEvent evt) &lt;br /&gt;   {&lt;br /&gt;      inputString += evt.getKeyChar();&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   public String getInputText()&lt;br /&gt;   {&lt;br /&gt;       return inputString;&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The CustomDialog class extends the JDialog class. The first&lt;br /&gt;parameter of the constructor is the parent frame, second parameter&lt;br /&gt;determines whether the parent frame is disabled or enabled when &lt;br /&gt;the dialog box will be shown.&lt;br /&gt;&lt;br /&gt;In the key released action of the text field i populate the inputString.&lt;br /&gt;The dialog box can be closed either by clicking the 'OK' button or close&lt;br /&gt;button of the top right corner. You can get the value of the input &lt;br /&gt;field from the parent from by calling the &lt;span id = "keyword1"&gt;public String getInputText()&lt;/span&gt; method.&lt;br /&gt;&lt;br /&gt;Now i describe how to open your custom dialog box:&lt;br /&gt;In the action handler of a button in the parent frame write the following code&lt;br /&gt;&lt;br /&gt;&lt;pre name = "code" class = "java"&gt;&lt;br /&gt;  &lt;br /&gt;   CustomDialog cDialog = new CustomDialog(this, true);&lt;br /&gt;   this.jtfShowText.setText(cDialog.getInputText());&lt;br /&gt;  &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This will show the dialog box. Now Input some text on the text field&lt;br /&gt;and close the dialog box. The input text will be shown in the text &lt;br /&gt;field of the parent frame.&lt;br /&gt;&lt;br /&gt;NB: use null or absolute layout to design the custom dialog box.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-7312346229054282394?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/7312346229054282394/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=7312346229054282394' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/7312346229054282394'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/7312346229054282394'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2008/09/showing-your-own-custom-dialog-box-in.html' title='Showing your own custom dialog box in java'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-5897427747025943997</id><published>2008-08-14T02:23:00.000-07:00</published><updated>2009-05-20T03:29:40.700-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java Persistence'/><category scheme='http://www.blogger.com/atom/ns#' term='JPQL'/><category scheme='http://www.blogger.com/atom/ns#' term='Java Persistence Query Language'/><category scheme='http://www.blogger.com/atom/ns#' term='Persistence Query'/><title type='text'>Introduction to Java Persistence Query Language (JPQL)</title><content type='html'>The Java Persistence Query Language(JPQL) is one of the basic area of Java Persistence  which allows you to write portable queries that work regardless of the underlying data store. It uses a SQL-like syntax to select objects or values based on entity abstract schema types and relationships among them. An entity is  a lightweight persistence domain object. Typically an entity represents a table in a relational database, and each entity instance corresponds to a row in that table.&lt;br /&gt;&lt;br /&gt;Here i describes some syntax of the language so that you can build&lt;br /&gt;your own query in JPQL easily.&lt;br /&gt;&lt;br /&gt;Lets start from a basic select query&lt;br /&gt;&lt;span id = "keyword1"&gt;SELECT  p FROM Player p&lt;/span&gt;&lt;br /&gt;This statement retrieves all players from Player entity.&lt;br /&gt;&lt;br /&gt;Now write a query with WHERE clause and input parameter&lt;br /&gt;&lt;span id = "keyword1"&gt;SELECT DISTINCT  p FROM Player p WHERE p.position = ?1&lt;/span&gt;&lt;br /&gt;Retrieves players with the position specified. The DISTINCT keyword eliminates duplicate values. ?1 element denotes the input parameter of the query. Here position a persistent field of the Player Entity.&lt;br /&gt;&lt;br /&gt;Select statement with named parameters&lt;br /&gt;&lt;span id = "keyword1"&gt;SELECT DISTINCT p FROM Player p WHERE p.position  =  :position AND p.name  =  :name&lt;/span&gt;&lt;br /&gt;The WHERE clause compares the values of these fields with the&lt;br /&gt;named parameters of the query, set using the Query.setNamedParameter&lt;br /&gt;method. The query language denotes a named input parameter using&lt;br /&gt;colon (:) followed by an identifier. The first input parameter is&lt;br /&gt;:position, the second is :name.&lt;br /&gt;&lt;br /&gt;At the time of writing Entity we relates one entity with another. Lets&lt;br /&gt;talk about queries that navigate to related entities. One thing to&lt;br /&gt;remember&lt;span id = "keyword2"&gt;"Expressions can navigate to relationship fields (related&lt;br /&gt;entities), but not to persistent fields"&lt;/span&gt;&lt;br /&gt;&lt;span id = "keyword1"&gt;SELECT DISTINCT p FROM Player p, IN(p.teams) t&lt;/span&gt;&lt;br /&gt;Retrieves All players who belong to a team.  The IN keyword signifies&lt;br /&gt;that teams is a collection of the Player entity. The p.teams&lt;br /&gt;expression navigates from a Player to its related Team. The period&lt;br /&gt;in the p.teams expression is the navigation operator.&lt;br /&gt;&lt;br /&gt;JOIN statement for the same query&lt;br /&gt;&lt;span id = "keyword1"&gt;SELECT DISTINCT p FROM Player p JOIN p.teams t&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Another statement that serves the same purpose&lt;br /&gt;&lt;span id = "keyword1"&gt;SELECT DISTINCT p FROM Player p WHERE p.team IS NOT EMPTY&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Navigating to single valued relationship field&lt;br /&gt;&lt;span id = "keyword1"&gt;SELECT t FROM Team t JOIN t.league l WHERE l.sport = 'soccer' OR l.sport  ='football'&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Navigating relationship field with input parameter&lt;br /&gt;&lt;span id = "keyword1"&gt;SELECT DISTINCT p FROM Player p, IN (p.teams)  t WHERE t.city = :city&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Some times you need to traverse multiple relationships. Following query navigate over two relationships.&lt;br /&gt;&lt;span id = "keyword1"&gt;SELECT DISTINCT p FROM Player p, IN (p.teams) t WHERE t.league = :league&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;To reach to a persistent field of league you can navigate by following way&lt;br /&gt;&lt;span id = "keyword1"&gt;SELECT DISTINCT p FROM Player p, IN (p.teams) t WHERE t.league.sport = :sport&lt;/span&gt;&lt;br /&gt;Here sport is a persistent field of League. And you have to navigate from Player to League via Team.&lt;br /&gt;&lt;br /&gt;After WHERE clause you have to use some conditional expression.&lt;br /&gt;Lets talk about conditional expressions of JPQL&lt;br /&gt;&lt;strong&gt;LIKE:&lt;/strong&gt;&lt;br /&gt;&lt;span id = "keyword1"&gt;SELECT p FROM Player p WHERE p.name LIKE 'Mich%'&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;IS NULL:&lt;/strong&gt;&lt;br /&gt;&lt;span id = "keyword1"&gt;SELECT t FROM Team t WHERE t.league IS NULL&lt;/span&gt;&lt;br /&gt;Retrieves All teams not associated with a league.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;IS EMPTY:&lt;/strong&gt;&lt;br /&gt;&lt;span id = "keyword1"&gt;SELECT p FROM Player p WHERE p.teams IS EMPTY&lt;/span&gt;&lt;br /&gt;Retrieves all players not belong to a team&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;BETWEEN:&lt;/strong&gt;&lt;br /&gt;&lt;span id = "keyword1"&gt;SELECT DISTINCT p FROM Player p WHERE p.salary BETWEEN :lowerSalary AND :higherSalary&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;[NOT] MEMBER [OF]:&lt;/strong&gt;(Determines whether a value is a member of a collection. The value and the collection members must have the same type):&lt;br /&gt;&lt;span id = "keyword1"&gt;SELECT o FROM Order o WHERE :lineItem MEMBER OF o.lineItems&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;[NOT] EXISTS:&lt;/strong&gt;(Return true only if the result of the subquery consists of one or more values and is false otherwise):&lt;br /&gt;&lt;span id = "keyword1"&gt;SELECT DISTINCT emp FROM Employee emp WHERE EXISTS (SELECT spouseEmp FROM Employee spouseEmp WHERE spouseEmp = emp.spouse)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;ALL&lt;/strong&gt; and &lt;strong&gt;ANY:&lt;/strong&gt;&lt;br /&gt;The ALL expression is used with a sub-query, and is true if all the&lt;br /&gt;values returned by the sub-query are true, or if the sub-query is empty.&lt;br /&gt;&lt;br /&gt;The ANY expression is used with a sub-query, and is true if some of&lt;br /&gt;the values returned by the sub-query are true. An ANY expression&lt;br /&gt;is false if the sub-query result is empty, or if all the values returned&lt;br /&gt;are false. The SOME keyword is synonymous with ANY.&lt;br /&gt;The ALL and ANY expressions are used with the =, &lt;, &lt;=, &gt;, &gt;=, &lt;&gt;&lt;br /&gt;comparison operators.&lt;br /&gt;&lt;span id = "keyword1"&gt;SELECT emp FROM Employee emp WHERE emp.salary &gt; ALL (&lt;br /&gt;SELECT m.salary FROM Manager m WHERE m.department = emp.department)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The following two queries tell you how to write UPDATE and DELETE&lt;br /&gt;statement in JPQL&lt;br /&gt;&lt;span id = "keyword1"&gt;UPDATE Player p SET p.status = 'inactive' WHERE p.lastPlayed &lt; :inactiveThr&lt;/span&gt;&lt;br /&gt;&lt;span id = "keyword1"&gt;DELETE FROM Player p WHERE p.status = 'inactive' AND p.teams IS EMPTY&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Lets talk about aggregate functions of JPQL, Some frequently used aggregate functions are AVG, COUNT, MAX, MIN, SUM.&lt;br /&gt;&lt;span id = "keyword1"&gt;SELECT AVG(o.quantity) FROM Order o &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id = "keyword1"&gt;SELECT SUM(l.price) FROM Order  o  JOIN  o.lineItems  l  JOIN o.customer  c WHERE c.lastname = 'Coss' AND c.firstname = 'Roxane' &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In most cases after aggregate functions you have to use GROUP_BY or HAVING clause. but how to use them in JPQL? Here is the answer&lt;br /&gt;&lt;span id = "keyword1"&gt;SELECT  c.country, COUNT(c)  FROM Customer  c  GROUP BY  c.country&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span id = "keyword1"&gt;SELECT  c.status, AVG(o.totalPrice)  FROM Order  o  JOIN  o.customer  c GROUP BY  c.status  HAVING  c.status  IN (1, 2, 3) &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;If you want to fetch data by your defined order then use ORDER_BY in the query&lt;br /&gt;&lt;span id = "keyword1"&gt;SELECT o FROM Customer  c  JOIN  c.orders  o  JOIN  c.address  a WHERE  a.state  = 'CA' ORDER BY o.quantity, o.totalcost&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Constructor expressions: It is an advance feature of JPQL. It allows you to return Java instances that store a query result element instead of an Object[]. The following query creates a CustomerDetail instance per Customer matching the WHERE clause. A CustomerDetail stores the customer name and customer’s country name. So the query returns a List of CustomerDetail instances.&lt;br /&gt;&lt;span id = "keyword1"&gt;SELECT NEW com.xyz.CustomerDetail(c.name, c.country.name) FROM customer c WHERE c.lastname = 'Coss' AND c.firstname = 'Roxane' &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;For more information about JPQL &lt;a href="http://edocs.bea.com/kodo/docs41/full/html/ejb3_langref.html#ejb3_langref_path"&gt;click here &lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-5897427747025943997?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/5897427747025943997/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=5897427747025943997' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/5897427747025943997'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/5897427747025943997'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2008/08/introduction-to-java-persistence-query.html' title='Introduction to Java Persistence Query Language (JPQL)'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-4334008494563774538</id><published>2008-07-03T05:08:00.000-07:00</published><updated>2009-06-14T20:27:00.701-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Open flash chart'/><category scheme='http://www.blogger.com/atom/ns#' term='flash chart'/><title type='text'>How to create a Open flash chart in Rails Application</title><content type='html'>&lt;a href="http://teethgrinder.co.uk/open-flash-chart/"&gt;Open flash chart&lt;/a&gt; is a free service, by using it you can create different types of charts easily.&lt;br /&gt;&lt;br /&gt;To create a open flash chart in Rails application at first you need&lt;br /&gt;the open flash chart plugin. To get this plugin go to your project folder and run:&lt;br /&gt;&lt;span id = "keyword1"&gt;ruby script/plugin install http://svn.pullmonkey.com/plugins/trunk/open_flash_chart/&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;After this Move the open_flash_chart.swf file into your RAILS_ROOT/public directory&lt;br /&gt;&lt;br /&gt;Now create a controller and add the following code&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="ruby"&gt;&lt;br /&gt;def index&lt;br /&gt;  @graph_data = open_flash_chart_object(450,220, &lt;br /&gt;                '/flash_chart/show_flash_chart',false,'/',true)&lt;br /&gt;end&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="ruby"&gt;&lt;br /&gt;def show_flash_chart&lt;br /&gt;  begin&lt;br /&gt;    chart = draw_chart&lt;br /&gt;    render :text =&gt; chart&lt;br /&gt;    rescue Exception =&gt; error&lt;br /&gt;    logger.debug "error&gt;&gt;" + error.inspect&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="ruby"&gt;&lt;br /&gt;def draw_chart&lt;br /&gt;&lt;br /&gt;  chart_data = get_chart_data&lt;br /&gt; &lt;br /&gt;  #get data to display in chart&lt;br /&gt;  x_lebels = chart_data[:x_level]&lt;br /&gt;  &lt;br /&gt;  # get x labels in a array&lt;br /&gt;  data = chart_data[:value]&lt;br /&gt;  &lt;br /&gt;  # get y axis value &lt;br /&gt;  line_data_hashes = [{:color =&gt; "#e11456", &lt;br /&gt;                    :legend =&gt; "Cost", :values =&gt; data}]&lt;br /&gt;  g = Graph.new&lt;br /&gt;  &lt;br /&gt;  #draw line&lt;br /&gt;  if line_data_hashes&lt;br /&gt;    line_data_hashes.each do |line|&lt;br /&gt;      g.line(2, line[:color], line[:legend], 10)&lt;br /&gt;      g.set_data(line[:values])&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;  &lt;br /&gt;  g.set_tool_tip('Year: #x_label#&lt;br /&gt;  Cost: #val#')&lt;br /&gt;  g.set_title("Sample Flash Chart",&lt;br /&gt;              '{font-size: 14px; color: #784016}')&lt;br /&gt;  &lt;br /&gt;  #set minimum y axis value&lt;br /&gt;  g.set_y_min(0) &lt;br /&gt;  &lt;br /&gt;  #set maximum y axis value&lt;br /&gt;  g.set_y_max(100)&lt;br /&gt;  &lt;br /&gt;  #set number of steps in y axis&lt;br /&gt;  g.set_y_label_steps(5) &lt;br /&gt;  &lt;br /&gt;  # set y axis legend&lt;br /&gt;  g.set_y_legend("Cost", 12, "#b9d800") &lt;br /&gt;  &lt;br /&gt;  # set x axix value&lt;br /&gt;  g.set_x_labels(x_lebels)&lt;br /&gt;  &lt;br /&gt;  #set x axis label's style&lt;br /&gt;  g.set_x_label_style(10, '#000000', 2) &lt;br /&gt;  &lt;br /&gt;  #set x axis legend&lt;br /&gt;  g.set_x_legend("Year", 12, "#b9d800")  &lt;br /&gt;&lt;br /&gt;  return g.render&lt;br /&gt;&lt;br /&gt;end&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;In index.rhtml put the following code&lt;br /&gt;&lt;pre name="code" class="ruby"&gt;&lt;br /&gt;  &lt;%= @graph_data %&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now run it and you will see the magic&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_MwOzNujvBcI/SGzr8ypSoXI/AAAAAAAAABI/DoU8KtNMdNM/s1600-h/open_flash_chart.bmp"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://4.bp.blogspot.com/_MwOzNujvBcI/SGzr8ypSoXI/AAAAAAAAABI/DoU8KtNMdNM/s320/open_flash_chart.bmp" alt="" id="BLOGGER_PHOTO_ID_5218805497835200882" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-4334008494563774538?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/4334008494563774538/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=4334008494563774538' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/4334008494563774538'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/4334008494563774538'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2008/07/how-to-creat-open-flash-chart-in-rails.html' title='How to create a Open flash chart in Rails Application'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_MwOzNujvBcI/SGzr8ypSoXI/AAAAAAAAABI/DoU8KtNMdNM/s72-c/open_flash_chart.bmp' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-7254113317077441586</id><published>2008-06-26T02:40:00.000-07:00</published><updated>2009-02-01T20:57:03.101-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Contiuous Integration'/><category scheme='http://www.blogger.com/atom/ns#' term='Rails Application'/><category scheme='http://www.blogger.com/atom/ns#' term='cruisecontrol.rb'/><title type='text'>How to run cruisecontrol.rb for continuous integration  of Ruby on Rails application</title><content type='html'>&lt;span style="font-size:100%;"&gt;CruiseControl.rb is a continuous integration tool for Ruby on Rails application. Its basic purpose is to alert members of a software project when one of them checks something into source control that breaks the build.&lt;br /&gt;&lt;br /&gt;To run cruisecontrol.rb first download it from &lt;a href="http://cruisecontrolrb.thoughtworks.com/"&gt;http://cruisecontrolrb.thoughtworks.com/&lt;/a&gt;&lt;br /&gt;Unpack the downloaded file.&lt;br /&gt;Then go to the folder from command prompt where it is unpacked&lt;br /&gt;and run: &lt;/span&gt;&lt;span id = "keyword1"&gt;cruise add project_name --url&lt;/span&gt;&lt;span id = "keyword1"&gt; (url of your subversion trunk)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;This will create a directory under &lt;span style="FONT-WEIGHT: bold"&gt;[cruise_data]/project/project_name&lt;/span&gt; and then checks out your project from the subversion URL you provided to &lt;span style="FONT-WEIGHT: bold"&gt;[cruise_data]/projects/project_name/work/&lt;/span&gt; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;Now run: &lt;span id = "keyword1"&gt;cruise start&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;This will start your web browser on port 3333&lt;br /&gt;Browse http://localhost:3333 and press the “Build Now” button on the Dashboard to build your project.&lt;br /&gt;&lt;br /&gt;After this every time any one checks something into source control cruise control automatically&lt;br /&gt;builds your project and report about the Build Changeset , Test failures and errors, etc.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-7254113317077441586?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/7254113317077441586/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=7254113317077441586' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/7254113317077441586'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/7254113317077441586'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2008/06/how-to-run-cruisecontrolrb-for.html' title='How to run cruisecontrol.rb for continuous integration  of Ruby on Rails application'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-3743262459213440078</id><published>2008-06-06T22:40:00.000-07:00</published><updated>2009-02-01T20:37:46.519-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Asynchronous mail sending'/><category scheme='http://www.blogger.com/atom/ns#' term='Asynchronous'/><category scheme='http://www.blogger.com/atom/ns#' term='ActiveMessaging'/><category scheme='http://www.blogger.com/atom/ns#' term='Amazon SQS'/><category scheme='http://www.blogger.com/atom/ns#' term='Amazon'/><title type='text'>Sending mail asynchronously by using Amazon SQS and ActiveMessaging</title><content type='html'>From our application we send mail to our users in many cases. Sending mail synchronously slows down the whole process. So to improve our application’s performance we feel the need of sending mail asynchronously. And I have done it using the &lt;a href="http://www.amazon.com/Simple-Queue-Service-home-page/b?ie=UTF8&amp;amp;node=13584001"&gt;Amazon SQS &lt;/a&gt;and &lt;a href="http://code.google.com/p/activemessaging/wiki/ActiveMessaging"&gt;ActiveMessaging&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;span id = "keyword2"&gt;What is &lt;/span&gt;&lt;a href="http://www.amazon.com/Simple-Queue-Service-home-page/b?ie=UTF8&amp;amp;node=13584001"&gt;Amazon SQS&lt;/a&gt;:&lt;br /&gt;&lt;br /&gt;Amazon Simple Queue Service (Amazon SQS) offers a reliable, highly scalable, hosted queue for storing messages as they travel between computers.&lt;br /&gt;Developers can push message to the queue any time and get the message when required. They can create an unlimited number of Amazon SQS queues, each of which can send and receive an unlimited number of messages. The message body can contain up to 8 KB of text in any format. A message is "locked" while a computer is processing it Messages can be retained in queues for up to 4 days&lt;br /&gt;&lt;br /&gt;&lt;span id = "keyword2"&gt;What is &lt;/span&gt;&lt;a href="http://code.google.com/p/activemessaging/wiki/ActiveMessaging"&gt;ActiveMessaging&lt;/a&gt;:&lt;br /&gt;&lt;br /&gt;ActiveMessaging is a Rails plug-in framework, which simplifies messaging integration. It is a generic framework to ease using messaging, but is not tied to any particular messaging system - in fact, it now has support for Stomp, JMS (using Stomp Connect or direct on JRuby), WebSphere MQ, Amazon Simple Queue Service (SQS), and the all Ruby ReliableMessaging. With ActiveMessaging and Rails now you can loosely integrate with systems as disparate as mainframes sending MQ messages or J2EE webapps, offload processing long-running tasks, or create applications with event or message-driven architectures.&lt;br /&gt;&lt;br /&gt;To integrate ActiveMessagin with your apllication&lt;br /&gt;you have to install the following gem and pugin&lt;br /&gt;&lt;br /&gt;&lt;span id ="keyword1"&gt;gem install daemons&lt;/span&gt;&lt;br /&gt;&lt;span id ="keyword1"&gt;ruby script/plugin install&lt;/span&gt;&lt;a href="http://activemessaging.googlecode.com/svn/trunk/plugins/activemessaging"&gt;http://activemessaging.googlecode.com/svn/trunk/plugins/activemessaging&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;First create a process using the following command&lt;br /&gt;&lt;span  id ="keyword1"&gt;script/generate processor message&lt;/span&gt;&lt;br /&gt;Running this generate for the first time outputs the following:&lt;br /&gt;&lt;br /&gt;create app/processors&lt;br /&gt;create app/processors/message_processor.rb&lt;br /&gt;create config/messaging.rb&lt;br /&gt;create config/broker.yml&lt;br /&gt;create app/processors/application.rb&lt;br /&gt;create script/poller&lt;br /&gt;&lt;br /&gt;Now configure the &lt;span  id ="keyword2"&gt;broker.yml&lt;/span&gt; as which broker you are using.&lt;br /&gt;I have used Amazon SQS as a broker. Here is my configure file&lt;br /&gt;&lt;br /&gt;development:&lt;br /&gt;adapter: asqs&lt;br /&gt;access_key_id: xxxxxxxxxxxxxxxxxxxxxxxx&lt;br /&gt;secret_access_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&lt;br /&gt;&lt;br /&gt;test:&lt;br /&gt;adapter: asqs&lt;br /&gt;access_key_id: xxxxxxxxxxxxxxxxxxxxxxxx&lt;br /&gt;secret_access_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&lt;br /&gt;&lt;br /&gt;production:&lt;br /&gt;adapter: asqs&lt;br /&gt;access_key_id: xxxxxxxxxxxxxxxxxxxxxxxx&lt;br /&gt;secret_access_key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&lt;br /&gt;&lt;br /&gt;Define your own queue by changing the &lt;span  id ="keyword2"&gt;config/messaging.rb&lt;/span&gt; file&lt;br /&gt;&lt;br /&gt;&lt;span id ="keyword1"&gt;s.destination :queue_name, ' queue_name&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Add the following to the controller from where you push message to the queue&lt;br /&gt;&lt;br /&gt;&lt;div id = "code_box"&gt;&lt;br /&gt;require 'activemessaging/processor'&lt;br /&gt;include ActiveMessaging::MessageSender&lt;br /&gt;publishes_to : queue_name&lt;br /&gt;&lt;br /&gt;def method_from_where_push_message_to_queue&lt;br /&gt;publish : scrumpadmailer, “put the required value to process the message"&lt;br /&gt;end&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Add the following to the &lt;span id ="keyword2"&gt;app/processors/message_processor.rb&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div id = "code_box"&gt;&lt;br /&gt;subscribes_to : queue_name&lt;br /&gt;def on_message(message)&lt;br /&gt;begin&lt;br /&gt;send mail by processing the message&lt;br /&gt;rescue&lt;br /&gt;publish : scrumpadmailer, “put the received message"&lt;br /&gt;end&lt;br /&gt;end&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;Now run the poller which monitors the queue continuously and upon receiving a message it calls the &lt;span id ="keyword2"&gt;on_message&lt;/span&gt; method of &lt;span id ="keyword2"&gt;app/processors/message_processor.rb&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Go to your application directory and run the following command&lt;br /&gt;&lt;span id ="keyword1"&gt;ruby script/poller run&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;To run the poller as a background process in linux run the following command&lt;br /&gt;&lt;span id ="keyword1"&gt;nohup ruby script/poller run &gt;&gt; mail_logger.txt &amp;amp;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Everything is done. Now when a message is pushed in the queue the on_message method&lt;br /&gt;Is triggered and mail will be sent&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-3743262459213440078?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/3743262459213440078/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=3743262459213440078' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/3743262459213440078'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/3743262459213440078'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2008/06/sending-mail-asynchronously-by-using.html' title='Sending mail asynchronously by using Amazon SQS and ActiveMessaging'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7771419712340162338.post-266530374493046422</id><published>2008-06-05T23:21:00.000-07:00</published><updated>2009-08-03T06:10:46.523-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Capistrano Deployment'/><category scheme='http://www.blogger.com/atom/ns#' term='Deploy Rails Application'/><category scheme='http://www.blogger.com/atom/ns#' term='Deployment'/><category scheme='http://www.blogger.com/atom/ns#' term='Capistrano'/><category scheme='http://www.blogger.com/atom/ns#' term='Automatic  Deployment'/><category scheme='http://www.blogger.com/atom/ns#' term='Deployment by Capistrano'/><title type='text'>Automatic Deployment of Rails Application by Capistrano</title><content type='html'>Previously we deployed our application manually in our Linux box. This was taking a lot of time and after every deploy we were facing some serious issues. Automatic deployment by &lt;a href="http://capify.org/"&gt;Capistrano&lt;/a&gt; has made deployment life easy. Here i have shared my experience about deployment by &lt;a href="http://capify.org/"&gt;Capistrano&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;span id ="keyword2"&gt;Requirements:&lt;/span&gt;&lt;br /&gt;Install Capistrano in local machine by : &lt;span id ="keyword1"&gt;gem install capistrano&lt;/span&gt;&lt;br /&gt;Install subversion command line client in local machine&lt;br /&gt;Install subversion in Linux box. I have done it by a rpm&lt;br /&gt;&lt;br /&gt;&lt;span id ="keyword2"&gt;Assumptions:&lt;/span&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;You are deploying to a single server, at least initially.&lt;/li&gt;&lt;li&gt;Your username is the same for both your subversion repository and your deployment machine.&lt;/li&gt;&lt;li&gt;Your subversion repository is accessible from both your local host, and the host that you will be deploying to&lt;/li&gt;&lt;li&gt;You have configured a public key to use for SSH access to your target host&lt;/li&gt;&lt;/ul&gt;&lt;span style="font-weight: bold; color: rgb(0, 102, 0);"&gt;&lt;p&gt;&lt;/p&gt;&lt;/span&gt;&lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;span id ="keyword2"&gt;Run Capistrano:&lt;/span&gt; &lt;p&gt;From command prompt go to your application directory then run &lt;span id ="keyword1"&gt;.capify&lt;/span&gt;.This will create a &lt;span id ="keyword1"&gt;capfile&lt;/span&gt; in the application root directory and &lt;span id ="keyword1"&gt;deploy.rb&lt;/span&gt; in config folder. &lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;span id ="keyword2"&gt;Configure deploy.rb:&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Now modify the deploy.rb file to deploy your application. Here is my deploy.rb&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;require 'mongrel_cluster/recipes‘&lt;br /&gt;&lt;br /&gt;set :application, “your application name"&lt;br /&gt;set :repository, “url of your repository"&lt;br /&gt;set :scm_username, “name"&lt;br /&gt;set :scm_password, “password"&lt;br /&gt;set :rails_env, "production --trace"&lt;br /&gt;set :deploy_to, "/var/www/rails/#{application}"&lt;br /&gt;&lt;br /&gt;#ssh configuration&lt;br /&gt;set :user, ‘user_name'&lt;br /&gt;ssh_options[:port] = 22&lt;br /&gt;ssh_options[:username] = ‘user_name‘&lt;br /&gt;ssh_options[:host_key] = 'ssh-dss'&lt;br /&gt;&lt;br /&gt;#set app, web, db role&lt;br /&gt;role :app, "www.scrumpad.com"&lt;br /&gt;role :web, "www.scrumpad.com"&lt;br /&gt;role :db, "www.scrumpad.com", :primary =&gt; true&lt;br /&gt;&lt;br /&gt;#configure for mongrel cluster&lt;br /&gt;set :mongrel_servers, 3&lt;br /&gt;set :mongrel_port, 6010&lt;br /&gt;set :mongrel_environment, 'production'&lt;br /&gt;set :mongrel_conf,"#{deploy_to}/current/config/mongrel_cluster.yml"&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span id ="keyword2"&gt;Now the time for deploying your application:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;br /&gt;&lt;/span&gt;Go to your project directory and run &lt;span id ="keyword1"&gt;cap deploy:setup&lt;/span&gt; Capistrano will now log into your server and try to set up a simple directory hierarchy. The basic layout is:&lt;br /&gt;#{deploy_to}/&lt;br /&gt;#{deploy_to}/releases&lt;br /&gt;#{deploy_to}/shared&lt;br /&gt;#{deploy_to}/shared/log&lt;br /&gt;#{deploy_to}/shared/system&lt;br /&gt;#{deploy_to}/shared/pids&lt;br /&gt;&lt;br /&gt;Every time you deploy your application, a new directory is created under the &lt;span id ="keyword1"&gt;releases&lt;/span&gt; directory, and then a symlink is created at &lt;span id ="keyword1"&gt;“#{deploy_to}/current&lt;/span&gt; that points at the newr elease. This &lt;span id ="keyword1"&gt;current&lt;/span&gt; symlink should be considered the root directory of the currently active release.&lt;br /&gt;&lt;br /&gt;run &lt;span id ="keyword1"&gt;cap -q deploy:check&lt;/span&gt; to check dependencies.&lt;br /&gt;&lt;br /&gt;&lt;span id ="keyword2"&gt;Cold deploy&lt;/span&gt;: The first time your application is not running. Things are “cold”. For this case, run &lt;span id ="keyword1"&gt;cap deploy:cold&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;span id ="keyword2"&gt;Subsequent Deploys&lt;/span&gt;: After the first deploy every time you want to deploy just&lt;br /&gt;run&lt;span id ="keyword1"&gt; cap deploy&lt;/span&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span id ="keyword2"&gt;Roll back&lt;/span&gt; your application to the previous release &lt;span id ="keyword1"&gt;cap deploy:rollback&lt;/span&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;span id ="keyword2"&gt;Problem I faced:&lt;/span&gt;&lt;br /&gt;After deploying my application on a Linux box, I faced some permission related problem to run the application. To solve this I had to put the required file in a directory and modify my &lt;span id ="keyword2"&gt;deploy.rb &lt;/span&gt;in the following way:&lt;br /&gt;&lt;br /&gt;&lt;div id = "code_box"&gt;&lt;br /&gt;after "deploy:symlink", :copy_permitted_files&lt;br /&gt;task :copy_permitted_files, :roles =&gt; :app do&lt;br /&gt;run "cp -rpf /var/www/rails/Permitted/public/* /var/www/rails/# application}/current/public/"&lt;br /&gt;run "cp -pf /var/www/rails/Permitted/database.yml /var/www/rails/#{application}/current/config/"&lt;br /&gt;run "cp -rpf /var/www/rails/Permitted/log/* /var/www/rails/#{application}/current/log/"&lt;br /&gt;end&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7771419712340162338-266530374493046422?l=zawoad.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zawoad.blogspot.com/feeds/266530374493046422/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=7771419712340162338&amp;postID=266530374493046422' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/266530374493046422'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7771419712340162338/posts/default/266530374493046422'/><link rel='alternate' type='text/html' href='http://zawoad.blogspot.com/2008/06/automatic-deployment-of-rails.html' title='Automatic Deployment of Rails Application by Capistrano'/><author><name>Shams Zawoad</name><uri>https://profiles.google.com/110755649381983417863</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='//lh3.googleusercontent.com/-VUqyHuevVUU/AAAAAAAAAAI/AAAAAAAAAAA/GwKiDHGb4VE/s512-c/photo.jpg'/></author><thr:total>1</thr:total></entry></feed>
