Home  >  

JXT - Javascript XHTML Tags

Author photo
AddThis Social Bookmark Button

First of all, I would like to thanks Rich Tretola and O'Reilly, for the possibility to write on this blog and talking about my project (http://www.jxtproject.com), I'm very thankful for that! ...and I'm quite embarrassed, because this is my first article here.

Preface
Although JavaScript is a programming language, with its syntax, rules and functions, nowadays it is used "unconsciously" by a lot of people which don't have any programming background, due to the diffusion of powerful and user friendly js libraries. This may results in bad written, slow, and buggy web sites. Another issue is that, in most cases, these libraries are used only to display advanced and interactive component which HTML can't offer and not to implement any kind of logic flow. So, if the goal is to extend HTML capabilities, wouldn't be the best and simplest solution to have a new set of powerful tags?

Overview
So, what is JXT and why you may be interested to it?
JXT is a javascript framework which let you use jQuery and Ext widgets (plugins/components) without writing a single line of code, but instead by using “in place” XHTML custom tags. This tags are “translated” by the framework and converted behind the scenes into JavaScript objects at runtime, once the page has been loaded. They are completely unobtrusive, because they don’t interfere with page layout and are physically destroyed once converted into JavaScript code. Moreover they are validatable by W3C, since JXT makes use of a custom DTD (based on W3C XHTML transitional DTD) and these tags have their own namespace (“jxt:” prefix). The abstraction work behind JXT has been possible thanks to the implicit standard defined by modern JavaScript libraries which provide a single argument (a “configurator” object) passed to a constructor in order to initialize a component, which is then rendered into a given target element (typically a div). In this way, JXT syntax will be the same for both libraries widgets. A tag will looks like the following below:

 
<jxt:widget type="libraryName" name="widgetName">
    <jxt:target>
        <div></div>
    </jxt:target>
</jxt:widget>

Configuring widgets
Widgets are configured like in javascript and jump from js code to JXT tags is really very simple, all you have to learn is how to convert JSON structure to nested <jxt:cfg> tags. A <jxt:cfg> tag represents a "key" inside an object, it has a name, a value and can contains infinite "subkeys", exactly like in JSON and instead of passing this object to a constructor, in JXT you simply nest <jxt:cfg> inside <jxt:widget>:

 
<jxt:widget type="libraryName" name="widgetName">

    <jxt:cfg name="param1" value="value1" type="string"></jxt:cfg>

    <jxt:cfg name="param2" type="object">
        <jxt:cfg name="prop1" value="value1" type="string"></jxt:cfg>
        <jxt:cfg name="prop2" value="value2" type="string"></jxt:cfg>
    </jxt:config>

    <jxt:target>
        <div></div>
    </jxt:target>

</jxt:widget>

The interesting part of <jxt:cfg> tag is that you can declare (you must) the data type of this key (int, float, array, object, boolean…) even if it is a custom type (LibraryName.ui.form.ComboBox).

Let’s see how to convert a JSON structure like this:

 
{
   id: "myForm",
   url: "submit.php",
   items: [
     {
        label: "name",
        allowBlank: false,
        fieldLabel: "First name"
      },
     {
        label: "Last name",
        allowBlank: false,
        fieldLabel: "last"
      },
     new Ext.form.TimeField({
        fieldLabel: "Time",
        name: "time",
        minValue: "8:00am",
        maxValue: "6:00pm"
      })
   ],
   buttons: [
     {
        label: "save",
        click: function() {
           alert("save!");
         }
      },
     {
        label: "reset",
        click: function() {
           alert("reset!");
         }
      }
   ]
}

Into JXT syntax:

 
<jxt:cfg type="string" name="id" value="myForm"></jxt:cfg>
<jxt:cfg type="string" name="url" value="submit.php"></jxt:cfg>
<jxt:cfg type="array" name="items">
  <jxt:cfg type="object">
    <jxt:cfg type="string" name="label" value="name"></jxt:cfg>
    <jxt:cfg type="boolean" name="allowBlank" value="false"></jxt:cfg>
    <jxt:cfg type="string" name="fieldLabel" value="First name"></jxt:cfg>
  </jxt:cfg>
  <jxt:cfg type="object">
    <jxt:cfg type="string" name="label" value="last"></jxt:cfg>
    <jxt:cfg type="boolean" name="allowBlank" value="false"></jxt:cfg>
    <jxt:cfg type="string" name="fieldLabel" value="Last name"></jxt:cfg>
  </jxt:cfg>
  <jxt:cfg type="object" jsclass="Ext.form.TimeField">
    <jxt:cfg type="string" name="fieldLabel" value="Time"></jxt:cfg>
    <jxt:cfg type="string" name="name" value="time"></jxt:cfg>
    <jxt:cfg type="string" name="minValue" value="8:00am"></jxt:cfg>
    <jxt:cfg type="string" name="minValue" value="6:00pm"></jxt:cfg>
  </jxt:cfg>
