Holy Jeez!  Maybe it's just the way your choosing to think about it that
sounds bad, but persisting UI components to a database is a serious bad
idea.  Like kicking Jesus in the nuts bad.
You need to separate out the portions of the UI that you will be saved to
the database from the actual UI.  By separating things out more you can deal
with them independantly rather than one big ball of mud.  Pull out data you
want to save from UI elements into a POAO - (plain old actionscript object).
 What does this UI represent in terms of your domain?  Is it a Shopping
Cart?  Create a class that represents it a shopping cart.  What goes in a
shopping cart?  An array of LineItems (another class).  Any special offers
being applied?   What are LineItems?  A Quantity, a Product, and Price.

Once you have your model for the shopping chart together then refactor your
ViewStack into a ShoppingChartView that has setter/getter for the
ShoppingCart object.  Override commitProperties to bind your shopping cart
object into the UI controls that make up your ShoppingChartView.  Once
you're done with that then you can begin to save the ViewStack's state in
that POAO.

Now I can ask the ViewStack component to get the ShoppingCart object and it
will return the state of the ViewStack back to me.  On the other side the
setter will bind the ShoppingCart object into the ViewStack component (hence
restoring it's state).  That gives me convenient methods to work with the
component at a higher level, and it gives me a barrier between the SQL
statements/Database code and my component.  So my database interaction can
be moved to some other location in my program, and my component exists
independent of a database.

Once you have the POAO together then you can start to save that object to
your database.  Sounds like you're encountering some null object, but
without a stack trace it's a little hard to point exactly where you're going
wrong.  But, from the sound of it it's just too jumbled up to make heads or
tails of anything.

Charlie


On Wed, Sep 9, 2009 at 10:31 AM, Hepp, Michael W.
<[email protected]>wrote:

>
> Greetings,
>
> I am trying to write a ViewStack with various radio buttons to a local
> database and then retrieve it in its saved (persisted) state but I am not
> having any success. Is it even possible to write/read a ViewStack to a
> database? I can write and retrieve strings, numbers, dates, and arrays, but
> not the ViewStack.
>
> private function writeToDatabase():void{
>         // Type to itemClass
>         item.status = 1;
>         item.date = new Date();
>         item.name = "test quote";
>         item.cartDP = cartDP;
>         item.productData = productVS;
>
>         var params:Array = [ item.status, item.date, item.name,
> item.cartDP, item.productData ]
>         var stmt:String =       "INSERT INTO Quote (status, date, name,
> cartDP, productData)";
>         trace (stmt);
>         sqlConnection.insert( stmt, params );
> }
>
> public function insert( sqlStmt:String, params:Array = null ):void{
>         var sqlInsert:SQLStatement = new SQLStatement();
>         sqlInsert.sqlConnection = sqlConnection;
>
>         //  ADD EVENT LISTENERS
>         sqlInsert.addEventListener(SQLEvent.RESULT, onInsertSuccess);
>         sqlInsert.addEventListener(SQLErrorEvent.ERROR, errorHandler);
>
>         // ASSIGN PARAMETERS
>         if( params ) {
>                 for( var i:int = 0; i < params.length; i++ ) {
>                         sqlInsert.parameters[i] = params[i];
>                 }
>         }
>         sqlInsert.itemClass = ItemTO;
>
>         // EXECUTE SQL ACTION
>         sqlInsert.execute();
> } // END insert()
>
> And this is all written to my local database, but when I read this back in
> I get Error #1009: Cannot access a property or method of a null object
> reference for the ViewStack even though there is data being returned from
> the query. I've even tried turning it into a byteArray:
>
>         var bytes:ByteArray = new ByteArray();
>         bytes.position = 0;
>         bytes.writeObject(productVS);
>
> But when I read it back, even though the ByteArray has data, I can't get it
> back into a ViewStack
>         var bytes:ByteArray = new ByteArray();
>         bytes = event.results[0]["productData"];
>         bytes.position = 0;
>         var newVS:Dictionary = bytes.readObject() as ViewStack;
>
> I am really spinning my wheels on this one and could really use some
> ideas/comments on what I am doing wrong or if this is even possible.
>
> Thanks,
> Mike
>
> -------------------------------------------------------------
> To unsubscribe from this list, simply email the list with unsubscribe in
> the subject line
>
> For more info, see http://www.affug.com
> Archive @ http://www.mail-archive.com/discussion%40affug.com/
> List hosted by FusionLink <http://www.fusionlink.com>
> -------------------------------------------------------------

Reply via email to