Luis Majano Forums Notification: Post to Separating model and view

Title: Separating model and view
Thread: Separating model and view
Forum: Need Help?
Conference: ColdBox
User: bburwick

Hey everyone, I'm using ColdBox and Transfer and I'm wondering the best way for
view code to access data from the model with several levels of nested objects.
A few different possibilities occurred to me, but I'm not sure which (if any) I
should use. Anyone have recommendations?

Three methods I thought of:
1.
Have the event handler just pass the parent object to the view via the request
collection and have the view code parse through it. This couples the view and
the model, but darn it, it seems easier.
2. Have the event handler ask the
model for a nested struct representation of the object and pass that to the view
via the request collection.
3. Just have the model return regular queries to
the event handler and then pass those queries to the view (the view would have
to group the output).

Here's a little more detail about what I'm trying to
do. I can see the post is getting long so you can stop reading if you already
know the answer to my question above (or if you're just bored :slight_smile: When a user
does an order checkout, I want to show the user a "review order" screen with all
the details of their order. I'll try to leave out the irrelevant stuff, but
here are the primary objects I'm working with: Order, OrderItem, Product and
ProductSpecification.

Order has a BillingAddress and a ShippingAddress.
Order has many OrderItems.
OrderItem has properties like 'quantity' and
'productOptionID'.
OrderItem has one Product.
Product has properties like
'name' and 'description'.
Product has many Specifications.
Specification has
properties like 'specName' and 'specValue'.

I want to spit all of this out on
the page. This isn't unusual or complicated, but I'm not sure how to do it in a
new environment. Anyone have ideas? Thanks!

http://www.luismajano.com/forums/index.cfm?event=ehMessages.dspMessages&threadid=68BD76AE-123F-6116-42E944468786E4DF