Saturday, May 9, 2009

HelloWorld - Ajax, Struts

This is a simple HelloWorld example for Ajax & Struts. In this example, I have a rudimentary Ajax call to the server side Struts Action class.

JavaScript:

<SCRIPT language="javascript">
var xmlHttp;
function greet(name) {
xmlHttp = GetXmlHttpObject();
if (xmlHttp == null) {
alert("Critical Browser Error: Pls. close the browser & try again!");
return false;
}
// struts action call
var url = "sayHello.do";
url = url + "?name=" + name.value;
url = url + "&sid=" + Math.random();
xmlHttp.onreadystatechange = stateChanged;
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}

function stateChanged() {

if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200) {
var strutsResp = xmlHttp.responseText;
document.getElementById("strutsResp").innerHTML = strutsResp;
} else {
alert("Critical Browser Error: Pls. close the browser & try again!");
}
}
}

function GetXmlHttpObject() {
var xmlHttp = null;
try {
xmlHttp = new XMLHttpRequest();
} catch (e) {
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
</SCRIPT>


HTML Form:

<form><!-- onchange='greet(this);'-->
<p><LABEL for="name">Name: <input type="text" name="name"
size="10" id="name" onchange='greet(this);'/></LABEL>
<input type="button" id="ok" value="OK"/>
</p>
</form>


Struts Config:

<!--Note: the response is fully cooked - no mapping required! -->
<action-mappings>
<action path="/sayHello" type="com.aj.helloajax.actions.SayHelloAction">
</action>
</action-mappings>


Struts Action Class:

public class SayHelloAction extends Action {

public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {

String name = (String)request.getParameter("name");
response.setContentType("text/html");
PrintWriter out = response.getWriter();

out.print("<h2>Hello "+name+" !!</h2>");
out.flush();
response.flushBuffer();
//Note: the response is fully cooked - no mapping required!
return null;
}
}

Thursday, April 30, 2009

Expand Collapse - Client Side using style.visibility

This is the simplest version of implementing Expand/Collapse of table rows using Javascript.
Clicking + expands the table & - collapses the table rows to the header.




Its important to note that even the selections are preserved, between expand and collapse; clearly since only the display property is altered.
I am enclosing the bare bone version of the code here. I have used some CSS to make the tables above look presentable.
Refer http://w3schools.com/css/ for more details

<br /><script language="javascript"><br />var disp = true;<br />function toggleDisplay(){<br /> if(disp){<br />  disp = false;<br />  document.getElementById("state").innerHTML="-";<br />  document.getElementById("table").style.<br />visibility="collapse";<br /> }else{<br />  disp = true;<br />  document.getElementById("state").innerHTML="+";<br />  document.getElementById("table").style.<br />visibility="visible";<br /> }<br />}<br /></script><br /></pre><br /><pre class="brush: html; wrap-lines: true"><br /><br /><body><br /> <table cellpadding="0" cellspacing="1"><br /> <thead><br />  <tr><td><a href='javascript:toggleDisplay()'><div id="state">-</div></a></td><td>Names</td></tr><br /> </thead><br /> <tbody id="table"><br />  <tr><td><input type="checkbox" name="name1"/></td><td>Ajay1</td></tr><br />  <tr><td><input type="checkbox" name="name2"/></td><td>Ajay2</td></tr><br />  <tr><td><input type="checkbox" name="name3"/></td><td>Ajay3</td></tr><br /> </tbody><br /> </table><br />

Sunday, March 8, 2009

Definitions of Success

Gary Davis, president of Davis and Associates Inc. construction: "Career success is measuring your effectiveness against the goals and objectives you've set, and then constantly re-evaluating your skills vs. their demand and your response to the challenges before you. If this 'self-check' is done regularly and realistically, your career success will be ultimately determined by the professional legacy you leave and those who've benefited from your life's work. [r]

I find this definition the most perfect one to capture an idea of success. If it were so that success was a single goal or single achivement then it would have been much easier to attain. But sucess is not an achievement but an ability - both physical & mental. It takes a lot of perserverance to apply the skill & then improve on it.

r: I am afraid I don't have a reference for this.

Friday, February 13, 2009

Allegged Confessions of a Senator/CEO

The only thing I have to say about the current economy is .. as follows.. one Senator or CEO.. saying..

..Hmm...

I did cause this, but in America we believe in the teachings of Gordon Gekko .. "Greed is good!" Why else "Wall Street" the movie, is a recommended must see in Business Schools. I thought I was the only one with this novel idea of making a lot of money and never expected that all my colleagues had the same one.

So what if I overindulged in greed, there is nothing illegal about it. And you say its unethical, hey I chose to be a capitalist - if I don't capitalize on opportunities, somebody else would. I was only digging graves, I never expected people will jump into it. It was their greed, that caused them to desire a lifestyle they could never afford. If I just brainwashed them by constant adds as to what they are missing in their lives and provide them money to acquire it, I'm only being generous.

I am pursuing "My" American dream, if it so happens to be a public nightmare that "your" grand children may suffer, its not my problem. If it was not for all my colleagues doing the exact same thing at the same time, I would have been super rich and the rest super jealous. But now it is affecting the entire economy and all my clandestine affairs are public.

Look its even on this stupid blog!

There is a reason why a Senator may also have this burden on his conscientious.

"Behind every successful businessman there is a more successful politician. "

* As usual the IMHO disclaimer applies!

Saturday, January 17, 2009

Samurai Jack - The best imagination!

It is no surprise that I bumped into this animation. Mix Animation, swords, fantasy world & I am there. Its not to say I like all kinds of cartoons,...I am not that kind of a cartoon. I had seen Samurai Jack few times and knew that the style is quite different from most. It looks too simple to me - official terms are "highly detailed, outline-free, masking-based animation". I seem to contradict when I say simple. However, there is plenty of detail, colors, & amazingly creative imagination.

I think Samurai Jack is the best animation. It would be more appropriate to say that the creator has the best imagination I have ever seen. I am not trying to compare this simple yet brilliant animation to the likes of Final Fantasy or Ghost in the Shell, but the creativity is out of the world, metaphorically & literally. Where most of the animators (graphic artists) try to bring the animation as close to the reality, Samurai Jack goes full blast into making taking the audience into a wonderful fantasy. The variety is so enormous that it just blows my mind. How can a person have such an innocent & vivid imagination? The stories are thought provoking & each one is quite unique in characters & places.
After such an impression, I decided to find some more information about this animation & reached Wikipedia. It turns out it has won Emmy award, 4 times. And surprisingly its an American animation created by Genndy Tartakovsky & that he lived in Chicago [1].
--
[1] http://en.wikipedia.org/wiki/Genndy_Tartakovsky

Tuesday, December 30, 2008

Microsoft on "Pay as you go" model for PC & software

You can read about this article at ComputerWorld. I recently wrote a comment on this, I'm just posting it here.

Once again MS comes up with an approach of making more money without the necessary effort. How about a good performance on their OS or fewer bugs, or a weight loss program for it? They seem to work overtime on making new themes for the same OS (Vista, Windows 7) & copying everything they can find on the way - Konfabulator widgets (now Yahoo), Google gadgets & of course the Mac OS X for almost everything.

It seems their think tank only has MBAs or Accountants. They lack any kind of creativity. They have never been pioneers in any kind of software or hardware. Mouse - Xerox, Apple. OS - Apple, Zune - ipod Apple, Xbox - PS2, Xbox 360 - PS3 & now muscling their way against Wii by heavy discounts.

How can a giant a$$ company lack any kind of creativity or passion? M$ seems to have a complete wrong mentality. They are too proud to learn from anybody but shameless to copy everybody.
They just play catchup to everybody!

Tuesday, December 9, 2008

To buy or not to buy?

I have a Nikon D80 and a Nikkor 18-135mm lens. Its a pretty good setup for amateur-enthusiast photography, and yet often I find myself researching the Nikon D300 or the new D700. Sometimes even the old D200 strikes my fancy and before I realize I am drooling all over my iMac. Then there are lenses. I fancy a Nikkor 70-300 mm VR and wish I could afford a 80-200mm f2.8. I go through this torment of oggling at the camera/lenses - features, quality, the kind of photographs I could take and then the budgeting. This is just the camera.

Then there are other interests:  Sports cars (BMW M3 E92, rather an E46 for me pls., or Mercedez SL65 AMG Black-edition) or  a Media system: perhaps a custom built: recevier, subwoofer, speakers etc. Bose Companion 5* just doesn't cut it, Computers: has to be a Mac and then sometimes I want to build my own monster with Nvidia SLI twin graphics cards 512 MB RAM each, 7.1 surround sound, 1Ghz FSB Motherboard, a RAID configured HD stack 7200rpm, a Blue Ray disc player, a liquid cooled cooling system, Phones: Nokia n series, a Blacberry Storm, or the ubiquitous Apple iphone*.

Well, the intention behind this particular blog is not to rant about the poor me not affording the pleasures of driving a Mercedez Benz SL65 AMG Black edition ($150K) a V12, 600 hp & 700 lb-ft torque, not snapping pictures with the shweet D700 ($2K) full frame at 5 fps, talking on the iphone, with my ears still numb from listening to the custom built Denon+Velodyne+NHT Home Theater System ($8K), and perhaps gone blind double checking if I am getting any resolution benefits using a Blue-ray disc on 42" 1080p plasma screen ($3K).

Nor is it to offer excuses and beleiving in the fable of sour grapes. The humble intention of this blog is to dissect the human urge behind possessing these wonderful material things. Before you roll your eyes and assume this is another of the Zen arts of living boringly, let me please goad you to read on.

I wish I had all these gadgets and more. I strongly believe in being Happy, no matter what it takes. (Pls. insert here your own sense of ethics, personal integrity in acquiring the means and the uncompromisable character for avoiding excessive indulgence).

Hinduism & Buddhism tell us otherwise. Material needs and material goods can only fill this void superficially making us more empty and definitely broke (No Chapter 11, bankruptcy claims here!).

But we are only human; with dreams and desires. I just want to insist on clarity in actions and reactions. Action being the purchase & the reaction being what I get having acquired the object of my drool (yikes!). Moving on..

Camera: I like my camera, Nikon D80, and as many wise professional photographers have said its not the camera that takes the photograph its the person behind it. But I still want a D300, there is a desire to possess something this awesome (& now affordable $1450).

And I don't fight this. I just ask myself..Why?
I guess its not the camera that I want. Because, I am not thinking of the photographs that I can take with the new one. Nor the passion of photography. Having an active d-lighting and magnesium alloy body is not going to change my pictures.

What is my passion for cameras?
I want to take good pictures and the thrill of capturing light, just the way I see it, or a perspective or a vision of something not so obvious; an exaggeration of the mundane.

So, "To buy or not to buy"?

Its just the passion of photography or my need for speed, exquisite car handling, the thrill of cornering a turn on a track at 90 mph or a need for loosing sense of the surroundings & life itself into the music & the movies made by some of the most brilliant and imaginative artists of this day.

Just identify the real passion and the real outcome of what you are investing in. Possessing a material object does not grant the possessor the same pride and satisfaction of the creator and obviously not the profits of the sale.


P.S: *
I am never going to buy a Bose. They are pretty good speakers, but they create an illusion of perfect sound by offering good bass and treble and not much of the mid range frequencies. Do I care? Illusions are just fine too! But heck, they are expensive for being "Bose". So here I have some budgetary concerns along with some pride for being taken for a false ride.

I don't want to buy an Apple iphone. Why? It seems, now that it has become seemingly affordable at $200 & $79 a month AT&T 2 yr contract, everybody has it. Nope! I will not be among everybody.

Now here we have pride and ego. Too bad Apple will not make one and only one just for me. If they did I would not afford it anyway. I also have this resent in becoming an iChimp. I bought an ipod and instantly became one. It gained spiritual importance as if it defined me. I guess a lot of Apple product owners feel such a spiritual upliftment by possesing an ipod, Macbook Pro or the invisibly thin MacBook Air. As if the device projects their own personal value! Hah! Talk about low self esteem! Having said this, I own two ipods 30 GB, 60 GB 5th genration, a powerbook since '05 & the new iMac laucned in '07. I often break down in tears looking at the new all solid aluminum MacBook Pro or the devine Mac Pro with a Cinema Display. Hmm!