1 Reply Latest reply on Aug 12, 2008 11:54 PM by jguglielmin

    Passing arguments to session scoped bean fails ??

    ixtlan
      Hi !

      I have the following code:

      A bean that lists all Patients

      `@Stateful
      @Scope(SESSION)
      @Name("viewPatientsHistory")
      public class ViewPatientsHistoryAction implements ViewPatientsHistory {
      .
      .
      .
             @DataModel
              private List<PatientHistory> patientsHistory;

              @DataModelSelection("patientsHistory")
              private PatientHistory selectedPatientHistory;

      @Factory("patientsHistory")
              public void findPatientsHistory() {
                      patientsHistory = em.createQuery("select p from PatientHistory p").getResultList();
      }


      `

      A facelet that among other has this code:

      `<ice:dataTable id="patients" value="#{patientsHistory}" var="patH" rows="25" sortColumn="#{viewPatientsHistory.sortColumnName}" sortAscending="#{viewPatientsHistory.ascending}">
                                                             
      .
      .
      .
      <ice:commandButton  value="View Details" action="#{patientHistoryView.viewPatientHistory(patH)}"/>       
      `

                                                                      `
      And another bean


      `
      @Stateless
      @Scope(PAGE)
      @Name("patientHistoryView")
      public class PatientHistoryViewAction implements PatientHistoryView {

              @In(create = true)
              private PatientHistory patientHistory;
             
              @PersistenceContext
              EntityManager em;

              //the most important place
              public void viewPatientHistory(PatientHistory patHist) {
                      em.merge(patHist);
                      this.patientHistory = patHist;
                      System.out.println(patientHistory.getBirth());
                      System.out.println(patientHistory.getId());
              }
      `

      And when method viewPatientHistory is called object patientHistory is OK, it's OK inside the method body, but as soon as it leaves method body object is cleared, if not for   |@In(create = true)|  I would get a null pointer exception, but since this annotation is here I get jus an empty object.

      Any ideas ??


        • 1. Re: Passing arguments to session scoped bean fails ??
          jguglielmin

          PAGE context is difficult/tricky with ICEfaces.  You have to follow the jsf lifecycle to see that each ajax partialSubmit will actually submit the form and based on the definition of page context, the parameters are cleared to begin a new jsf lifecycle.  You would have to show your complete facelet markup for me to be sure, but this is probably your problem.  You might want to create a destroy method and annotate it, put some logging in and you will see when the bean is destroyed using this context.  A solution could be either to create smaller forms on the same page or to use CONVERSATION scope, depending on your requirements.  As well, you can turn any partialSubmit's off and just submit the form like regular jsf....many choices.