|
|
Using jMaki WidgetsBefore starting you learn more about the jMaki Widget which will describe the seperate components that make up a widget. It would also be good to review thejMaki Application Structure to learn more about what resources need to be put in what places. This document explains how to define widgets and describes how to configure individual instances of widgets. This document will also review the life cycle of a jMaki widgets. Identifying jMaki Widgets
The "name" attribute is the key used to put all the components together. The name of a widget maps to a directory that contains the resources needed for a widget. A widget is generally made up of a html template ( In JSP / JSF <widget name="my.widget"/> In PHP: <?php addWidget("my.widget"); ?>
In the example, the jMaki server-side component will look in the same directory as the widget
for a directory called "my" which contains a directory "widget". If this directory is found,
jMaki will then look for a file called The life-cycle of a jMaki WidgetNow that we know what widgets are and have seen how widgets names and types are used let's dig a little deeper and see how widgets are created and initialized. jMaki widgets are rendered in a two step process which spans both the client and the server. The following diagram details the lifecycle in more detail. ![]()
The key steps for the the parameters getting passed by the server rendered code to the JavaScript
instance are found in steps 3, 5 and 6 above. Parameters such as the widget identifier from template
content in jMaki Widget AttributesjMaki widget instances can be configured with a variety of properties which are described in the Widget Model documentation In JSP and JSF the attribute names matching the property names are used to configure a widget. In PHP the order of the function parameters is the following: addWidget(name, service, args, value, uuid); The only required parameter is the name and if you need to skip any arguments you can do so by
passing Example of a jMaki WidgetFollowing is an actual JSP file declaring two jMaki components. <%@ taglib prefix="a" uri="http://jmaki/v1.0/jsp" %> <a:widget name="dojo.clock" /> The same widget may be defined in PHP as: <?php require_once 'Jmaki.php'; ?>
<?php addWidget('dojo.clock'); ?>
The JSP and PHP are rendered to HTML as: <script type="text/javascript" src="http://localhost:8084/WebApplication2/resources/jmaki.js"></script>
<script type="text/javascript">jmaki.webRoot='http://localhost:8084/WebApplication2';jmaki.resourcesRoot ='/resources';jmaki.xhp ='http://localhost:8084/WebApplication2/xhp';</script>
<script type="text/javascript" src="http://localhost:8084/WebApplication2/glue.js"></script>
<script type="text/javascript" src="http://localhost:8084/WebApplication2/resources/system-glue.js"></script>
<script type="text/javascript">if (typeof djConfig =='undefined') djConfig = { parseWidgets: false, searchIds: [] };</script>
<script type="text/javascript" src="http://localhost:8084/WebApplication2/resources/dojo/resources/libs/dojo/v0.4.3/dojo.js"></script>
<script type="text/javascript" src="http://localhost:8084/WebApplication2/resources/dojo/clock/component.js"></script>
<span id="dojo_clock1"></span>
<script type="text/javascript">jmaki.addWidget({widgetDir:'http://localhost:8084/WebApplication2/resources/dojo/clock',uuid:'dojo_clock1',name:'dojo.clock',sourceURL:'http://localhost:8084/WebApplication2/'});</script>
In the case of both platforms the script and style references are the same. This is what allows one set of widgets to be supported on multiple server runtimes because the JavaScript, CSS, and template code which make up the widgets and client-side infrastructure are the same. The bootstrapper ("jmaki.js") is loaded first as it manages the loading and initialization of all the widgets. The parameters that make an individual widget unique are passed to the bootstrapper for each component instance as can be seend in the following snippet: <script type="text/javascript">jmaki.addWidget({widgetDir:'http://localhost:8084/WebApplication2/resources/dojo/clock',uuid:'dojo_clock1',name:'dojo.clock',sourceURL:'http://localhost:8084/WebApplication2/'});</script>
These parameters are passed to the constructor for each widget (defined in widget's "component.js" file). The processing of the parameters is up to the widget. |