File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

implementing Wild Card search using struts textbox or autocomplete

 
vinayreddy podduturi
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Joe Ess
Bartender
Posts: 9214
9
Linux Mac OS X Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch. What have you tried so far?
 
vinayreddy podduturi
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • 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: 9214
9
Linux Mac OS X Windows
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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: 9214
9
Linux Mac OS X Windows
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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: 9214
9
Linux Mac OS X Windows
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If Possible please can you show me by rewriting the code and post it.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic