Tuesday, October 7, 2008

Moved blog

Hi, I moved my blog to

Monday, February 4, 2008

Google FlexLib

For everybody out there who hasnt stumbled into Google flexlib,just a note here to let you know that it has some very good components implemented.Some of the impressive ones are :
SuperTabNavigator: This one allows you to scroll through the tabs in a tab navigator,if there are too many and provides a drop down to view all the open Tabs
Scrollable Arrow Menu:This one is pretty sleak,with the typical windows style roll over to view the sub menu.
TreeGrid:This allows you to display hierarchical data like a tree,but with a datagrid as node children,Although the implementation does not take care of the fact that if u decrease the size of the first column,u can no longer see the node name
DockingToolBar:This is very good and extremely useful,it gives you a tool bar that you can move around the Application.
HAccordian:This is just an Accordian but horizontal,can be very useful
Here is the link to a description of these components with documentation:
http://code.google.com/p/flexlib/wiki/ComponentList

Apache Versus Tomcat

This is a pretty popular question judging from the results on google,so I just wanted to consolidate whatever information I found on the web,which helped me decide.

  • Apache Http Server comes with other features like Modules configuration, SSL, SSO capabilities etc .
  • If you use Apache Tomcat,you are restricted to serving jsp's and servlet's.
  • Clustering: By using Apache as a front end you can let Apache act as a front door to your content to multiple Tomcat instances.so handling the failure of one Tomcat is easier.But you could always use Tomcats Clustering capabilities and a hardware load balancer.Apart from loadbalancing.
  • Clustering/Security: You can also use Apache as a front door to different Tomcats for different URL namespaces (/app1/, /app2/, /app3/, or virtual hosts). The Tomcats can then be each in a protected area and from a security point of view, you only need to worry about the Apache server. Essentially, Apache becomes a smart proxy server. 2/ (i.e. the capability of reverse proxying, allowing you to 'plug in' one or more web applications running on one or more Tomcat instances in one URL space.)
  • Security. This topic can sway one either way. Java has the security manager while Apache has a larger mindshare and more tricks with respect to security. But also keep in mind, if you run Apache with Tomcat - you have two systems to defend, not one.
  • Add-ons. Adding on CGI, perl, PHP is very natural to Apache. Its slower and more of a kludge for Tomcat. Apache also has hundreds of modules that can be plugged in at will.
  • With Apache in front of Tomcat, you can perform any number of decorators that Tomcat doesn't support or doesn't have the immediate code support.
  • Speed. Apache is faster at serving static content than Tomcat. But unless you have a high traffic site, this point is useless. But in some scenarios, tomcat can be faster than apache. So benchmark YOUR site. Socket handling/system stability. Apache has better socket handling with respect to error conditions than Tomcat. The main reason is Tomcat must perform all its socket handling via the JVM which needs to be cross platform. The problem is socket optimization is a platform specific ordeal. Most of the time the java code is fine, but when you are also bombarded with dropped connections, invalid packets, invalid requests from invalid IP's, Apache does a better job at dropping these error conditions than JVM based program. (YMMV)

WebServers And Containers Basics

