Hello,
I am a beginner of Vaadin. I use add-on TokenField as a multi-select in a Form, add-on AppFoundation
as JPA based persistence. A TokenField is binded to a user Set.
The problem is that until committed Form TokenField is ok. It displays right item caption(user name) ,
but after that it displays wrong item caption like “org.vaadin.appfoundation.authentication.data.User@1db80b” (see attachments).
I debugged my code. I found after method Form.setItemDataSource is executed,
the item caption of TokenField displays wrong result.
My code look more less like this.
public class MailForm extends Form implements
ClickListener{
private TokenField addresSelect;
public MailForm(final PaWebApplication app) {
this.app = app;
setWriteThrough(false);
HorizontalLayout footer = new HorizontalLayout();
setFooter(footer);
addresSelect = new TokenField("宛先");
addresSelect.setStyleName(TokenField.STYLE_TOKENFIELD);
addresSelect.setContainerDataSource(app.getUserDataSource());
addresSelect.setRequired(true);
addresSelect.setFilteringMode(ComboBox.FILTERINGMODE_CONTAINS);
addresSelect.setTokenCaptionPropertyId("name");
addresSelect.setTokenCaptionMode(ComboBox.ITEM_CAPTION_MODE_PROPERTY);
addresSelect.setNewTokensAllowed(false);
addresSelect.setRememberNewTokens(false);
addresSelect.setInputPrompt("type or select tags here");
addresSelect.setWidth(350, UNITS_PIXELS);
addresSelect.setImmediate(true);
addresSelect.addListener(new ValueChangeListener() {
public void valueChange(
com.vaadin.data.Property.ValueChangeEvent event) {
Set<User> tokens = (Set)event.getProperty().getValue();
if (tokens!=null){
String name="";
for (User user : tokens)
name +=user.getName();
getWindow().showNotification("Tokens: "+ name);
}
}
});
setFormFieldFactory(new DefaultFieldFactory() {
@Override
public Field createField(Item item, Object propertyId,
Component uiContext) {
if (propertyId.equals("address")) {
Field field= addresSelect;
return field;
}
});
}
In additon, on valueChange event of TokenField , it displays right user name.