Custom Tags That Encapsulate Business Rules


It's often helpful to create custom tags to represent the business rules or logic your application needs to enforce or adhere to. After these custom tags are written correctly, you can rest assured that your application won't violate the corresponding business rules.

For instance, looking at the tables in the ows example database, it's easy to see that several tables will be involved when someone wants to place an order from Orange Whip Studios' online store. For each order, a record will be added to the MerchandiseOrders table, and several records can be added to the MerchandiseOrdersItems table (one record for each item the user has in the shopping cart). In addition, you will need to verify the user's credit-card number and perhaps send a confirmation email as an acknowledgment of the user's order. In a real-world application, you might also need to decrease the current number of items on hand after the order has been placed, and so on.

You could place all those steps in a single custom tag. It could be called something such as <cf_PlaceMerchandiseOrder> and take a few simple and easily understood parameters that represent everything necessary to complete an order successfully. The tag might look like this when used in code:

 <!--- Place order for selected items and get new Order ID ---> <cf_PlaceMerchandiseOrder  contact  merchIDList="2,6,9"  shipToCurrentAddress="Yes"  sendReceiptViaEmail="Yes"  returnVariable="NewOrderID"> 

In fact, a version of the <cf_PlaceMerchandiseOrder> tag is developed in Chapter 28, "Online Commerce."



Macromedia Coldfusion MX 7 Web Application Construction Kit
Macromedia Coldfusion MX 7 Web Application Construction Kit
ISBN: 321223675
EAN: N/A
Year: 2006
Pages: 282

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net