3 Replies Latest reply on Aug 27, 2007 10:30 AM by sjmenden

    how to use DataModelSelectionIndex correctly ?(newbie questi

    guiltyxsin

      Hi,

      Trying to use the DataModelSelectionIndex to pick up particular row of data and use it to do another query from other Action.java. I am not sure if I have done it right or not. I just can't get the data from the database.

      this is what I have done. Have been stuck on it for a while. Appreciate any help.

      @DataModel
      private List<Customer > customers;
      @DataModelSelectionIndex
      private int customerIndex;
      
      @Out(required=false)
      private Customer customer;
      
      @Factory("customers")
      public void findCustomers()
      {
       customers = em.createQuery("select c from customer c").getResultList();
       }
      
      public String selectcustomer()
      {
       setcustomer();
       return("selected");
      }
      
      public void setcustomer()
      {
       customer= customers.get(customerIndex);
      }
      


      And I inject customer on the other Action.java and use it to query for related data. but it doesn't work. Am I doing it wrong?

      Here's the code for second Action.java

      @In
      private Customer customer;
      
      @DataModel
      private List<Result> results;
      
      public void getResult()
      {
      
      results = em.createQuery("select r from Result r where r.subscription_id = :SID")
      .setParameter("SID", patient.getId())
      .getResultList();
      
      }
      


      build and deploy successfully but just not returning anything from getResult, a blank page. I have no idea why.

      Regards,
      Andy