| ~>\t/<~ |
|
||
WhatWhyWhereDownloadInstallRunHowQuickstartHTMLXMLCustom TagsOverlaysAlternate SyntaxExamplesReferenceTagsviewhtmlctrltagneticconfigJavaScript LibsDSRJavadocWhenWhoSF Project Link |
Why TagnetoMotivationTagneto was developed to aid using an MVC approach for building XML user interfaces (UI). HTML UI that uses JavaScript as the controller is the main target of the framework, but parts of it can be applied to any XML user interface. The framework is based on the following principles:
Approaching UI construction this way allows for the general UI Layout files to be served statically from a web server. This in turn allows for caching of the files by proxy servers and by clients. Some care needs to be taken with versioning, but there are simple approaches that solve the issue at the expense of longer term cacheability. Since all data UI happens on the client, the state machine for the UI has to be centralized in the logic engine running on the client. This normally means a script language like JavaScript. This frees server application logic on the server to focus on data services and core business logic only. Normally UI flow and state change more frequently than the core data services and business logic, so using partitioning specified by the principles allows for a clearer, more efficient separation of work between two teams. This allows the implementation of the server data services to be done in a separate technology than the UI. It even allows the possibility to be served from a different place than the server, even locally on a client machine (although there are browser security models to consider). For rich web applications, there is better performance with this approach because:
For development, prototyping is made easier, since the data services easily can be "canned", static XML/JavaScript responses. MVC ChallengesThere are particular Model, View and Controller challenges in using the MVC framework described above for web applications, and Tagneto provides tools and support to address the challenges.ModelGetting the ModelIn the strictest conformance of the above principles, the dynamic Model data for the page (user's data, request-dependent data) is not combined with the layout HTML on the server. It happens on the client. There are a few ways to retrieve the Model with this approach:
Format of the ModelWhen the model data is retrieved from the server, it should either be encoded as XML or JavaScript. Once the browser receives the data in XML or JavaScript, the Tagneto approach favors holding the data as JavaScript structures, but XML could be used directly with an XSLT style sheet.The decision on whether to fetch XML or JavaScript encoded Model data will probably be most dependent on the server providing the API calls. Using XML could allow re-using some existing data APIs that the server exposes. It would be more performant to retrieve the data as JavaScript, since the Tagneto approach prefers that format, and a conversion will have to be done on XML data. However, that might require custom adapters on the server to convert data to the correct format. Approaches like JSON may make this easier to do. Tagneto has script libraries that convert XML to JavaScript, and convert JavaScript to an encoded type suitable for GET/POST requests. ViewView AssemblyAn application server is not required to serve the View HTML files. However, for large projects, there are many pieces of HTML/CSS/script that are reused as part of many pages. Some sort of tool is needed to build the final View HTML pages from HTML fragments. This tool should be able to run offline, as part of a "compile" step for the application.If the complete View HTML page is built up from HTML fragments, the tool should have the ability to put the code in the right places in the final HTML file (<script>, <style>, <link> tags should go in the <head> area), and the HTML fragments should be able to specify an "API" for inclusion in the final HTML file. Tagneto gives the developer a set of tags and tag handlers to do effective View assembly. It is easy for the developer to define new tags that use the built-in tag handlers. HTML SanitationUsing HTML fragments to build a larger page can lead to a final HTML file whose source is not easy to read. In addition, when the HTML is ready to be pushed to a production environment for end users, it may be desirable to strip out comments and excessive white space to cut down on size. Validating the HTML and JavaScript at "compile time" for the UI would also avoid unwanted bugs that may only surface when a user actually uses the application.Post file filters are supported in Tagneto that allow processing the final HTML pages. Right now, only a file filter that supports stripping whitespace and comments is built. HTML pretty printing and validation is on the task list. ControllerGrouping event handlersFinding all the event handlers on a page in traditional HTML/JavaScript pages is hard to do. Event handlers can be embedded directly in HTML as an element's attribute, and reference functions in an external script file. Event handlers can be added during runtime via JavaScript. The ctrl:listen tag allows a developer to group all the event handlers on a page so it is easy to edit, but allow for the flexibility of binding the event handlers as element attributes or dynamically binding in script.Using JavaScript to create HTMLUsing JavaScript to create HTML for data UI can be messy. Using DOM methods (like appendChild()) is harder to do than "just writing HTML". Using innerHTML to inject HTML requires the HTML to be properly escaped in a JavaScript string -- something that is hard to read and maintain. Tagneto's ctrl tags allow the developer to just write HTML and allow the framework to escape the HTML properly.Allowing browser caching of pages with dynamic URLsIt is normal for web pages to need dynamic information, usually in the form of GET (querystring) parameters, like "?name1=value1&name2=value2". However, asking for a page like that may not be cacheable, and the browser will unload the current page to navigate to the new URL. If these effects are not desired, Tagneto's Ctrl.js can be used to allow passing of dynamic parameters via the fragment identifier of the URL, like #name1-value1.Why Not Something Else?Tagneto was developed because of perceived shortcomings with the existing alternatives. The shortcomings may no longer exist in the alternatives (Tagneto was started in the summer of 2004), or Tagneto's author may have missed solutions or misunderstood the alternatives.The main alternatives seemed to be Java Server Pages, Active Server Pages or PHP. They all have a similar design (from the perspective of a developer using them to build UI), so they will be referred to as SP (Server Pages) for the rest of this document. All of the SP variants are valuable and useful, and Tagneto can be used with them. Tagneto's motivational principles and the author's subjective preference gives rise to some differences between Tagneto and SP:
Why Java?Java was Java used to build the View Assembly tool in Tagneto (The Java runtime is needed only by the web developer, not on the web server or on the end users computer). Java was used because that language is the most comfortable one for the author. It is also nice that it is cross-platform, and has internationalization and localization features built in. Being object-oriented makes it nice for other developers to extend Tagneto. Rhino, JavaScript engine that included E4X, was readily available for it too. |