JSXHelloWorld
  1. About This Tutorial
  2. Prerequisities
  3. Enable JSX on HTML page
  4. First JSX package

About This Tutorial

This "HelloWorld" tutorial has been divided into two sections;

  1. In the first section you will learn how to properly include JSX onto your page.
  2. Second section will show you how to build your first JSX module that captures a mouse click on a button and pop-up an alert.

Prerequisities

JSX Toolkit is downloaded and installed in target directory. See the GettingStarted page for instructions.

Enable JSX on HTML page

In this section you will essentially test your JSX installation. First create a 'index.html' page in your context root - the place where you've installed the JSX libraries. To actually enable JSX Toolkit on your page, insert two <script> tags into the head element.

<html>
    <head>
        <script type="text/javascript">var jsxContext='.'; var logLevel='INFO';</script>
        <script type="text/javascript" src="./jsx/core.jsx"></script>
    </head>
    <body>
        <script type="text/javascript">
	    logger.info("Welcome to JSX!");
	</script>
    </body>
</html>

That's it! With above code in your page, you should be able to see a popup debug log window appear, that should be clear indication that JSX is enabled.

First JSX package

Everything in your JSX enabled application should be done by packages. Some other frameworks create one monolithic .js file that holds everything, but this is not our way. The advantage of this approach is that you can load only those parts of JSX Toolkit (and your packages) that the page actually needs. This saves bandwidth, and of course, user frustration with slowly loading pages.

So, let's get started.

jsxPackage("myapp.mypackage", function(thisPackage){

	var EventHandler = jsxImport("jsx.utils.events.EventHandler");

	jsxClass("MyClass", EventHandler, function(superClass){
	
		this.instantiate = function(element){
			superClass.instantiate.call(this);
			this.addHandledElement(element);
		}
		
		this.onclick = function(evt){
			alert("Hello World!");
		}
	});
});

The jsxClass that was created is going to live inside the myapp.mypackage.MyClass namespace. The MyClass class is an EventHandler, it hooks up to the JSX event routing engine.

Now, to get MyClass up and running, add a button and instantiate the class like below.

<html>
    <head>
        <script type="text/javascript">var jsxContext='.'; var logLevel='INFO';</script>
        <script type="text/javascript" src="./jsx/core.jsx">
    </head>
    <body>
        <input type="button" id="clickme" name="clickme" value="Click Me">
        <script type="text/javascript">jsxBehavior("myapp.mypackage.MyClass", "clickme");</script>
    </body>
</html>