|
JSXHelloWorld @Jun 7, 2007, 2:51:36 PM
About This TutorialThis "HelloWorld" tutorial has been divided into two sections;
Enable JSX on HTML pageIn 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
<html> <head> <script type="text/javascript">var jsxContext='.'; var jsxLogLevel='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 packageEverything 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 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="ClickMe"> <script type="text/javascript">jsxBehavior("myapp.mypackage.MyClass", "ClickMe");</script> </body> </html> |
All contents copyright of the author. ©2007. JAMWiki Version 0.5.3 |