Aptana Jaxer, the open-source Ajax server that embeds the Mozilla browser engine server-side, is nearing its first release. There's been lots of work on Jaxer with significant community feedback and ideas coming from the Jaxer betas over the summer. This latest (and probably last before 1.0) release candidate packs in some great performance enhancements like native JSON as well as a brand new built-in capability for easily dispatching RESTful and RPC service requests. And like before we're looking for feedback before we finalize and ship 1.0. So please grab a copy of the latest...
If you've not yet tried Jaxer, now is a great time. Aptana Studio provides extensive integrated tooling and samples for Jaxer, and Aptana Cloud now lets you deploy instantly to Jaxer servers running on elastic cloud computing infrastructure. Of course you can also download Jaxer and put it on your server for free too. It's free and open source.
If you are already using Jaxer, you'll love all the enhancements.
Here a synopsis of all the new features and improvements that have gone into this latest release candidate:
More specifics on these below...
Sandbox enhancements
The Dojo 1.2 plugin for Aptana Studio provides code completion; code assist for Dojo Core, Dijit, and DojoX; sample code; project wizards; and more to support your Dojo development efforts.
To get the Dojo 1.2 plugin for Aptana Studio:


As of today you can download or update to the latest release candidates of Aptana Studio, Jaxer and Cloud. These are major releases for our company: we're updating Studio to a new version, we're releasing an incredible new service, Aptana Cloud, and we've reached our 1.0 milestone of one of the world's most unique offerings, the first Ajax Server, Aptana Jaxer.
Cloud 1.0 RC makes web app deployment and management almost too easy!
Aptana Cloud is a new service from Aptana that is completely integrated into Aptana Studio enabling you to more easily develop, deploy, and manage your web applications. With PHP, Apache, MySQL and Jaxer servers already running on top of an elastic computing infrastructure, Aptana Cloud is the fastest way to deploy and scale your sites and apps. Even before you go live, Cloud's hosted SVN, SFTP and staging servers combined with the remote file editing, database management, and Cloud configuration tools make site development and management a breeze.
You can see all the features or watch this screencast to check out just how seamless Aptana has made deploying and scaling your apps in the "Cloud".
We wanted to push out a RC (Release Candidate) version prior to final release so that you could give it a try. It's absolutely free right now, so we'd love for you to try it out. Let us know what you think. Let us know if we missed anything or if you'd like to see something done differently. You can get started by downloading Aptana Studio 1.2 RC (which comes bundled with Jaxer 1.0 RC as well as our Cloud RC support), or if you are an existing Studio user, follow these update instructions.
Studio 1.2 RC adds new capabilities and improves upon many core features.
Enhancements include: Updated smart synchronization utility and a brand new set of visual database tools plus numerous bug fixes and UI enhancements with performance improvements throughout. A new Aptana ID system provides single-sign for the bug database (ASAP), Aptana Cloud, and soon the discussion forums and more. And there's a new 'My Aptana' start page with quick links to your recent files and core features.
Jaxer 1.0 RC adds and refines more features for server-side JavaScript and Ajax.
Since Jaxer is the world's first Ajax server, this release candidate is a huge milestone. This next-to-final release of Jaxer has some great performance improvements that make it comparable to Ruby on Rails and PHP, plus includes new APIs for JSON and REST style data services.
If you are not yet familiar, Jaxer lets you use your JavaScript and Ajax skills server-side to create entire apps, or optimized presentation tiers that can complement other back-ends. Aptana Studio 1.2 RC includes the Jaxer 1.0 RC.
As we get ready to release Jaxer 1.0, we put together a few simple benchmarks
to see how it performs
relative to a couple of other web platforms: PHP and Rails.
We wanted to answer a simple question: how does Jaxer, with its server-side DOM and JavaScript, perform relative to these other popular alternatives?
This was not designed to be an all-encompassing shoot-out, or a detailed study of everything you might want to do in a web app. Instead, we took a few common tasks — making database requests, using JSON, etc. — and implemented them as you might expect in the three platforms. We made enough DB requests and JSON calls and so on to give us a reasonable number of milliseconds to measure. But we also wanted to make the repetitions representative of what you might find on somewhat intensive real-world page, so we're not making a million DB requests, just a hundred, for instance. And we included one benchmark of serving an almost-static page: the "almost" was to make sure we were measuring the time the platform took to really read through the page, in case it had dynamic content in it. (Otherwise, if the page were truly static, you could always arrange for the web server to serve it without involving the platform.)
The first chart shows how long each platform took to perform the task. For the "static" page, we measured the total time taken to serve the request, as measured by the external web client making the request (over the local network). For the other benchmarks, we measured the time taken to perform the
specific task itself, excluding the overhead of setting up and tearing down the benchmark,
serving the test page, etc. That allowed us to combine these tests and assess what an entire page would take to serve, if it had static content and database requests and some JSON manipulation and so on. Of course your mileage may vary: your app may have less DB requests, more JSON, less IO, whatever. But remember the question we're trying to answer: how does Jaxer perform relative to other accepted platforms for several common tasks? We believe these benchmarks answer that: Jaxer performance is very much comparable to PHP and Rails.
Of course, significant boosts to JavaScript performance are around the corner for Firefox (see Brendan's TraceMonkey article). Since Jaxer is built on the same engine as Firefox, those same improvements will soon be in Jaxer too... With the imminent and massive improvements to JavaScript performance coming to the Mozilla engine.
Now let's take a closer look at these tests below. All were run multiple times on a Macbook Pro (2.5 GHz Intel Core 2 Duo) with 4 GB of RAM.
We grabbed a copy of one of our blog pages (Aptana Acquires Pydev) and saved it locally. We turned it into a .php file with a smidgen of PHP in it; we threw in a short <script runat="server">...<script> for Jaxer; and created a simple view out of it for Rails. Jaxer was the slowest to serve this page, and not surprisingly: it needs to parse and create the entire DOM of the page to allow server-side manipulation. Still, under 20 ms is pretty good, and is usually dwarfed by weightier tasks such as DB queries.
To measure raw iteration speed we created some very simple loops with and without a bit of variable manipulation. This time Jaxer was far faster than PHP or Rails: at least for simple, common for loops, Mozilla's SpiderMonkey JavaScript engine is no slouch.
| PHP | Jaxer | Rails |
Using JavaScript literals as a serialization format predates Ajax, and has become an incredibly prevalent cross-platform data format. We created a simple JSON structure and a more complex one, and measured a variety of encoding and decoding tasks. All three platforms now have native JSON support, so all three performed very well in this benchmark.
To measure typical file I/O performance, we created a 1 KB string and wrote it to a file, then appended a 100 KB string, and read the whole thing back, and repeated it a few times. Jaxer came out somewhat slower than the other platforms: some of this may be due to the extra conversions between JavaScript's native utf8 encoding and the filesystem, but we'll need to go back and dig deeper.
To measure database performance, we tried to level the playing field as much as possible by coding straight SQL statements. We also emphasized SELECTs over DML queries because most apps read much more than they write. Jaxer came out somewhere between PHP and Rails, with half its time spent wrapping the raw MySQL data in easier-to-manipulate JavaScript structures. Of course in real-world apps you're likely to use prepared statements, and very often (esp. in Rails, and soon in Jaxer too) an Object-Relational Mapping such as ActiveRecord to abstract out the SQL calls.
Finally, we included some page scraping tests. Many web apps mash up other content, repurpose it, or extract data from remote sources. In our case we read in the same blog page as in the static example, and navigated it in a variety of ways. PHP was fastest here, with Jaxer slightly behind and Rails a distant third. Looking for a moment beyond performance, Jaxer is the only platform that would allow scraping of true Ajax web pages, for example pages that created their content "client-side" via Ajax calls.
You can download the complete source we used to generate and display these results, and try them yourself. The README file should have the instructions you need. You can grab Apache+Jaxer from the Aptana download site, Apache+PHP+MySQL from several places such as XAMPP, and Ruby and Rails from RubyOnRails.org (if it isn't already on your platform — you'll need Rails 2.1.0, the json Ruby gem, and to run the tests in production mode).
If you'd like to discuss these, I've started a forum thread for this.
The latest update to jQuery, version 1.2.6, includes faster event handling, faster CSS selectors, an overhaul of attr(), improvements to toggle(), support for all the Dimensions plugin methods (the plugin is now part of the core code), and more... and now it's available in Aptana Studio as well!
If your copy of Studio is set to automatically check for updates, you'll be prompted to install the jQuery 1.2.6 plugin with the next check. If you check manually, follow the steps below to get the updated library files, code assist, and local, searchable documentation that come with the jQuery 1.2.6 plugin:
We're happy to announce that we've updated our support for the Ext JS library to the latest version, 2.2. Ext JS 2.2 contains numerous bug fixes and feature enhancements, including full Firefox 3 support, improved checkbox and radio groups, a history component, and a GMapPanel extension that packages Google Maps functionality into an Ext component. It's also fully backwards-compatible, so you should be able to move to this version from 2.0 without difficulty (though you can also install 2.2 into Studio alongside 2.0 if you want).
The Ext JS 2.2 plugin for Aptana Studio provides code completion, code assist, Ext JS 2.2 examples, project wizards and more atop solid javascript coding and Ajax debugging utilities so that you can be as productive as possible with Ext JS.
To get the Ext JS 2.2 plugin for Aptana Studio:


We are very excited to announce that Pydev, the popular Python and Jython IDE, is now part of the Aptana product family and that Pydev creator, Fabio Zadronzy, will head up continued efforts to advance Pydev as part of the Aptana team. Like our products for Ruby on Rails, Ajax, and PHP, Pydev offers code completion, refactoring, code analysis, debugging support, and lots lots more. Pydev's popularity in the Python community and Eclipse ecosystem made it the clear choice for Aptana. The acquisition sets the stage for a full Python suite of products and services ranging from local development to cloud deployment.
Interest in Python has been steadily growing and earlier this year got a big boost when Google announced that Python was the language for Google App Engine.
Dion Almaer, Open Web Advocate for Google recently commented "This has been a great year for the Python developer community with the advent of great frameworks such as Django and deployment solutions such as Google App Engine. Now the tooling is getting better all the time. One of the great tools is Pydev, especially if you are Eclipse-minded. Having Aptana take on Pydev only means progress for that project and Python developers."
Google is also a worldwide licensee of the commercial version of Pydev, Pydev Extensions, which includes even more high-productivity features for Python developers.
Today you can use the products side by side, installing Pydev into Aptana Studio, or plugging both into Eclipse. The combination gives Python developers access to all of Aptana's great tooling for Ajax and current Aptana Studio users access to one of the best Python IDEs out there, and the ease of using both together should increase as we integrate the products more closely over the coming months.
You can learn more about Pydev and Aptana's support for Python at http://www.aptana.com/python, or just go straight to the Pydev and Pydev Extensions sites for downloads and more details.
Please start submitting your ideas for future feature enhancements and how you'd like to see these products come together.
Mozilla CTO Brendan Eich, the creator of JavaScript, in this article by Ryan Paul of Ars Technica, discusses how Mozilla is "'getting ready to take JavaScript performance into the next tier' with a radically innovative optimization tactic called tracing that has already produced performance improvements ranging between 20 and 40 times faster in some cases."
The Mozilla JavaScript engine (SpiderMonkey) is what's inside the Firefox browser and the Aptana Jaxer, Ajax server.
"Eich says that Mozilla wants to 'get people thinking about JavaScript as a more general-purpose language' and show them that 'it really is a platform for writing full applications.'"
Tom Kirkpatrick of codegobbler.com has told us he's writing a series of articles on some of the great features in Aptana Jaxer. His most recent article is on the new Jaxer.Process APIs that lets Jaxer interact with the operating system on the server to achieve all kinds of things. (Yes you heard right. That's JavaScript interacting with the operating system).
Tom's simple example, complete with full source calls usr/bin/uptime to get the uptime, then display it in the webpage. There's a full working demo to if you want to see the uptime of codegobbler.com's server too.

