Best way to pass properties between window

I have one view, so when I click in one button I need to open a window and pass an list to this new window, (in this window I will add or remove itens) so I does this:

my click:

public void mostrar() {
    GerenciarJanela.abrirJanela("", 80, 80, new SelecionarDestinatarioImp(destinatarios), 
            new CloseListener(){
        public void windowClose(CloseEvent e) {
            destinatarios.addAll(((SelecionarDestinatarioImp) e.getWindow().getContent()).getDestinatarios());
            txtDestinatarios.setValue(((SelecionarDestinatarioImp) e.getWindow().getContent()).getDestinatarios().toString());

this is my GerenciarJanela

public class GerenciarJanela {
    private final static Logger logger = Logger.getLogger(GerenciarJanela.class.getName());
    public static void abrirJanela(String titulo, Integer altura, Integer largura, Component tela, CloseListener closeListener){
        Window window = new Window(titulo);
        window.setWidth(largura, Unit.PERCENTAGE);
        window.setHeight(altura, Unit.PERCENTAGE);
        if(closeListener != null){
        Class<?> clazz = tela.getClass();        
        Field field;
        try {
            field = clazz.getDeclaredField("window");
            field.set(tela, window);
        } catch (Exception e) {
            logger.log(Level.WARNING,"View sem uma propriedade com o nome window");

and this is my method when I close the window and the method that will be called in my CloseListener

   private List<Grupo> destinatariosSelecionados = null;//Seeted in constructor with the list passed in  mostrar()
    private void fecharJanela(){
    public List<Grupo> getDestinatarios(){
        return this.destinatariosSelecionados;

So when I debug in the line this.window.close() my destinatariosSelecionados have 3 itens, but when execute the method getDestinatarios() the same prop are null

how can I pass and receive properties correctly between windows?


One way I could suggest just to improve your code is the following:

public void mostrar() { final SelecionarDestinatarioImp selDest = new SelecionarDestinatarioImp(destinatarios); GerenciarJanela.abrirJanela("", 80, 80, selDest, new CloseListener(){ @Override public void windowClose(CloseEvent e) { destinatarios.clear(); destinatarios.addAll(selDest.getDestinatarios()); txtDestinatarios.setValue(selDest.getDestinatarios().toString()); }}); } Also I can’t get what you are trying to do with reflection (which is a very unrecommended thing to use anyways).
You didn’t show all the relevant code, so I couldn’t follow the whole call path.

Show more of your SelecionarDestinatarioImp class so that I can maybe spot the bug.