concept auction in category lift

appears as: uctions, auction, The auction, auctions, n Auction, n auction, Auction, uction, An auction
Lift in Action: The Simply Functional Web Framework for Scala

This is an excerpt from Manning's book Lift in Action: The Simply Functional Web Framework for Scala.

The first common element will be the shopping basket. Each customer using the application will have an associated order that consists of auctions they successfully bid on; it’s the usual shopping cart setup that most users will be familiar with. As users might already be in a bidding war but not actually be on the site when the auction is over, use of Lift’s state machine to ensure that any auctions the users wins while the site isn’t loaded in their browser will be properly attributed to them.

Now that you have the base of the application in place, the next thing to do is construct the frontend so that visiting customers can browse through the auction catalog and access details on any particular auction. By its very nature, an auction is a highly spontaneous affair, so it’s critical to get real-time feedback when other customers bid on the same auction as you, particularly if they placed a higher bid!

An auction is intrinsically a real-time event: users need to see what the highest bid currently is, and see if they’re winning the auction in question. The user experience would be greatly enhanced if each user’s bids were automatically propagated to the other users; the resulting interface then wouldn’t need to be refreshed, and users would receive instant updates whenever someone else makes a successful bid on an item the user is viewing. It would also be good if the user were notified when an auction they had previously bid on but weren’t currently viewing received another bid. Fortunately, Lift provides a mechanism to make this a reality: Comet.

These helper methods either take Auction or Box[Auction] instances and serve as useful assessors for common auction aspects, ensuring that you don’t continually need to unbox auctions throughout your code. You can merely compose the class or object with the AuctionHelpers trait and have these functions automatically.

Listing 4.13. Definition of the AuctionInstanceHelpers trait
trait AuctionInstanceHelpers extends AuctionHelpers { protected def auction: Box[Auction] protected def hasExpired_? : Boolean = hasExpired_?(auction) protected def leadingBid: Double = leadingBid(auction) protected def minimumBid: Double = minimumBid(auction) protected def winningCustomer: NodeSeq = winningCustomer(auction) }

This is a very simple trait that builds on the AuctionHelpers trait, provides an implied Box[Auction], and then calls the methods we just defined in AuctionHelpers. The reason for this is that in both the CometActor and the Details snippet, we’ll want to be accessing a boxed instance of Auction, and as the auction is a member field, we might as well deal with it as an implied value rather than constantly passing it as an argument to methods. This is most certainly a style preference, but composing such a trait is more idiomatic Lift development and thus merits discussion.