Hope this helps:
------------------------------- Action class
------------------------------------------------
//the options to be returned
private String[] options;
public void setOptions(String[] options) {
this.options = options;
}
public String[] getOptions() {
return options;
}
//the term user typed
private String term;
public String getTerm() {
return term;
}
public void setTerm(String term) {
this.term = term;
}
public String getData() {
populateOptions(term);
return SUCCESS; //I am using JSON plugin for SUCCESS(
https://cwiki.apache.org/S2PLUGINS/json-plugin.html)
}
private void populateOptions(SString queryString) {
if(queryString == null){
return;
}
queryString = queryString.toLowerCase();
String[] uiOptions = getAllData();
List<String> matchList = new ArrayList<String>();
for(String uiOption: uiOptions) {
if(uiOption.toLowerCase().startsWith(queryString))
matchList.add(desc);
}
options = new String[matchList.size()];
matchList.toArray(options); //populate options with
matches
}
------------------------------- Struts XML
------------------------------------------------
<action name="GetMasterData" class="MasterDataProviderAction" method=
"getData">
<result name="success" type="json">
<param name="root">options</param>
</result>
</action>
------------------------------- JS & HTML
------------------------------------------------
$(<your-selector>).autocomplete( { source:
'your-urlbase/GetMasterData'});
- rahul
From:
sharath karnati <[email protected]>
To:
Struts Users Mailing List <[email protected]>
Date:
23-04-2010 01:07
Subject:
Re: Jquery autocomplete with struts2.
Please find below example
http://makhaer.blogspot.com/2008/12/jquery-autocomplete.html
in this example, he is just using jquery with textfield for doing
autocomplete with PHP. I'd like to do samething with struts2 action.
Can anyone please let me know, how to send data from action to .jsp to
display autocomplete rather than using another plug-ins.
Thanks,
Sharath.
--- On Thu, 4/22/10, Johannes Geppert <[email protected]> wrote:
From: Johannes Geppert <[email protected]>
Subject: Re: Jquery autocomplete with struts2.
To: [email protected]
Date: Thursday, April 22, 2010, 2:29 PM
Hello,
since version 2.0.0 the Struts2 jQuery Plugin have a autocompleter tag.
This is an easy way to implement an Autocompleter.
See:
http://code.google.com/p/struts2-jquery/wiki/AutocompleterTag
Best Regards
Johannes Geppert
sharath wrote:
>
> Hi All,
>
> I'm trying to use Jquery autocomplete with struts2. The example for
> using Jquery autocomplete is given below(link)
>
> http://makhaer.blogspot.com/2008/12/jquery-autocomplete.html
>
> In this example, author is returning data with .php similarly I'd
like
> to return data from struts2 action(not with json object)
>
> Can anyone please let me know how to return data from struts2 action
> for accomplishing same thing.
>
> Thanks in advance.
>
> Regards,
> Sharath.
>
-----
---
web: http://www.jgeppert.com
twitter: http://twitter.com/jogep
--
View this message in context:
http://old.nabble.com/Jquery-autocomplete-with-struts2.-tp28329744p28332899.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
=====-----=====-----=====
Notice: The information contained in this e-mail
message and/or attachments to it may contain
confidential or privileged information. If you are
not the intended recipient, any dissemination, use,
review, distribution, printing or copying of the
information contained in this e-mail message
and/or attachments to it are strictly prohibited. If
you have received this communication in error,
please notify us by reply e-mail or telephone and
immediately and permanently delete the message
and any attachments. Thank you