Hi, I am using the SuggestField Add-on and I am quit satisfied with it. But now I have a little problem, probably soemone can tell me the reason: If I set a value it is not displayed in the field but it has been set. I think the reason migtht be an error in my code, I hope someone can give me an advice:
[code]
public OrganizationCustomerSuggestionField(Organization organization, OrganizationCustomerType organizationCustomerType) {
this.setLocale(UI.getCurrent().getLocale());
this.setImmediate(true);
this.setInputPrompt(Lang.getString(“playerSearch”, getLocale()));
this.setWidth(100, Unit.PERCENTAGE);
this.setNewItemsAllowed(false);
//
// Set the suggestion handler
//
this.setSuggestionHandler(new SuggestionHandler() {
/**
*
*/
private static final long serialVersionUID = 5936331305246105024L;
@Override
public List<Object> searchItems(String query) {
organizationCustomers = OrganizationCustomerUtils.searchForName(organization, organizationCustomerType, query);
List<Object> results = new ArrayList<>();
for(OrganizationCustomer customer : organizationCustomers)
results.add(customer);
return results;
}});
//
// Create suggestion converter
//
this.setSuggestionConverter(new SuggestionConverter() {
/**
*
*/
private static final long serialVersionUID = -8342054010047293L;
@Override
public SuggestFieldSuggestion toSuggestion(Object item) {
// TODO Auto-generated method stub
SuggestFieldSuggestion sug = new SuggestFieldSuggestion();
sug.setId(((OrganizationCustomer) item).getUser().getPid()+"");
sug.setDisplayString(((OrganizationCustomer) item).getUser().getSurname().toUpperCase()+" "+((OrganizationCustomer) item).getUser().getFirstname());
return sug;
}
@Override
public Object toItem(SuggestFieldSuggestion suggestion) {
for(OrganizationCustomer customer : organizationCustomers) {
if((customer.getUser().getPid()+"").equals(suggestion.getId()))
return customer;
}
return null;
}});
}
[/code]Thank you,
Florian