aspose file tools*
The moose likes Struts and the fly likes implementing Wild Card search using struts textbox or autocomplete Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "implementing Wild Card search using struts textbox or autocomplete " Watch "implementing Wild Card search using struts textbox or autocomplete " New topic
Author

implementing Wild Card search using struts textbox or autocomplete

vinayreddy podduturi
Greenhorn

Joined: Mar 11, 2012
Posts: 13
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

Joined: Oct 29, 2001
Posts: 8927
    
    9

Welcome to the JavaRanch. What have you tried so far?


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
vinayreddy podduturi
Greenhorn

Joined: Mar 11, 2012
Posts: 13
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

Joined: Oct 29, 2001
Posts: 8927
    
    9

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

Joined: Mar 11, 2012
Posts: 13
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

Joined: Oct 29, 2001
Posts: 8927
    
    9

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

Joined: Mar 11, 2012
Posts: 13
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

Joined: Oct 29, 2001
Posts: 8927
    
    9

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

Joined: Mar 11, 2012
Posts: 13
If Possible please can you show me by rewriting the code and post it.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: implementing Wild Card search using struts textbox or autocomplete