1 2 Previous Next 17 Replies Latest reply on Oct 5, 2007 9:00 PM by Daniel Hinojosa

    Need help updating multi-table dataTable - injecting list?

    Arbi Sookazian Master

      I have successfully created a dataTable based on two different DB tables with a 1:1 relationship. I need to know for CRUD purposes, how will it be possible to update the DB in a JSF/Seam/EJB3 framework this app is currently in.

      Specifically, as in the pic below, you see that the user can change multiple columns in multiple rows for one of the entities (in this case only the CreditCard data can be updated, the Customer data is read-only).

      I've seen in the hotel booking example that you inject the instance of the entity bean that had its setter methods called when the form was submitted in the JSF. In this case, it's not just one row that's being set and updated, it's potentially multiple rows in one transaction/use-case.

      Does Seam support this? If so, how can I persist multiple rows/entity instances in a single transaction? It seems that I must inject the entire List of modified rows/entities into the SFSB first.

      See partial code below:

      CustomerAction.java (SFSB):

       private List<Customers> customers;
       private Customers customer;
       public void find()
       customers = em.createQuery("select c, cc "+
       "from Customers c inner join c.creditCard as cc "+
       "where c.userId = :userId")
       .setParameter("userId", user.getUserId())


       <h:dataTable value="#{customers}" var="customer"
       bgcolor="#F1F1F1" border="10" width="100%" cellpadding="0" cellspacing="0"
       dir="LTR" frame="hsides">
       <f:facet name="header">First Name</f:facet>
       <h:outputText value="#{customer[0].firstName}"/>
       <f:facet name="header">Last Name</f:facet>
       <h:outputText value="#{customer[0].lastName}"/>
       <f:facet name="header">Street Name</f:facet>
       <h:outputText value="#{customer[0].streetName}"/>
       <f:facet name="header">CC #</f:facet>
       <h:inputText value="#{customer[1].creditcardnumber}"/>
       <f:facet name="header">Company Name</f:facet>
       <h:inputText value="#{customer[1].companyname}"/>
       <h:commandButton value="submit" action="#{customerAction.submit}"/>


        1 2 Previous Next