251 pdfsam Foundations Of Ajax (2005)

228 CHAPTER 8 ■ PUTTING IT ALL TOGETHER even escape the data for you. All you need to worry about is telling Taconite ...

1 downloads 27 Views 41KB Size
228

CHAPTER 8 ■ PUTTING IT ALL TOGETHER

even escape the data for you. All you need to worry about is telling Taconite what values should be sent to the server, and it takes care of the rest. Since all the JavaScript is created by the parser based on the HTML you specify, you don’t have to worry about dealing with browser JavaScript incompatibilities. The parser takes care of them for you. Did you catch that? Taconite takes care of the incompatibilities. Seriously, you don’t have to worry about it; we’ve done that for you. All you need to do is specify the dynamic content as HTML within a JSP, and the parser does the rest. The beauty of Taconite’s design is that it encourages you to keep all your business logic on the server side (where, frankly, it is a lot easier to write) while the browser does what it does best: it renders a user interface. Taconite trivializes the task of making Ajax requests from the browser to the server so you can reuse domain logic with ease. Of course, removing redundancy is not the only reason you should avoid business logic in the browser. Hosting domain logic on the client can open security vulnerabilities. If your logic is implemented on the browser, what’s keeping a malicious user from using a tool such as Greasemonkey to update the JavaScript and insert some special processing (say a 90-percent discount on your new widget?) Taconite makes it easy to access your business routines on the server side where it’s easiest to develop, debug, and secure. Taconite’s server-side library is lightweight, requiring only your favorite JSP/servlet container and nothing else. Configuration is minimal (no reams of XML here!); all you have to do is add Taconite’s tag library descriptor (TLD) location to the WEB-INF.xml file. Thanks to its small size and zero dependencies, Taconite plays nicely with any J2EE Web framework. Whether you use Struts, Spring, MVC, WebWork, Tapestry, or something else entirely, you can use Taconite without any extra work or a steep learning curve. Just imagine integrating Taconite with Struts: the client-side JavaScript library automates the task of creating the query string that is sent to the server. Struts automatically creates and populates an ActionForm object based on the query string’s values and passes the ActionForm to an Action class, where the “real” processing work begins. After domain logic has been processed, the Action class forwards the response to a JSP that uses Taconite’s custom JSP tags to render the content that will dynamically update the page’s contents. We’ve recently ported the parser to a JavaScript library so that developers can use it outside the Java space. To use the JavaScript-based parser, the dynamic content must be valid XML embedded in a special Taconite tag. Using this approach, the content is returned as XHTML that is parsed to JavaScript and then evaluated on the browser. Since the JavaScript is produced in a central location (the Taconite parser), we make sure it handles any known incompatibilities between browsers. We take care of these issues so you can focus on writing content in a natural way—as HTML. As new issues come up, we can update the parser without affecting any client code!

What Does Taconite Do with the Content? So, if innerHTML isn’t the answer, what are you actually doing on the client side? If you’ve looked at the W3C’s Load and Save specification, you would see things such as ACTION_APPEND_AS_CHILD and ACTION_REPLACE. Taconite supports these actions and others, giving you complete flexibility with content placement. Following the ideals of the Load and Save specification should make the transition from Taconite to the W3C specification easier. Taconite currently supports the following actions, assuming that the actions are in reference to a specified context element: