myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Madhav Bhargava" <>
Subject I just cannot make InputSuggestAjax component work
Date Sat, 09 Jun 2007 20:53:22 GMT
Hi All,

Weblogic 8.1
JDK 1.4.2.x
Myfaces 1.1.5
Tomahawk 1.1.5
Tomahawk sandbox 1.1.5

I have taken the lead from the example at which is again
present at

Instead of an Address bean i have a KeyValuePair bean. This bean has 2
properties - key (String), value (Object). I want to display the values in
the drop down that would come up when the user starts typing something and
then the selected bean will then be passed to the model. Using the key field
of the selected bean i will then compose a query for the database.

JSP code:
<s:inputSuggestAjax suggestedItemsMethod="#{ajaxsuggest.suggest}"
    itemLabelMethod="#{ajaxsuggest.getLabel}" value="#{
    <f:converter converterId="inputSuggestAjaxConverter"/>

Methods in Controller/Managed bean for inputSuggestAjax component:

    public List suggest(String prefix) {
        List matchingList = new ArrayList();
        Iterator iter = items.iterator();
        while(iter.hasNext()) {
            KeyValuePair bean = (KeyValuePair);
            if (bean.getValue().toString().startsWith(prefix)) {
        return matchingList;

    public String getLabel(Object selectedBean) {
        if (null != selectedBean && selectedBean instanceof KeyValuePair) {
            Iterator iter = items.iterator();
            while(iter.hasNext()) {
                KeyValuePair bean = (KeyValuePair);
                    return (String)bean.getValue();
        return null;

Just to test i am populating the items List in the controller itself:
    public InputSuggestAjaxController() {
        items = new ArrayList();
        items.add(new KeyValuePair("1", "India"));
        items.add(new KeyValuePair("2", "US"));
        items.add(new KeyValuePair("3", "Russia"));
        items.add(new KeyValuePair("4", "China"));
        items.add(new KeyValuePair("5", "Indonasia"));
        items.add(new KeyValuePair("6", "Iran"));
        items.add(new KeyValuePair("7", "Uganda"));

Custom Converter for this component:
    public Object getAsObject(FacesContext context, UIComponent component,
String value)
            throws ConverterException {

        if (null != value) {
            KeyValuePair bean = new KeyValuePair();
            return bean;

        return null;

    public String getAsString(FacesContext context, UIComponent component,
Object value)
            throws ConverterException {
        if (null != value) {
            if (value instanceof KeyValuePair) {
                return (String)((KeyValuePair)value).getValue();
            }else if (value instanceof String) {
                return value.toString();
        return null;

public class KeyValuePair implements Serializable {
    private String key = null;
    private Object value = null;
    //getter and setter methods...

The problem is that when the user starts typing nothing is suggested even
though the control goes to suggest method and a list is created properly.
getLabel method gets called and even the method in the converter gets
called. But somehow it does not show up.

Browser that i am using is IE 6

Any help in this regard will be greatly appreciated.


When I tell the truth, it is not for the sake of convincing those who do not
know it, but for the sake of defending those that do

View raw message