2

I'm new to Twitter Typeahead (typeahead.js 0.11.1) and I'm trying to configure it with Thymeleaf + Spring MVC using the remote option.

Here is my controller class:

@Controller
public class AutocompleteController {

    @Autowired
    private IRefDataService refDataService;

    @RequestMapping(value = "/get_user_firstname_suggestions.json", method = RequestMethod.GET)
    public @ResponseBody List<String> getUserFirstNameSuggestions(@RequestParam("searchTerm") String searchTerm) {
        return refDataService.getUserFirstNameSuggestions(searchTerm);
    }
}

Here is my javascript code:

// constructs the suggestion engine
var firstNames = new Bloodhound({
    datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
    queryTokenizer: Bloodhound.tokenizers.whitespace,

    remote:{ 
        url: "/hub/get_user_firstname_suggestions.json?searchTerm=%QUERY"         
    }
});

//Initialize the Bloodhound suggestion engine
firstNames.initialize(); 

$([[${'#' + heading.fieldName}]]).typeahead({
    hint: true,
    highlight: true,
    minLength: 2
},
{
    name: 'firstNames',
    display: 'value',
    source: firstNames.ttAdapter()
});

When I try to run my application, I am getting the following message:

INFO: Character decoding failed. Parameter [searchTerm] with value [%QUERY] has been ignored. Note that the name and value quoted here may be corrupted due to the failed decoding. Use debug level logging to see the original, non-corrupted values.
Note: further occurrences of Parameter errors will be logged at DEBUG level.

Any ideas how I can resolve this?

Zahanghir
  • 547
  • 4
  • 9
  • 22

1 Answers1

4

Ok. After doing a lot of searching and digging around I managed to solve it. The 'wildcard' option was missing.

var firstNames = new Bloodhound({
    datumTokenizer: Bloodhound.tokenizers.whitespace,
    queryTokenizer: Bloodhound.tokenizers.whitespace,
    remote: {
        url: '/hub/get_user_firstname_suggestions.json?searchTerm=%QUERY',
        wildcard: '%QUERY'
    }     
});

So I added the 'wildcard' option as shown above and this did the trick.

Zahanghir
  • 547
  • 4
  • 9
  • 22