</jxt:cfg>
<jxt:cfg type="array" name="buttons">
  <jxt:cfg type="object">
    <jxt:cfg type="string" name="label" value="save"></jxt:cfg>
    <jxt:cfg type="function" name="click" value="alert('save!')"></jxt:cfg>
  </jxt:cfg>
  <jxt:cfg type="object">
    <jxt:cfg type="string" name="label" value="reset"></jxt:cfg>
    <jxt:cfg type="boolean" name="allowBlank" value="alert('reset!')"></jxt:cfg>
  </jxt:cfg>
</jxt:cfg>

Not only widget
The framework was born to use widgets with ease, but is not limited to the <jxt:widget> tag and its subtags. JXT offers also its own tags and features, which can be combined together to obtain the desired result. At the moment these are very few, but they will increase in the next releases. You can however already use <jxt:if> for conditional display, <jxt:datetime> to print a formatted date and <jxt:loop> to duplicate html nodes. This last one is very cool combined with certain widget like carousel, in order to print dynamically N img tag (where N is the number of “steps” attribute). It has in fact a special notation which allow you to access loop’s iterator value, here is an example:

 
<jxt:loop steps="10">
     <img src="img/demo_pic_{loop:step}.jpg" alt="pic {loop:step}" />
 </jxt:loop>

More on JXT
JXT is a young project at its first beta release, but I think it has great potential. I’m spending a lot of my spare time thinking to new implementations and improvements and I have a lot of ideas for the future. One great addition which will be present in the final release will be the possibility to separate configuration in an external xml file, in this way the page will contains only <jxt:widget> declarations. If you are interested (as I hope), you can read more about it on: http://www.jxtproject.com

For questions and feedback I will be glad to reply here and on the forum: http://www.jxtproject.com/forum

Read more from Davide Zanotti. Davide Zanotti's Atom feed daveoncode on Twitter

Comments

8 Comments

Aaron Terry said:

Very interesting concept you have going here. Keep up the good work. As an advanced ColdFusion Developer, it kind of reminds me of the goal of entry-level ColdFusion. That being to make complex programming understandable to people used to a tag based language like HTML.

Sean Hess said:

Clever. I've been wanting to do that for a long time. I didn't know that you could use a custom namespace to get it to validate, that's great! Very good idea to destroy them afterward.

How is performance with all that translation going on?

Sean Hess said:

I would prefer the following syntax:

<jxt:CustomWidget/>

to this

<jxt:widget type="libraryName" name="widgetName">

What about the possibility of developer namespaces? Instead of specifying the library name and the widget name as attributes, the library could be defined in the namespace, and the widget as the tag.

@Aaron Terry: eheh, I've been a Coldfusion developer for a couple of years, maybe I've been influenced ;-)


@Sean Hess: in order to allow custom namespaces I should expose a javascript JXT object and a dedicated method, actually the jxt.js doesn't create any js variables in memory, it is merely a parser... however, I could create a special tag for configuration options... mmmh, I will evaluate that idea. The performance are really good, of course by using jxt widget creation is slower (couldn't be differently), but the parser needs only few milliseconds to parse hundreds nested tags. Anyway next releases will be faster (at the moment I've improved jxt:loop until 10x)

Madan Narra said:

This is really awesome !! Keep up the good work and thanks for such a good framework.

One doubt regarding its usage.

Can I still make use of Javascript code and access the JXT Widgets ? There could be such a situation where in the complex of code increases and we couldn't implement it within Tags.

@Madan: at the moment, there is no way to directly access widgets created (this my
big omission, which I've already implemented in the coming release). Anyway this is
true only if you use Ext library, because jQuery plugins are accessible and
editable later, by using a jQuery selector ($("#mydiv").pluginName({// ... config
here})) .
In the next release, widget tag will have a "jsid" attribute which will work as you need.

ps. I've been too shameless by calling first release "1 beta", it should be
considered an alpha... but I was too anxious about its publication :)
Anyway next release will be an huge step toward a concrete, stable and useful
framework!

Mario said:

It is an admirable effort but I do not agree with the concept.
Lets keep semantics/content/(x)html, appereance/transitions/css and interactivity/functionality/js each at its own layer.
If you want to make non-programmers life easier why don't you invest somr time doing some sort of Dashcode for designers...

Best Regards

@Mario: I don't understand the connection between my project and its goals and the
dashcode (are you talking about http://developer.apple.com/tools/dashcode ...right?
)... they are two completely different worlds.
For that concerning layers separation you are right, in fact I'm working to
externalize configuration in external file (optionally.... as is optional import
your javascript code from an external file rather than write it directly in the page)

Leave a comment


Tag Cloud

Question of the Week: Call for Topics

What do you want from InsideRIA?

Answer

Latest Features

Recommended for You

@InsideRIA on Twitter

Archives

  • Or, visit our complete archive.  

About This Site

Welcome to the premiere community site for all things RIA sponsored by O'Reilly Media and Adobe Systems Incorporated.