JSP Taglib Release: JSP 2D Taglib
I’m proud to announce the release of a little project I recently started…
The JSP 2D Taglib.
The idea for this taglib came to me a while back when I was trying to learn how to embed Rhino in a Java app. If you’re not familiar with Rhino, it’s the Mozilla Foundation’s JavaScript interpreter implemented in pure Java. Rhino has a lot of cool features that extend beyond providing just a basic JavaScript runtime… It offers full access to the Java APIs and libraries in JavaScript, compilation of JavaScript to Java bytecodes, and you can also embed the interpreter in your applications.
That last item is what I’ve done with my new JSP Taglib (check out my other JSP Taglib hotness).
Lots of developers are familiar with the <canvas> tag that Apple invented as an HTML extension a few months back as a part of their Dashboard effort. What apple did was to expose some of the Cocoa Objective-C graphics APIs to JavaScript within an HTML tag named canvas. With this, you could use scripts to draw graphics primitives like circles, arcs, polygons, color gradients and various image effects.
Apparently, the Mozilla guys thought this was a good idea and decided to play along. Firefox 1.1 will include full support for the <canvas> tag.
Anyhow, when Mac OS X Tiger arrived, I took a look at the <canvas> tag docs, and noticed the differences in the Cocoa graphics API that was exposed via the canvas tag vs. the Java 2D API. I was immediately a little annoyed. Great, now I have to learn a new graphics API to use this thing. This really isn’t a valid complaint, as the basics of the API are not hard to pick up, but still… you only have so many brain cells, right?
So that little annoyance quickly spawned a new idea… what about a JSP or JSF taglib that could expose the Java 2D API to JavaScript a la the <canvas> tag? And what if this taglib worked in every browser, including IE? With an open-source JavaScript interpreter (Rhino) available, it should be fairly straight-forward to embed the interpreter in a JSP Taglib, drop a java.awt.Graphics2D object into the JavaScript runtime as a global variable, execute the tag’s JavaScript code body as methods of the graphics object, and then write the resulting image out to the web app’s root directory where it can be accessed from a normal HTML <img> tag!
So, thats what I did. Check it out.
Basically, this taglib allows you to “paint” directly on any web page using JavaScript and the Java 2D API. Sweet!
But wait, there’s more! Just like any JSP or JSP EL expression, the 2D Taglib has access to implicit read-only JavaScript Object represenations of the applicationScope, sessionScope, requestScope, pageScope, request parameters and more! This is where the true power of the 2D Taglib becomes evident…
Imagine for a moment that you work for a web hosting company that has developed a web app to edit your client’s server configurations… Objects representing those servers are stored throughout the life of the application in each of the scopes mentioned above. At runtime, using the 2D Taglib, your application could access the server objects in a given scope and render dynamic graphical representations of a given client’s hardware configuration. Look ma, no Photoshop!
About this entry
You’re currently reading “JSP Taglib Release: JSP 2D Taglib,” an entry on Todd Ditchendorf’s Blog.
- Published:
- 07.10.05 / 9pm
- Category:
- Java, JavaScript/DHTML, JavaServer Faces, Rhino
1 Comment
Jump to comment form | comments rss [?] | trackback uri [?]