• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

implementing Wild Card search using struts textbox or autocomplete

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,

Can anyone please help me in implementing wildcard search using struts textbox or autocomplete feature. And we can use database to retrieve the values from the database.
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the JavaRanch. What have you tried so far?
 
vinayreddy podduturi
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am sharing my idea with you. Using struts autocomplete tag i created a text field to input the value like 'a*' to display values starting with 'a'. So actually it need to be send to action class and search in the database using sql query with LIKE operation to retrieve the results and stored in an arraylist and should be popup in the text field so that we can select the list of values which start with 'a'. But my problem is that I am not able to send value which we type in the text field that should be passed to action class and perform some database operation and display the result.

<s:label name="stateName" value="Select State Name:" />
<s:autocompleter theme="simple" list="state" name="StateName"/>


we are accessing the list as mentioned above. And we should not use the submit button in order call the action class.
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you look at the documentation for the autocompleter tag there's an example that looks like what you want to do:

 
vinayreddy podduturi
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes I have seen that example. But can you expalin me what exactly does href does and what json list does in that. And my problem is

I don't know how to get the value from auto textfield (this is done: and store in a string and perform database operation and then storing the result.)

String name= the value should be obtained from auto text field which is like "a*";

and i am replacing * with % inorder to perform wildcard search in database.

String name2 = name.replace('*','%');

String sql= "SELECT distinct name from States where name like '"+name2+"'";

storing in a list.

listStates.add(rs.getString("name"));

And in my case what is the use of href?

All this stuff is in action class.
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

vinayreddy podduturi wrote:
And in my case what is the use of href?



As the example says "The text entered on the autocompleter is passed as a parameter to the url specified in "href"", so the value of href should be the name of your action. You should have a getter and setter for whatever the autocompleter name is in your action.
 
vinayreddy podduturi
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is what I did.

<td><struts:url id="stateValue" action="history" method="setValue" />
<dojo:autocompleter list="listStates" href="%{stateValue}" name="state" id="state" cssStyle="width:106px"/></td>


In the action class history:

these methods are to get value from autocomplete form:

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}

for the obtained list after executing query.

public List<String> getStates() {
return state;
}

public void setStates(List<String> state) {
this.state = state;
}

But still it is not working for me. Please can you suggest me with an example so that I can clear my doubt.
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you have it backwards. The href should be the URL that you get the list from, and the name should be the name of a field that you will be setting on the action:"state".
I don't think you want to use the "list" as you are using an action to populate the text box, and you don't appear to have a getter/setter of that name in your action.
 
vinayreddy podduturi
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If Possible please can you show me by rewriting the code and post it.
 
reply
    Bookmark Topic Watch Topic
  • New Topic