0
votes

I have a form where I have a button, when I click on that button, a Dialog opens to select a value and then my dialog close.

But, doing this my Bean (@ViewScoped) is called again (re-instantiated) and I lose my information that I previous entered on page.

I searched and I found a similar behaviour (http://forum.primefaces.org/viewtopic.php?f=3&t=38235) but no answer.

I initialize my bean with constructor but I don't know if this is the problem.

@ManagedBean(name="exameBean")
@ViewScoped
public class ExameBean implements Serializable {

public ExameBean(){
    exame = new Exame();
    exames = new ArrayList<Exame>();
    }

public void selecionaPaciente() {
    RequestContext.getCurrentInstance().openDialog("/pages/SelecionaPaciente");
}

 public void retornaPaciente(Paciente paciente) {
    RequestContext.getCurrentInstance().closeDialog(paciente);
}

 public void pacienteSelecionado(SelectEvent event) {
        exame.setPaciente((Paciente) event.getObject());

 }

}

SelecionaPaciente.xhtml

  <p:column headerText="Selecionar">
                    <p:commandButton icon="ui-icon-search" actionListener="#{exameBean.retornaPaciente(lista)}" />
                </p:column>
1
That will happen if you restart the view scope. It will be restarted if you tell JSF to create a new view. That will happen if you e.g. return a string from action method for navigation. Did you do that?BalusC
@BalusC I edited my post to put my page that represent dialog return and my bean methods that openDialog, CloseDialog and set values. What you think?gustavomr

1 Answers

0
votes

May you need to use @SessionScoped, when you use @ViewScoped and show a dialog, you lose the actual instance of you MB. I had the same problem today and i solved using a init method annoted with @PostConstruct (To Load all my data ) and annotate with @SessionScoped to use and manage my data loaded from init().