Wednesday, February 07, 2007

Javascript: The Definitive Guide

The title does sound presumptuous but after reading it you can only agree that if there is any Javascript book worth reading, this is it. David Flanagan does a most excellent work of introducing the Javascript language and of exploring all the kinks and nice features that you can take from it.

Having known Javascript for sometime I could not avoid being wowed in some chapters by some cool features that I really did not know existed in the language.

This 5th edition is well worth it even if you read previous editions. I did have a previous version and found that this new edition brings a significant amount of new content worth spending your budget in.

The book is well structure dividing it's presentation in core javascript and client-side javascript. Something I really liked seeing.

The core Javascript section presents pretty successfully crucial aspects of the language like closures and prototyping (among many others)...Even if you already know Javascript you should give it a try...I'm almost sure you will learn something from it.

The client-side Javascript is where this book gets even more of its value... from a fantastic CSS reference chapter (I do not believe you need much more than this to get you rolling with CSS), to even handling, DOM navigation, XML handling and scripting with Java, Flash, charting with Javascript and CSS (way cool). A really interesting read.

Like I said before, if you're out to get just one (or your first) Javascript book, I believe this is it! An interesting and absolutely essential read for any web developer these days.

5 stars!

7 comments:

Marcelino said...

Is it possible to communicate between JavaScript and Java in the browser?

Francisco Assis Rosa said...

In short, yes. Like everything, there is always more than one way to do it. You can have your Javascript either communicate with Java all on the client side or communicate with Java on the server side.

On the fully client side approach, you can work with Java applets and are allowed to call methods from Javascript into the interface of the Java applet. I have to admit I have never been much of a fan of applets so I have not implemented this option yet. But the book does cover it in good details in chapter 22.

For client side Javascript to talk to server side Java, DWR (Direct Web Remoting). Now this is a pretty cool piece of code that hooks up to your classes (any POJO on your server) on the server side and exposes an automatically generated Javascript library for each visible class. Calling a Java object on the server side from Javascript becomes as easy as 1) including the automatically generated Javascript class library, 2) calling objects in Javascript using this library interface. DWR takes care of all things like marshalling/unmarshalling of types and objects, takes care of all the nitty gritty details of communication. Pretty easy and nice. Latest versions of DWR also allow you to send back from the server Javascript commands to run on the client...the full cycle.

And talking of Java/Javascript integration...do you know that you can use Javascript as scripting language in your Java code ? Java 6.0 came out with Javascript support. Pretty cool to be able to use something you already know well on the client side to script your server side. The potential that comes out of this is really promising. For details on this see article.

Ayisha said...

Nice and knowledgeable sites for everyone-
booksshelf
knowledge
books
liberary
kitaben
Books and references
books
tutorial books

sesha said...

I am new to Struts and I am struggling on what would
be the best way to do the following:

on several pages, the user can perform actions which
need to be confirmed before being actually performed
(e.g., exiting the application or confirmation page is the same regardless of the calling
point, but if the user cancels, I need to go back to
the previous page. I am not sure how to pass the return
url to the confirmation page, and how to make this
page generic (template tag, read value from session)...

would anyone have an idea?
Thanks for your help,

-Seshagiri

sesha said...

I am new to Struts and I am struggling on what would
be the best way to do the following:

on several pages, the user can perform actions which
need to be confirmed before being actually performed
(e.g., exiting the application or logging off). The
confirmation page is the same regardless of the calling
point, but if the user cancels, I need to go back to
the previous page. I am not sure how to pass the return
url to the confirmation page, and how to make this
page generic (template tag, read value from session)...

would anyone have an idea?

Thanks for your help,

-Seshagiri

Francisco Assis Rosa said...

I guess it depends a lot on what you really want to do...the following HTML snippet will do what you want and will be independent of any web framework use. It is a pure Javascript browser side solution. There are, of course, a million ways to do something like this, the code should give you one idea on how to achieve it.

What is the main points in the code:

*) I am using scriptaculous. You do not need to use it to do this code (pretty simple), but as a rule I am trying to stay away from the browser weirdnesses, scritptaculous is an excelent javascript library that gives me just that (actually I just needed prototype for this example to be fair).

*) It all works by having javascript make appear a "dialog" div using CSS styling. This dialog can obviously be styled to look a lot nicer that it looks in the example and could also have been centered on the screen. All are details of implementation that you can follow through. This dialog will have the yes no confirmation buttons, will contain the id of the form that needs to be submitted on success.

I think this is a pretty simple solution to do what you need...

Since blogger is not that nice with HTML code in comments, you can find the HTML code here

Like I said, there are a ton of different ways to do something like this, the solution outlined above will keep confirmations client-side.

Hope this helps!

Francisco Assis Rosa said...

Also, for the purposes of the example, I left javascript code in HTML and CSS styling inlined. You would probably want to put those in separate files.