how to get the original SelectItem value after the user's choice?

I create input text with auto suggest items

<af:inputText label="Seller" id="Seller"
              valueChangeListener="#{managedBeanTest.OnChangeSeller}" autoSubmit="true"
              autoComplete="on">
  <af:autoSuggestBehavior suggestedItems="#{managedBeanTest.OnSearchSellers}"/>
</af:inputText>

set SelectItem value to my class Item

public class Test
{
    public static class Item
    {
        public Item(int id, String code, String name) { ... }
        public String toString() { ... }
    }

    public List<SelectItem> OnSearchSellers(String search)
    {
        ResultSet rs;
        ...
        List<SelectItem> result = new ArrayList<SelectItem>();

        while (rs.next())
            result.add(new SelectItem(new Item(rs.getInt(1), rs.getString(2), rs.getString(3))));

        return result;
    }

    public void OnChangeSeller(ValueChangeEvent valueChangeEvent)
    {
        Object newVal = valueChangeEvent.getNewValue();

        if(newVal != null)
          System.out.println("OnChangeSeller: " + newVal.getClass().getName());
    }
}

But in OnChangeSeller i've got only java.lang.String. How I can get original selected item value (Item class) ?

Answers


Actually passing a Java object to a HTML page doesn't work as the browser only shows String values (have a look at the rendered HTML page). So what you need to do is to pass the index of the object as a value. Then when the user selects a value you take the index and lookup the list for the real object you are interested in.

Frank


doesn't valueChangeEvent.getOldValue() not have this?


"doesn't valueChangeEvent.getOldValue() not have this?"

Yes, if you use ADF binding. In this case the returned value is the index of the list


Need Your Help

Android preference, does it have to be unique?

android

For my private static final String PREFS_NAME = "mypref"; does the PREFS_NAME have to be unique for every application? Or can I use the same one over and over.

@XMLRootElement versus @XmlType

xml jaxb jax-ws

What's the difference between annotating a class with @XMLRootElement and @XMLType. I've been annotating classes with @XMLType when the structure will be used more than once within an XML schema an...