Good work Tom! We look forward to more great stuff from codegobbler.com
Mark Perkins, a Senior Web Developer at VGroup has summarized in this blog post the ubuiquity of JavaScript on the Web and how this dynamic language is empowering all kinds of new possibilities in applications. From ECMAScript to ActionScript, Flash to W3C, Google and Yahoo Maps, Apple's Mobile Me, Aptana Jaxer, Rhino, Firefox, Apple Gadgets, Google Gadgets, Yahoo Gadgets, and even Vista Gadgets, and Adobe AIR, (and more), Mark highlights how JavaScript is at the core of the future of the Web not just online, but on the desktop and on mobile devices as well.
Only thing I'd add to Mark's comments is that JavaScript is set to get even faster than the already blazing improvements delivered by Mozilla Firefox and the Webkit engine that powers iPhones and Sarafi. Projects like Tamarin and its convergence with Mozilla's SpiderMonkey (which Aptana Jaxer, the open source Ajax server uses) are slated to provide the equivalent of Just-In-Time (JIT) compliation of JavaScript and open even greater possibilities for greater JavaScript use.
Jaxer 1.0 is packed full of new, exciting stuff and we are proud to announce Jaxer 1.0 Release Candidate B. This is our first pre-release of Jaxer 1.0 to the general public and we are looking forward to more feedback from the Ajax community. Jaxer 1.0 RC B has more features and capabilities than the prior Jaxer betas, and we're calling this a release candidate because the APIs are now pretty much set for what we'll have in the final 1.0 release. So it's a great time to get started with Jaxer 1.0. Aptana Cloud users and nightly build users are still on Jaxer RC A until updates for those are released (soon).
Jaxer 1.0 RC B is available both within Aptana Studio 1.2 (also just released) and as a standalone server. All are open source. The Studio download is suggested if you are new to Jaxer since Studio includes many helpful features to getting started with Jaxer including a fresh batch of Jaxer 1.0 samples.
Download Aptana Studio with Jaxer 1.0 RC B — or — Download Jaxer 1.0 RC B server.
This release contains many new and enhanced features including:
I'm really excited about the ability to return custom content types (json, gif, xml, html, etc...), particularly the JSON type since the server-side is natively JavaScript. What could be easier — especially with the enhanced serialization support for JSON. And with the E4X (native XML for JavaScript) capabilities in Jaxer, returning XML types is now a piece of cake too. This means that you can now easily use Jaxer as a JSON or XML service provider not just to Ajax clients, but also to things like Adobe Flash, Adobe Flex and Microsoft Silverlight which can consume JSON or XML and support JavaScript and XML on the client as well, a technique useful in mashups and all types of social and mobile apps.
The new secure sandbox lets you load, on the server, pages from other domains and allow their JavaScript to execute without giving them access to the Jaxer API or your own server-side code, but still giving your code access to their window objects and anything inside them. While you can't see these windows (they're on the server) you can use them programmatically whether you're consuming web pages in mashups or generating them to be sent to the browser. Uri Sarid's blog has a nice example using these to do "DOM Scraping" where you actually can execute the JS functions of the page you're consuming on the server, access its DOM and get what you need for your mashup or app. Since Ajax is so prevalent today in web pages, being able to trigger the Ajax events server-side such that the content added via the Ajax calls is available in a server-side DOM is very handy in this case and could be applied for things like search engine optimization and accessible modes for web apps as well.
Get all the details of what's new and what's improved in the Migrating Jaxer Beta to Jaxer 1.0 doc.
Jaxer 1.0 docs are in process, links to which can be found at the Jaxer Developer Center.
We'd love your feedback on this release and your thoughts on where Jaxer should go next via the Jaxer forums.
We're finalizing our Jaxer 1.0 release, and I thought I'd go back to Paul's 'DOM Scraping' example and see what Jaxer 1.0 has to offer.
A main new feature is Jaxer.Sandbox, which lets you open new server-side sandboxed 'windows' and load pages into them. You can GET a page from any url, or even POST some content and load back the response. You can control whether JavaScript is executed in the window, whether it honors meta refreshes, whether it loads synchronously or asynchronously, etc. And, most important, the window and its contents have no access to Jaxer and its APIs nor to your app — but your app has full access to it.
There's a lot of other new goodness in Jaxer 1.0, as well as the official released version of the Mozilla engine found in Firefox 3. So for example getElementsByClassName is natively implemented (see John Resig's speed comparison), in addition to the other Mozilla features such as built-in XPath functionality and a very robust DOM feature set — just what you need for some serious 'screen scraping', mashups, and content repurposing.
Let's see it in action. First, let's grab the same three pages Paul used and extract some choice content elements into our page before sending it to the browser. We'll reuse the same Jaxer.Sandbox instance three times, each time loading a different page into it and grabbing some content by id or by classname. The page is basically a single script block: containing the following server-side JavaScript: and a single helper function that adds the given contents from the sandbox to the current page:
Here's the resulting page:

