2017-02-23 10 views
0

こんにちは、私はVaadinで初心者です。フォームを作成し、そのPOJOオブジェクトにバインドしようとします。Vaadin with SpringBoot

...Some declaration 

Binder<User> binder = new Binder<>(User.class); 

@Autowired 
public FormUser(UserRepository userRepository, AuthorityRepository authorityRepository){ 
    this.userRepository = userRepository; 
    this.authorityRepository = authorityRepository; 

    authorities = new ListSelect<>("Authorities", authorityRepository.findAll()); 
    authorities.setItemCaptionGenerator(Authority::getAuthority); 

    //Set items 
    username.setIcon(FontAwesome.USER); 
    password.setIcon(FontAwesome.USER_SECRET); 
    saveButton.addClickListener(e -> { 
     userRepository.save(user); 
    }); 

    setSpacing(true); 
    addComponents(username, password, authorities, saveButton); 
    binder.bindInstanceFields(this); 
} 

FormUserを含むビューにアクセスしようとするが、このエラーを取得する:

java.lang.IllegalStateException: Property type 'java.util.Collection' doesn't match the field type 'java.util.Set< dev.gva.model.Authority >'. Binding should be configured manually using converter.

public class Authority{ 
    private Long id; 
    private String authority; 

    getter/setters.. 
} 

はユーザー

を0
public class User{ 
    private Long id; 
    private Collection<Authority> authorities; 

    other fields, getters/setters... 
} 

このコンバータの書き方は?おかげ

+0

'authorities.setConverter(new Converter 、Collection >(){/*...*/})'を試したことがありますか? –

+0

@A.Meierすぐにお試しになります。アドバイスありがとうございます – GVArt

答えて

0

は、代わりにあなたがUser -class以内にあなたのauthorities -attributeため設定またはリストを使用する必要があります変換のための定型的なコードを追加します。その利点は、authoritiesに重複が許されないことです。 リストの違いはです。リストは、インデックスでアクセスできます。あなたはあなたが必要なものを決めるのですが、と設定すれば十分でしょう。

関連する問題