2017-02-23 5 views
0

안녕하세요, 저는 Vaadin에 초보자입니다. 양식을 만들고 POJO 개체에 바인딩하려고합니다.Vaadin with SpringBoot

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.. 
} 

사용자 :

시도가 FormUser이 오류가 포함되어보기에 액세스 할 수

...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); 
} 

0

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

    other fields, getters/setters... 
} 

이 변환기를 작성하는 방법은 무엇입니까? 감사합니다

+0

'authorities.setConverter (새 변환기 <, 모음 () {/*...*/})'을 (를) 설정 했습니까? –

+0

@ A.Meier 조만간 조언 드리겠습니다. – GVArt

답변

0

대신 당신이 User - 클래스 내에 authorities -attribute에 대한 설정 또는 목록를 사용해야 변환에 상용구 코드를 추가. 그 이점은 authorities에 중복이 허용되지 않는다는 것입니다. 의 차이는목록입니다. 목록은 주문되었으며 색인을 통해 액세스 할 수 있습니다. 당신은 당신이 필요로하는 것을 결정하지만, 세트으로 충분할 수도 있습니다.