1 Reply Latest reply: Feb 4, 2010 10:48 AM by 843807 RSS

    well can you tell how transfer a List eg. created as bean->jsp(view)

    843807
      well can you tell how transfer a List eg. created as
         public List getLineList() {  // beans.OrderTotals
           return lineList;
         }
       
          public static void addPlant(OrderPlantItem orderPlantItem) {
       
                  lineList.add( orderPlantItem );
          }
      from bean to jsp or from bean to bean or from jsp call to bean, and appear contents on screen or populate a Table(db) ?
      In a Shopping cart web app I must add lineItems first and after Order, to Tables in DB: LineItems and Orders respectively?
      //beans.AddOrder
      ........
      public String updateTables(OrderTotals OrderTotals2, List lineList2) {  // void
           String sqlCommand1= "INSERT INTO Customers VALUES('0011','"+this.getCustName()+"','"+this.getCustStreet()+"','"+this.getCustCity()+"','"+this.getCustState()+"','"+this.getCustZip()+"','2')" ;
           String sqlCommand2= "INSERT INTO Orders VALUES('1011','0011','"+new java.util.Date()+"','"+new java.util.Date()+"',"+OrderTotals2.getTotal()+","+OrderTotals2.getShipping()+","+OrderTotals2.getTax()+")" ;
           String url = "jdbc:odbc:plants"; //dsn plants
           String user="";
           String password="";
           try {
             Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
             conn=DriverManager.getConnection
               ("jdbc:odbc:plants", user, password);
             sttmnt=conn.createStatement();
             sttmnt1=conn.createStatement();
             sttmnt2=conn.createStatement();
                //get statement object
            }catch (Exception exception)  {
         //return (exception.getMessage());
            } // end of catch
              finally {
                  //
              }
       
            try {
       sttmnt.executeUpdate(sqlCommand1);
       
       
      //Object[] lineList2 = lineList5.toArray();
       
              for (int i = 0; i < lineList2.size(); i++)  //lineList2.length
              {
                OrderPlantItem lineItem0 = (OrderPlantItem)lineList2.get(i);
       
                String sqlCommand3= "INSERT INTO OrderDetail VALUES('1011',"+i+1+","+lineItem0.getPlantID()+","+lineItem0.getQty()+","+lineItem0.getSubtotal()+")" ;
        
                  sttmnt2.executeUpdate(sqlCommand3);
              }
                   sttmnt1.executeUpdate(sqlCommand2);
       } // end of try
       catch
      <jsp:useBean id="add" scope="session" class="beans.AddOrder" />
      <jsp:useBean id="AddChoosePlant" scope="session" class="beans.OrderTotals" />
       
      <%
      add.updateTables(AddChoosePlant,AddChoosePlant.getLineList());  
        %>
        • 1. Re: well can you tell how transfer a List eg. created as bean->jsp(view)
          843807
          1)db Q

          in a for body that executes a query like above:
          sttmnt2.executeUpdate(sqlCommand3);
          the
          sttmnt2=conn.createStatement();
          must appear outside loop? is this above correct?

          2)Q:List object data appear in jsp(view) or enter in db-table(model) like cartItems in cart

          When I have a List obj contains cartItems objects (eg shopping cart) already populated in a javabean, and want to appear this data to the next jsp file(view) and then enter them in database table via next confirm.jsp that use a process bean(model), what to do to transfer this List Object?