That's not too bad, but the timestamps on the News.com section don't look good, and there are a bunch of JavaScript errors on the browser from left-over JavaScript content that was in the original WashingtonPost.com page. We can quickly clean that up with another, tiny DOM helper function that removes any DOM NodeList you pass to it. And while we're at it we'll also remove the reference to the client-side Jaxer framework since we won't be needing it here. The script block becomes:
Now that's much better:

But if you run this example yourself, you'll see it's slow: each of the original servers is a bit slow to load its entire page, and you have to load all three server-side before your page is ready to be sent to the browser. We could load all three in parallel, using the Jaxer.Sandbox's async capabilities and the Jaxer.Thread.waitFor() method to wait for them to load. But even then the user would see nothing in the browser until the slowest one was done loading server-side. So let's load them asynchronously client-side, by creating a server-side function called getFragment that loads a url and returns some of its contents, and setting getFragment.proxy = true so we can call it asynchronously from the client. The page now has two script blocks, one that runs on the browser and one on the server: The client-side code is: and the server-side code is: The result looks the same as the previous screenshot, but the order in which the sections are displayed may vary, depending on which remote server responds first.
We are pleased to announce that Greg Murray (creator of the jMaki Ajax framework, former Ajax architect for Sun Microsystems, Sun NetBeans IDE team member and lead on the Java Servlet 2.5 specification) and Ryan Johnson (creator of the livepipe and object.event Ajax libraries) have joined the Aptana Jaxer team!
Greg's primary role will be creating increasingly robust application frameworks for Jaxer, Aptana's open source Ajax server product. Ryan has already been working on MVC concepts for Jaxer and will be collaborating with Greg and the rest of the Jaxer team to drive that and other great concepts for Jaxer forward.
The timing could not be better. Greg and Ryan have joined up just before we get the Jaxer 1.0 release candidate out the door to the whole community (it's just a matter of days now). This puts us in a great position to start working on some of the next things that'll be in store for Jaxer in the coming months -- and there are some great ideas brewing. For example, Greg and Ryan have already been collaborating with the Jaxer team to create an ActiveRecord-like JavaScript ORM for Jaxer that promises to make working with JavaScript data a pleasure -- since it'll all be native JavaScript! Dion Almaer and others in the community have been championing this idea as well. Now we're doing it! Of course Greg and Ryan are both deeply involved in the Ajax community in their own ways as well: Greg with the jMaki project and Ryan with Dynamic Reach and his active role in the Prototype community. So be on the lookout for blog posts from Greg and Ryan to keep abreast of all the stuff they'll be up to here at Aptana.
This beta is for two groups: People who want to try Jaxer RC 1.0, and, People using Eclipse 3.4 who want to test updated Studio compatibility.
Existing Studio users:
Use policy file http://beta.aptana.com/php/3.2/policy.xml, then perform a normal update.
Eclipse 3.4 users:
Follow the instructions at Plugging Aptana into an existing Eclipse configuration and use http://beta.aptana.com/php/studio/3.2/ as the update site.
New in Studio
(For more complete list, see Migrating from Jaxer beta.)
I quickly launched my VMWare Fusion into Vista, gulp, and proceeded to run Microsoft's Visual Studio 2008. This posting won't be a tutorial on how to write C#, but i'll just go over some of the basics of setting up a simple C#-based COM object that can be used from within Jaxer.
The first thing to note is that to register COM objects in Vista, you need to be Administrator, so just launch Visual Studio as Administrator using the right-click menu 'Run as Administrator'. Once you have Visual Studio running, start by creating a new 'Class Library' project.
Once you've created the project, right-click on the project and go to the Properties menu, we'll want to make this object a COM-visible one.
In the 'Build' section of the properties, scroll to the bottom and check the 'Register for COM Interop' checkbox. This will make your object visible to other languages as a COM object.
The next thing you'll need to do is open your 'AssemblyInfo.cs' file, which is usually in your Properties folder of your project. Be sure to change the 'false' value to 'true' for the 'ComVisible' setting:
Now that you've done that, you can just create a COM object the 'usual' way. The complete project is attached, so you can take a look there. The image processing code was borrowed from the following online tutorial: http://blog.paranoidferret.com/index.php/2007/06/13/csharp-tutorial-image-editing-rotate/
Once you've got your object compiled, using it from within Jaxer is super-easy! You can just use the COMObject function to create a wrapped instance of the native object and then just use functions and properties on it just as if it were native JavaScript.
So here is the very short HTML file and JavaScript code running server-side via Jaxer that creates the COM object, loads our image, rotates it via the input field in the HTML form, and then saves it back as a new image. The communications from JS to .NET happens very quickly and as you can see, was super-simple to set up.
Here's a screenshot of the image being rotated:
What's really cool is that you can write anything you like in C#/VB.NET and easily access it via JavaScript in Jaxer. Note how in my sample, the onclick event for the button calls the server-side JavaScript function directly, which in turn calls the .NET COM object. That is, you can bind browser-side buttons directly to back-end .NET COM objects, all in JavaScript through Jaxer!
| Attachment | Size |
|---|---|
| MyCOMObject.zip | 15.16 KB |
There are some interesting threads going on in the Aptana Forums about using Aptana Studio with Adobe Flex and Flex Builder. The idea of using Ajax and Flex or Flash together is not new. Google Finance did a great job a few years ago blending the two to provide a very nice user experience with Flash-based interactive charts within an otherwise Ajax UI.
It seems that the Aptana community is uncovering increasing efficiencies in using Aptana Studio and Adobe's Flex Builder together. We've also known that many Adobe AIR users are building their Ajax apps for AIR using Aptana Studio, and have heard from others that using Aptana Jaxer to create JSON data services (written natively in JavaScript) consumable by Flash and Flex apps makes a lot of sense as well. Flash and Flex each have an "Ajax bridge" to expose JavaScript APIs for the embedded objects.
Anyways... It seems Adobe is now actively taking a deeper look at this trend in the hybridization of Ajax and Flash and Flex. I saw that they are offering $75 bucks for an hour phone call to discuss your experience with and thoughts on using these together.
Here's the link if you're interested: http://www.adobe.com/go/RIAintegration_study/. $75 bucks... That's almost the cost of a tank of gas in San Francisco.
We're continuing that philosophy now with our Aptana Cloud offering (currently in beta) as well as our support for Ruby on Rails, PHP and LAMP development, and of course app development with Ajax libraries on the client side and for those that want server-side Ajax, Aptana Jaxer, a first-of its kind open source Ajax server built around the Mozilla browser engine.
"We can see that Jaxer lets developers leverage the hard work which has already been spent building client-side libraries on the server-side. These simple examples show off some of the true potential of utilizing the Ext JS framework on the server-side" says Rich.
The easy to follow example shows off a very simple wrapper around an Ext.data.Store and the corresponding Jaxer server code that returns JSON to a Ext JS datagrid.
A comprehensive guide to using RadRails to develop your Ruby on Rails projects in a professional and productive manner
Aptana RadRails is an Integrated Development Environment for Ruby on Rails projects. Built on top of the well-known Eclipse platform, RadRails provides all the tools you need to create a whole Rails application from a single interface, allowing you to focus on the creative part of the development as your IDE takes care of the mechanics.
This book will show you how to use the tools RadRails provides to improve your productivity:
This book is for Ruby on Rails developers who want to make the most of the framework by using an Integrated Development Environment.
Even though the book explains everything you need to follow the contents, the focus is on how to use the tool and not on the Rails framework itself, so previous working knowledge of Rails is highly advisable. Previous knowledge of Eclipse is not necessary.
--------------------------------------------------------------------------------
Javier Ramírez has been developing Web Applications since before the term Web Application was coined. Born in Zaragoza, Spain, in 1974, he started programming as a hobby around the age of 11 assisted by his older sister. A few years later, he got his first modem and became a regular of BBSes and Newsgroups. His interest in developing server applications that can be accessed remotely comes from those times.
He has learned —and forgotten— many programming languages, including Basic, dBase III, Cobol, Pascal, SQL, C, C++, ASP, TCL, JavaScript, PHP, and Java, the language on which he has focused for most of his career so far. He has held the positions of programmer, analyst, consultant, team leader, post-sales engineer, project manager, and software architect, totaling over 12 years in the IT business.
Having developed projects mainly for banks and other big corporations in Spain, Italy and the US, he co-founded some years ago a small software development shop, which provided him with valuable experience about the difficulties and the joys of entrepreneurship. After two years, he left the company in pursuit of new professional challenges.
For the last two years, he has been proudly working for ASPgems, where he discovered Ruby on Rails, which soon became his framework of choice for developing Web Applications. He is one of the organizers of the Spanish Rails Conference, also participating as a Speaker in the two events held so far.
He has also been an instructor on Robotics, Java, FatWire Content Server, and Ruby on Rails, and a University Lecturer in the subjects of 'Software Engineering' and 'The Java Programming Language', which he currently teaches at Universidad Francisco de Vitoria, in Madrid.
Javier Ramírez holds a B.Sc. in Business Information Systems with First Class Honors and a degree in Ingeniería en Sistemas de Computación.
------------------------------------------------------------------------------------------------
In June, Aptana and ColdFusion enthusiast, Mark Drew will be at CFUnited presenting:
Fresh AIR: Getting to grips with Aptana and AIR appsMark, who has been central to the CFEclipse project, is sure to deliver a great session, so be sure to check it out.
This session will give a nice and fresh introduction to developing AIR applications using Aptana. By using a ColdFusion developer's existing knowledge of HTML and JavaScript (and some quick introductions to JavaScript libraries such as EXT and JQuery), the whole process of developing rich desktop apps will be demystified.
Aptana will build off of its IDE and AJAX success with its new technology. Read the full story.
Learn more about Aptana Cloud, an "Elastic Application Cloud" that's ideal for Web developers who use scripting languages.
Join the early access program.
Following are the convenience functions that help make the magic happen. The first function is addElementToPage(). It very simply just creates an H2 tag and sets the title and a DIV tag which contains the contents of the fetched element:
This next function, getDocumentFromURL(), is the one that does most of the work. (I found some good info on the subject of HTML to DOM here: http://jszen.blogspot.com/2007/02/how-to-parse-html-strings-into-dom.html) It first goes and retrieves the remote page. Then it creates a 'document fragment' from the contents of the fetched site. That fragment is then added to a dynamically created IFRAME. Finally, the Document object from the IFRAME is fetched and returned. In short, we can pass in a URL, get the string value, place it into an IFRAME, then pull out the resulting Document object so that we can work on it.
This final function was found at http://www.dustindiaz.com/getelementsbyclass/ and walks a node looking for an element with a specific class name. It was used in the case where elements don't have ID's, so a class name is used instead.
What's exciting about this sample is that it is relatively simple, uses the full power of server-side JavaScript and more importantly, Jaxer's cool server-side DOM capability to enable real 'DOM scraping'. Once window object creation is finished in Jaxer (real soon now), then you'll be able to fetch remote pages, execute their integrated code, then proceed to fetch out items from the resulting DOM.
Update: see the Jaxer 1.0 version.
In this example, (the first in a series) we're going to build a simple voting tool, using a single page of DHTML. The implementation is quite basic but covers a good few examples of how to use Aptana Jaxer in real world situations, such as :
This example was written as a single page webapp. You could remove the Javascript to another file and make it all unobtrusive if that is what gets you excited, but I'm just using an inline script tag, as the code is only about 30 or so lines long. Also in Jaxer we could have easily implemented this using Jaxer's seamless ajax callback mechanism but for the purpose of this example we'll stick with a traditional form post.
Let's get started. Most folks reading this should be familiar with the standard blog/portal poll, where you are presented with a set of choices.
and once you have voted you get to see the current results of the voting.
In our example we allow multiple votes per user but you can easily change that by just commenting out a single line of code.
One of the interesting features of this application is that, by using server-side DOM manipulation in Jaxer, you can remove any unwanted content before it is sent to the client browser. We use this to hide the vote results until the user has voted
This is a useful technique for permission based forms where, for example, you may want remove the credit card details unless the user has established the correct permissions and been validated by the server.
So let's jump in and have a look at the code used to make this work. The code in this article has been updated to use the API of Jaxer 0.9.8 or later, for The full source listing below contains comments to indicate where the code was changed to work with the later API.
Above is the contents of the HEAD element. Just the usual suspects, setting the title and some simple CSS stuff. The only interesting part is at line #3, where we load the jQuery library on the server, because we intend to do some serverside DOM manipulation before the page is sent to the client.
The runat='server' attribute tells Jaxer to load this javascript library on the server.
The autoload attribute is a recent addition to Jaxer, and it instructs Jaxer to load that page and keep it cached as preparsed bytecode (for faster library loadtime) for any future calls to this page, including callbacks.
In the body of the document we have a simple form which we will dynamically populate on the server. The form will post the vote to itself on the server.
We are marking up the DOM content with the classnames 'voter' and 'nonvoter' to identify content that is specific to a user's status, and make it easily accessible using jQuery on the server.
The first dozen or so lines are simply creating a DB and preparing a schema for use.
So we've connected to the database (which was automatically created if needed, how convenient!) and set up the schema and initial content we expect. We also setup an Array (questions) containing the questions for the voting poll
Next we need to check the session value we are storing (status) to determine whether this user has already voted, and then check to see if the form data for the vote is being posted. Then, if we are actually voting, we write the vote to the database and set the user status to 'voter'.
When we write the vote to the database, we grab the sessionID and the remote IP address and write those out with the vote data, this will let us enforce single voting later if we need it.
Finally query the database to get the current vote counts, remembering to subtract 1 from the total to account for the dummy rows we inserted to seed database and prevent any nulls from appearing in the results totals.
Now we build the DOM, to do this we issue a query to the DB to get the current vote tally.
Using E4X - ECMAScript For XML as a simple templating tool we create the DOM with the nodes populated according to our dataset.
One of the nice features of server-side javascript with Jaxer is that you have access to all neat things built into Mozilla without the worry of client side browser support, which enables reliable use of the advanced features of the Javascript language.
If you look closely at the code below you'll notice we use a simple syntax for variable substitution using curly braces containing javascript code inside the E4X assigments. This allows us to use this for templating as long as we are creating valid XML nodes.
So the document now has a DOM that has been populated with the content for BOTH voters and non-voters. We use a little jQuery magic to remove the elements we don't want presented to the user.
In this way the user will EITHER see the form with the question and the submit button
OR the current voting results data.
Now we set the session variable status to be the current status of the user as they have either voted or not.
Finally as the page that is served has no further dependency on Jaxer once it leaves the server, we tell Jaxer to not bother injecting the client framework. Normally the client framework would be automatically inserted as a script tag in the outgoing HTML, but our simple example doesn't need to communicate back to the Jaxer server, as it contains no server callbacks.
So there you have it, a simple poll on a single page, using many of Jaxer's cool features.
The full code and supporting files for this article are available here
| Attachment | Size |
|---|---|
| choices.png | 7.09 KB |
| voted.png | 7.61 KB |
| votepoll.zip | 36.12 KB |
Aptana Jaxer has been updated to 0.9.5 providing increased performance for server-side JavaScript and a host of other enhancements to make End-to-End Ajax development easier.
Aptana Studio users can get the latest via Help > Software Updates. Otherwise, download the latest now.
One of the common web tasks that always seems to involve a lot of arcane knowledge of backend systems, is how to upload files. Like most systems, Aptana Jaxer uses the post/receive model, where a web form is posted to the server, and the target of that form will receive and process the content. Where Jaxer makes this really easy is that it is all done with regular JavaScript and HTML. No special enviroment vars, excessive string processing, or finding handles to oddly named temp files is required.
All you need is a form to present to the user, which contains an input element of type upload, and an HTML page to receive the submitted form containing a "runat=server" script block that retrieves the data from the request. You could have the form and the recipient be the same page, however in this example I'll use two files for clarity. As an aside in Jaxer you can actually send the form directly to a JavaScript function living on the server but we'll look at that configuration in a future blog entry.
This example upload form simply allows you to select up to 2 files for upload from the local filesystem. Pressing 'upload' posts the contents of that form to an HTML page containing the JavaScript shown later.