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(){
@Override
public void windowClose(CloseEvent e) {
destinatarios.clear();
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.setCaption(titulo);
window.setWidth(largura, Unit.PERCENTAGE);
window.setHeight(altura, Unit.PERCENTAGE);
window.setModal(true);
if(closeListener != null){
window.addCloseListener(closeListener);
}
Class<?> clazz = tela.getClass();
Field field;
try {
field = clazz.getDeclaredField("window");
field.setAccessible(true);
field.set(tela, window);
} catch (Exception e) {
logger.log(Level.WARNING,"View sem uma propriedade com o nome window");
}
window.setContent(tela);
UI.getCurrent().addWindow(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(){
this.destinatariosSelecionados.clear();
this.destinatariosSelecionados.addAll(this.destinatariosSelecionadosContainer.getItemIds());
this.window.close();
}
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?
tks