Hi Izak,

you do not have to manage the session for yourself. Tapestry will take care of 
this.

I wrote a example, how your code could be. It is handwritten in notepad, not 
checked and I am new to Tapestry, but I think it should work :)

in hivemind.xml:

<!-- tell tapestry to take care of your order-object in the session -->
<contribution configuration-id="tapestry.state.ApplicationObjects">
        <state-object name="shoppingCard" scope="session">
        <create-instance class="yourPackage.MyShoppingCard"/>
        </state-object>  
</contribution>

your ShoppingCard-Object (the one stored in the session later)

public class MyShoppingCard implements Serializable {

        private Order order = null ;

        public Order getOrder { return this.order ; }

        public void setOrder(Order order) { this.order = order ; }

}


Your order object stored in the card:

public class Order implements Serializable {

        private ArrayList<OrderLineItem> orderLineItems = new 
ArrayList<OrderLineItem>() ;

        public Order() 

        public void addItem(OrderLineItem item) {
                orderLineItems.add(item) ;
        }
        public void setUser( ... 
        ... and so on ... :)
}

in your page.java (to get access to your ShoppingCard object):

@InjectState("shoppingCard")
public abstract MyShoppingCard getShoppingCard() ;

// if you want to check if the ShoppingCard already exists, without creating a 
session:
@InjectStateFlag("shoppingCard")
public abstract boolean getShoppingCardExists() ;


public void addALineItem(OrderLineItem item) {
        // create a session if none exists and/or initialize your order-object 
...
        if (!getShoppingCardExists() || (null==getShoppingCard().getOrder())) 
                getShoppingCard().setOrder(new Order()) ;
        // add a line to the card ...
        getShoppingCard().getOrder().addItem(item) ;
        ...
}


public void saveCard() {
        try {
                
saveTheOrderToDB_or_something_like_this(getShoppingCard().getOrder()) ;
                // now set the order to null, to start with a fresh 
order-object (so the ShoppingCard object may still exits, but without an order 
...
                getShoppingCard().setOrder(null) ;
        } catch ( ......
}

Hope this helps,
Gerald

>
>Hello,
>
>In my application I am saving an "Order" into the user's session. An order
>consists of an
>"OrderCart" which contains a bunch of "OrderLineItem" objects. Now when the
>user creates
>a new order, a new "Order" object is being generated and saved as such in
>the database,
>but as soon as I add items to the "OrderCart" , then the "OrderItems" from
>the previous order are still in the users session.
>
>So basically, I need to clear my "OrderCart" so that when a new order is
>being created, that it keeps the correct "OrderLineItems" associated with
>the corresponding order.
>
>Just a side note : In the "Managing Server Side State" on the Tapestry home
>page, they
>talk about setting the page to "Pristine State". Does that apply to my
>situation?
>
>Thanks,
>
>-- Izak

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to