FileDocCategorySizeDatePackage
UsernameSuggestAction.javaAPI DocExample2229Wed Apr 05 20:04:52 BST 2006com.oreilly.ajax

UsernameSuggestAction

public class UsernameSuggestAction extends fr.improve.struts.taglib.layout.suggest.SuggestAction

Fields Summary
Constructors Summary
Methods Summary
public java.util.CollectiongetSuggestionList(javax.servlet.http.HttpServletRequest in_request, java.lang.String in_word)

        
        // Get all the user names
        Collection usernames = getUserSuggestions();
        
        // Start to build the suggestions list
        ArrayList suggestions = new ArrayList();
        
        if (in_word != null && in_word.length() > 0)
        {
            Iterator iter = usernames.iterator();
            
            while(iter.hasNext())
            {
                String currentWord = (String) iter.next();
                
                if(currentWord.toLowerCase().startsWith(in_word.toLowerCase()))
                    suggestions.add(currentWord);
            }
        }
        
        return suggestions;
    
private static java.util.CollectiongetUserSuggestions()

        
        ArrayList arrayList = null;
        Connection con = DatabaseConnector.getConnection();
        try
        {
            Statement statement = con.createStatement();
 
            String sqlString = "select username from users;";
            ResultSet resultSet = statement.executeQuery(sqlString);
            arrayList = new ArrayList();
            while (resultSet.next())
            {
                arrayList.add(resultSet.getString(1));
            }
        }
        catch (Exception e)
        {
            System.out.println("exception caught getting usernames");

        }
        finally
        {
            if (con != null)
            {
                try
                {
                    con.close();
                }
                catch (SQLException e)
                {
                }
            }
        }
        return arrayList;