Skip to main content

How to add a jMaki Widget using JavaScript ?

2 replies [Last post]
krishnag
Offline
Joined: 2008-02-12

I want to add a new jMaki widget on runtime to the page.
Suppose user click on a button and a jMaki Autocomplete
widget will be added to the page - i want this using JavaScript without page refresh.

Any clue!!!!!

Thanks
Krishna

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
gmurray71
Offline
Joined: 2003-07-31

Hi,

Which version of jMaki are you using?

If you are using the latest and greatest from the nightly builds the code for the widget loader should be included:

If not find it here:

https://jmaki-ext.dev.java.net/source/browse/*checkout*/jmaki-ext/trunk/...

Place this file in your :

/resources/jmaki/widgetFactory dirctory.

This file needs to be defined after your first widget (after the jmaki.js has been loaded). You could even add it as a dependency of your autocomplete component.

Use it like this:

var widgetFactory = jmaki.getExtension("jmaki.widgetFactory");
if (widgetFactory == null) widgetFactory = jmaki.loadExtension("jmaki.widgetFactory");
widgetFactory.loadWidget(
{ widget : { name : 'jmaki.tagcloud'}
container : _someDiv,
callback : _callback
});
}

widget is the wargs you normally give a widget. You are required to provide a name as the minimum. Provide a DOM node reference and also a callback if you want it called following the widget load. The widget loader will load all the required JS and CSS resources needed by a widget.

If you are loading widget resources from somewhere other than /resources/ you can provide a widgetDir property as part of the widget properties to where to find the widget resources (component.js/component.css/component.htm). Widgets tend to also need the widgetDir to find images or other widget related items.

Please let me know if you have a hard time with this.

-Greg

krishnag
Offline
Joined: 2008-02-12

Thanks Greg !

i am using jmaki 1.8.0 released on 30th April-2008.

I downloaded the file described by you and added the script code mentioned...

but the [b]widgetFactory[/b] directory is not available in [b]resources [/b]folder. I created this directory and kept the file [b]extension.js[/b] in that directory. but still i facing following JavaScript error

[i]

[b]widgetFactory is undefined[/b][/i]

following is my jsp code

//and _someDiv is also defined

---Krishna