我使用自动建议项目创建输入文本
<af:inputText label="Seller" id="Seller"
valueChangeListener="#{managedBeanTest.OnChangeSeller}" autoSubmit="true"
autoComplete="on">
<af:autoSuggestBehavior suggestedItems="#{managedBeanTest.OnSearchSellers}"/>
</af:inputText>
将 SelectItem 值设置为我的类 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());
}
}
但在 OnChangeSeller 中,我只有 java.lang.String。如何获得原始选定项目值(项目类)?