Skip to main content

Lost the functionalities of a jmaki widget after an ajax request

4 replies [Last post]
mediii
Offline
Joined: 2007-09-03
Points: 0

Hi all,

I encounter some trouble with a jmaki widget (scriptaculous autocompleter), after refreshing my component by an ajax request,

I lost the script that enable the widget, after receiving the ajax response from the server, the rendered script is wrapped by //

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mediii
Offline
Joined: 2007-09-03
Points: 0

Thank you Greg, this is a great help for my futur uses of the jmaki components.

Mediii

gmurray71
Offline
Joined: 2003-07-31
Points: 0

Hi Mediii,

How are you using the autocompleter? (could you include it here)?

What server runtime are you using? PHP / JSP / Ruby / HTML

mediii
Offline
Joined: 2007-09-03
Points: 0

Hi gmurray71,
I'm working with JSP page under Tomcat6 and Glassfish2.

the autocompleter widget is loaded first from the jsp page by the following line:

id="textfield" value="#{autoCompletionBean.words}"
binding="#{viewBean.autocompleteComponent}"/>

the property autoCompletionBean.words contains the array of words for JSON code to init the widget, the keyword list is loaded from a database I use postgres.

In my application, I use JSF1.2 and Ajax4Jsf library (by JBoss) for multpile usages (rerender several components via ajax), and at a point I need to refresh a panel which contains this jmaki widget, for example I need to switch the rendered property to true or false and refresh the page by calling a reRender process on the wrapping panel. see the following lines:


...

...

After refreshing the mypanel the widget is disactivated and all scripts which has loaded with the compoenent is wrapped by //

I have tried to reload the widget by this script :

but without succes :(

Message was edited by: mediii

Message was edited by: mediii

gmurray71
Offline
Joined: 2003-07-31
Points: 0

Hi,

Basically jMaki is set up to not load widgets a second time (intentionally).

The code that is stopping you is here:

// see if the widget has been defined.
if (_jmaki.attributes.get(_jmw.uuid) != null) {
return null;
}

In your case what you could do is call :

1) Give your widget a knowin ID

2) Remove the instance of the widget in jMaki's widget list:

jmaki.attributes.remove("textfield");

3) Now load the widget again:

jmaki.loadWidget(
{
uud : "textfield",
name : "scriptaculous.autocompleter",
value : "some value"
}
);

The code you have will not load a widget becasue you are basically only passing in the widget constructor. The real challenge in your case is getting the widget value. To recreate the widget. In your case the best way to do this might be to use a service with an Ajax request to load the autocompleter words.

This way the widget would reload the words when the widget is reinitialized.

jmaki.loadWidget(
{
uud : "textfield",
name : "scriptaculous.autocompleter",
service : "mywordsservice.jsp"
}
);

Does tnis make sense?

-Greg