jagbandhuster
jagbandhuster

Reputation: 707

Calling bean method using javascript

I want to show a list of options to the user when he/she clicks on an inputText component. I need to call a bean method by JavaScript using onclick attribute in IceFaces.

<ice:inputText id="inputText1" partialSubmit="true" value="" onclick="" />

How can I achieve this?

Upvotes: 0

Views: 2494

Answers (2)

Icarus
Icarus

Reputation: 63970

As @Neall said, you need to initiate an XMLHttpRequest and return the data to the client. There are many ways to do this and I don't know the framework you are referring to, but in general, you initiate the XMLHttpRequest passing some parameters -if needed- to a web method, for example, and then return the data in JSON format. When you issue the request it usually has a callback function for success and one for error. On the sucess event, you parse the JSON response and do whatever you need to do with it.

Look at here, for example:

http://elegantcode.com/2009/02/21/javascript-arrays-via-jquery-ajax-to-an-aspnet-webmethod/

Upvotes: 1

Neall
Neall

Reputation: 27164

It looks like you are trying to run server-side code when the user takes some action on the client side. You probably want to initiate an XMLHttpRequest.

The XMLHttpRequest basically just hits a URL, optionally returning some data to the browser. This is what people usually call AJAX. (For Asynchronous Javascript And XML - although people usually use JSON instead of XML.)

Upvotes: 1

Related Questions