Skip to main content

get the selected value from a widget scriptaculous AutoCompletion in server

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

hello all

i have the same problem like the thread by rasane http://forums.java.net/jive/thread.jspa?threadID=32566&tstart=0 but with another widget (scriptaculous autocompletion).

how can we get the selected value by the user from a scriptaculous widget autocompletion with the onkeyUp event ?

the value property is not in a JSON format its a String[] array, for example i have

what is the correct script i must add ? :
jmaki.subscribe("/scriptaculous/autocompleter*", function(e) {........ ???

ps: sorry for my bad english.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
rasane
Offline
Joined: 2007-08-15
Points: 0


cognizing the fact, that values on the http stream can be only formatted strings, one way to do the same could be:
jmaki.subscribe("/scriptaculous/autocompleter*", function(e) {
// begin prepare formatted string any manner you like
var formatString="{";
for (var i=0; i< e.value.length; i++){ formatString = formatString + e.value[i] + ":" ;}
formatString = formatString + "}";
// end prepare formatted string any manner you like
jmaki.doAjax({
method : "POST",
url : jmaki.webRoot + "/faces/ApplicationBean-countryService.ajax",
content : { cmd : 'setValue', value : formatString}, // < this is the only change
callback: function(req) {
jmaki.log("Back from Comobox Update: response is : " + req.responseText);
},
onerror : function(m) {
jmaki.log("Error updaing Combobox data");
}
});
});

in the server side service, unpack using split on ":" character
hope that gives you ideas..

regards,
rasane
ps: i have not run the above code, there could be syntactical issues

hi,
cognizing the fact, that values on the http stream can be only formatted strings, one way to do the same could be:
jmaki.subscribe("/scriptaculous/autocompleter*", function(e) {
// begin prepare formatted string any manner you like
var formatString="{";
for (var i=0; i< e.value.length; i++){ formatString = formatString + e.value[i] + ":" ;}
formatString = formatString + "}";
// end prepare formatted string any manner you like
jmaki.doAjax({
method : "POST",
url : jmaki.webRoot + "/faces/ApplicationBean-countryService.ajax",
content : { cmd : 'setValue', value : formatString}, // < this is the only change
callback: function(req) {
jmaki.log("Back from Comobox Update: response is : " + req.responseText);
},
onerror : function(m) {
jmaki.log("Error updaing Combobox data");
}
});
});

in the server side service, unpack using split on ":" character
hope that gives you ideas..

regards,
rasane
ps: i have not run the above code, there could be syntactical issues

Message was edited by: rasane

Message was edited by: rasane

rasane
Offline
Joined: 2007-08-15
Points: 0

// end prepare formatted string any manner you like
jmaki.doAjax({
method : "POST",
url : jmaki.webRoot + "/faces/ApplicationBean-countryService.ajax",
content : { cmd : 'setValue', value : formatString}, // < this is the only change
callback: function(req) {
jmaki.log("Back from Comobox Update: response is : " + req.responseText);
},
onerror : function(m) {
jmaki.log("Error updaing Combobox data");
}
});
});

in the server side service, unpack using split on ":" character
hope that gives you ideas..

regards,
rasane
ps: i have not run the above code, there could be syntactical issues

finally got the entire content in!!

Message was edited by: rasane

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

thanks rasane for reply, but probably i didn't explain what i want exactly, the e.value return the selected value by the user and not the array value.

i have find a solution for my problem : i expalin it :

in the jsf page :
...

note in the line url : jmaki.webRoot + "/faces/Bean-method.ajax", the Bean is my declared managed bean and method is a method defined into this class :

in the java code:

public class Bean {
...
public void method(FacesContext context, AjaxResult result) {
String value="";
HttpServletRequest request = (HttpServletRequest)context.getExternalContext().getRequest();
// get the command
String command = request.getParameter("cmd");
result.setResponseType(AjaxResult.JSON);
if ("setValue".equals(command)) {
value = request.getParameter("value");
System.out.println("the selected value is "+value);
result.append("{message:'success'}");
} else {
result.append(value);
}
}
}

and in the component.htm located in the widget folder (for my widget the path is \resources\scriptaculous\autocompleter\component.htm)

this method works correctly