1 Reply Latest reply on Aug 12, 2010 12:23 AM by hedberg.biz

    Flex 4 data management - how do I approach this?

    hedberg.biz Level 1

      Hi guys, quite an explanation here, hope someone has the patience to read it through

      I'm building an application in Flex 4 that handles an ordering system. I  have a small mySql database and I've written a few services in php to  handle the database.

      Basically the logic goes like this:

      I have tables for customers, products, productGroups, orders, and orderContent

      I have no problem with the CRUD management of the products, orders and  customers, it is the order submission that the customer will fill in  that is giving me headaches:

      What I want is to display the products in dataGrids, ordered by group,  which will be populated with Flex datamanagement via the php-services,  and that per se is no problem. But I also want an extra column in the datagrid that the user can fill in with the amount he wishes to order of that  product. This column would in theory then bind to the db table  "orderContent" via the php services.

      The problem is that you would need to create a new order in the database  first that the data could bind to (orderContent is linked to an order  in the db).

      I do not want to create a new order every time a user enters the page to  look at the products, rather I would like to create the order when a  button is pressed and then take everything from the datagrids on the  page and submit it into the database.

      My idea has been to create a separate one-column datagrid, line it up  next to the datagrid that contains the products and in that datagrid the  user would be able to enter the amount of that product he'd like to  order.

      I've created a valueObject that contains the data I would need for an order:

      Code:
      package valueObjects
      {
        public class OrderAmount
        {
         
          public var productId:int;
          public var productAmount:int;
          public var productPrice:Number;
         
          public function orderAmount()
          {
          }
        }
      }

      My idea was to use a service to get all products from a certain  group, populate an ArrayCollection with the data, then transfer each  object in that ArrayCollection to an instance of the Value Object above,  add the value object to another ArrayCollection that would the be used  as a dataProvider for the one-column datagrid.

       

       

      I've tried to use the results from the automatically generated  serviceResults that retrieve the products for the datagrid and put in a  resultHandler that transfers the valueobjects, however this does not  seem to work.

       


      Basically my question is this:

      Am I approaching this thing completely wrong, or is there a way I can get it to work the way I planned?

      Would I need to create a completely new service request to get the product id:s, and price to populate the one-column datagrid.

      I'll post some code if that would help.

      Thank you if you read this far.
        • 1. Re: Flex 4 data management - how do I approach this?
          hedberg.biz Level 1

          Solved it by creating a Value Object class to  hold all the info needed for each row in the grid and from the php  service that returned all products in a group, I looped through the  result and transfered the data needed into my Value Object.

          I then added each Value Object into an ArrayCollection and made that the dataProvider for the dataGrid.

          No need to use two grids. I forgot how logic things get when you  think of datagrid data just as an ArrayCollection and forget the visual  presentation of it on screen.

          Put in a few itemRenderers and the whole thing is beautiful!