Apache Webserver versus Apache Tomcat is a popular question,and being on the brink of choosing between the two,I started googling,but before I blog what i found,I just wanted to go over the bare basics of webservers,containers and HTTP.For the experienced ones,skip this and go directly to the differences :Apache Versus Tomcat
HTTP
Hypertext Transfer Protocol (HTTP) is a communications protocol used to transfer information on the web. HTTP is a request/response protocol between a client and a server. The client i.e. a web browser or some other end-user tool makes an HTTP request(called the User Agent)(http://www.google.com/ .The responding server which stores or creates resources such as HTML files and images—is called the origin server understands this request and returns the html content specified by the URL. There can be proxies, gateways and tunnels in between the client and the server, but ultimately the server receives and understands the request and sends the requested resources to the client.The server can return pure HTML content/HTML content with scripts embedded within which are understood by the client's web browser and executed on the client appropriately/files.
Typically, an HTTP client initiates a request by establishing a Transmission Control Protocol (TCP) connection to a particular port .An HTTP server listening on that port waits for the client to send a request message.
Upon receiving the request, the server sends back a status line, such as "HTTP/1.1 200 OK", and a message of its own, the body of which is perhaps the requested file, an error message, or some other information.
Resources to be accessed by HTTP are identified using Uniform Resource Identifiers (URIs) or Uniform Resource Locators (URL).
Web Server
A webserver is a piece of software that understands these HTTP requests,and is able to locate the resource that was requested,or atleast some component that will handle the request and return the resource.This is the basic functionality provided by any webserver.But on top of this,the webserver can also provide some services like: Authentication,handling static content and dynamic content(CGI,JSP,PHP,ASP e.t.c),HTTPS support(SSL or TLS) to allow secure encrypted connections to the server on the port 443 instead of 80,Content Compression,Virtual Hosting(Serve many websites using one IP address),Large File Support,Bandwidth throttling.

A basic HTTP webserver only understands HTTP,If we are programming in JSP's and servlets,we need something that understands Servlets and JSP's,the job of a Servlet Container is just that.Consider Apache HTTP Server and Apache Tomcat.The Apache HTTP Server like the name suggests acts as a webserver,Apache Tomcat acts as a webserver and can also understands servlets(A servlet container).So in order to use the Apache Webserver and let it serve jsp's and servlet's we can plug the Apache Tomcat Container into the Apache HTTP Server.My next blog entry throws some light on the choice between using just the Apache Tomcat(which is a web server and a servlet container) and using the Apache Webserver with the Apache Tomcat.Please check back in a while and reply with any comments or questions.

Wednesday, January 30, 2008

Flex Editable DataGrid With A Fairly Intelligent ItemEditor

I was faced with the task of creating a datagrid which was editable.The column that was editable could take in only numbers,the user should be able to enter a number of a maximum precision of 8,and I should be able to restrict the user from entering a - in the middle of the number.
I moved in small baby steps,but finally have this working.Here's what I did:

Once you make a column editable,flex by default uses the TextInput control as the itemeditor,when you try to edit a cell.So the first thing I did was to tell the DataGrid to call my custom method "editingEnded" on the "itemEditEnd" event.In this method,I do a bunch of checking on what the user entered.If I think something is wrong,I call event.preventDefault() which basically reverts the changes.This seems okay,but the user will know the errors once he comes out of the edit box,this is sort of like asking the user to fill up a huge form,and then validate on submit and present an empty form to the user.
Instead I extend TextInput and create a NumberInput component and use this as the ItemEditor for my DataGrid column,using the property: itemEditor="Common.NumberInput".In the constructor,I add an event listener to listen to an even called TextEvent.TEXT_INPUT.
addEventListener(TextEvent.TEXT_INPUT,onTextInput);
This event is raised whenever a user enters any character. So this makes my job easy,I only check if that character is valid,if not I call event.preventDefault() which basically results in nothing being shown in the editor.I make use of regular expressions to do this:
var re:RegExp =new RegExp("[^0-9,.-]", "i");
var illegalCharacterFound:Boolean = re.test(event.text);
The regular expressions support in Flex is pretty neat,check out more on this at
Flex RegExp LiveDocs

I can do much more in this method onTextInput.Here is the method for you to use.There might be better ways to do this,but this works.I've put in some pretty long comments for you to understand what is happening.

public function onTextInput(event:TextEvent)
{
var re:RegExp =new RegExp("[^0-9,.-]", "i");
var illegalCharacterFound:Boolean = re.test(event.text);
if (illegalCharacterFound)
event.preventDefault();
//I did not have this piece of code initially,so after the user enters 8.12345678,suppose he selects 567 and then types 3 i.e he is trying to change 8.12345678 to 8.1234378,this was not accepted by my code,so the check below handles this
if(this.selectionEndIndex-this.selectionBeginIndex>0)
return;
else
{
var dot:int=this.text.indexOf(".");
//If a decimal already exists,and the user is trying to enter a decimal point again
if(dot!=-1 && event.text==".")
{
event.preventDefault();
return;
}
var dec:String;
if(dot==-1 dot==(this.text.length-1))
dec="";
else
dec=this.text.substring(dot+1,this.text.length-1);
if(dec.length>=8)//Since I want the user to enter a maximum of 8 decimals
event.preventDefault();
}
}
Hope this helps some of you around,as always please correct me or let me know of your comments.

Flex ProgressBar versus CursorManager

I have been using the CursorManager.setBusyCursor() and CursorManager.removeBusyCursor() methods recently,to indicate to the user that the data is being retrieved from the server and when the retrieval/processing is done.This worked out fine for me,until I had two tabs in the application.Once the FlexApplication is initialized,both these tabs get initialized,i.e both of them start retrieving data from the Server.Now since we have only one cursor,I noticed that the cursor on the first tab changed from busy to normal,before I saw the data,this was due to the fact that the second tab had received the data already and changed the cursor from busy to normal.I then decided to use the ProgressBar component.The behaviour you would most likely need will be achieved by hiding/showing the progress bar.Here are some things to note while using it :

The ProgressBar has a property called: Indeterminate.If this is set to false,a user will see a percentage "Loading 5%...",else it will only show "Loading".My Flex UI contacts a remote server and gets data using OpenAMF,so there is no way of me to know how much percent of the work has completed.So I set this to true.Now if you get a glimpse of this ProgressBar,you will notice,that there is some animation running continiously,and even if you hide this,some CPU processing power is still being used.So I recemmend setting the intedeterminate to false,when you hide it and set it to true just before you show it.

If you want the ProgressBar to be centered on its container,use the verticalGap and horizontalGap properties and set both of them to 0.

Im not an expert at this,so please correct me if I'm wrong,or feel free to post your comments or suggestions.