I have a vaadin UI class with a constructor taking 2 arguments. It builds a simple line with some fields, showing data. In another (parent) UI, I want to embed that first UI (child) multiple times, depending on some data loaded in the parent. So now I have two questions:
- Can I use springs
@Autowired
annotation to inject multiple instances of my child UI to the parent? If yes, how do I do this? - How do I pass arguments to the constructor of my
@Autowired
child class?
I already found out, that I must annotate the constructor of my child class with @Autowired
.
My child UI class with constructor (annotated with @Autowired
)
public class ChildUI {
private String arg1;
private String arg2;
@Autowired
public ChildUI(String arg1, String arg2){
this.arg1 = arg1;
this.arg2 = arg2;
}
}
In my parent class, I want to do something like this (personList is loaded from database):
public class ParentUI {
...
for(Person p : personList){
//inject instance of ChildUI here and pass p.getLastName() to arg1 and p.getFirstName() to arg2
}
...
}
I googled for a while but I did not really find what I was looking for. Maybe I just don't know what keywords to search for. Can maybe someone try to explain what to do?