Melati Shopping Trolley Interface

(c) Paneris 2001 Tim Joyce (timj At


This file describes the Melati ( shopping trolley interface developed by Paneris ( and how to install and set it up. It assumes you have installed Melati and have created your own POEM database/melati application to which you wish to add the Shopping Trolley.

The shopping trolley system is a java package to be used with Melati. Melati is a java servlet based framework for developing HTTP applications using POEM. POEM provides an OO wrapper around an SQL database. Together Melati and POEM provide a RAD toolkit for building web sites.

The Melati Shopping Trolley Interface is designed to provide a flexible abstraction of the basic processes of allowing customers to buy goods on a website. By default, it is not integrated with POEM, and so makes no assumptions about the underlying database implementation. It does provide the following:

  • Ability to add / remove / update items in a shopping trolley (stored in the user's session)
  • Collection of User details
  • Calculation of VAT and delivery charges
  • Connection to a 3rd party site for payment

Because exact implementations of shopping trolleys are notoriously varied, this interface seeks to provide as much flexibility as possible. You can customise your implementation in 2 ways:

  • Writing implementations of 2 abstract classes:
    • and
    • This allows you to decide how to calculate delivery charges etc.
  • Writing templates:
        - Trolley.wm
        - Details.wm
        - Confirm.wm 
        - Order.wm
        - Menu.wm  

The basic process as experienced by the user is fairly typical of any online Shopping experience:

  • Load up the trolley
  • Enter customer details
  • Confirm order
  • Make payment


Preinstallation System Requirements

Install and test Melati from

Download and unzip Melatishopping

Download the latest Melatishopping snapshot from and unzip or untar it. eg:

Unix users type:

  cd /usr/local/
  tar -xzf melatishopping_0.50.tar.gz
  ln -s melati_0.50 melati 

Windows users should use WinZip

Arrange for the Melati Shopping classes and properties files to be accessible to your servlet runner.

For Apache Jserv, this can be done either in the file, by adding a lines


or in your zone .properties file by adding


to the line beginning repositories=

Write your ShoppingTrolley and ShoppingTrolleyItem classes

These should be based on and You will (at least) have to define the following abstract methods. If you don't want to make use of a particular feature, simply "return".


  * Set the Locale for this trolley.
  public Locale getLocale(){}

  * Load a trolley from something persistent.
  public void load(Integer id) {}

  * Save a trolley to something persistent.
  public void save() {}

  * Provide a mechanism for working out if 
  * this order should include a delivery charge.
  public boolean hasDelivery(){}

  * You need to provide some mechanism for calculating the delivery
  * value for the order (item delivery values are calculated individually.
  public double getDeliveryValue() {}

  * Provide a mechanism for working out if 
  * this order should include a discount.
  public boolean hasDiscount() {}

  * If you want to apply a discount to this order, do it here.
  public double getDiscountRate() {}

  * Provide a mechanism for working out if 
  * this order should include VAT (default should be true).
  public boolean hasVAT() {}

  * If you want something to happen (like sending an email) when the user
  * has returned from paying, do it here.
  public void confirmPayment(Melati melati) {}


  * Load in information about this product given an id.  
  * Perhaps this id represents a poem troid?
  protected void load(Integer id){};
  * Work out the cost of delivery for this item.
  public double getDeliveryValue() {}

Specify your classes in

For example, you need to specify the 2 classes you created above:

 # What class implements the shopping trolley = <Your>ShoppingTrolley

 # What class implements the shopping trolley items = <Your>ShoppingTrolleyItem

Modify your Templates

The interface to the Shopping Trolley is defined in the following templates:

 Trolley.wm - The initial page where you can add/remove/edit trolley items 
 Details.wm - Collection of user details
 Confirm.wm - Confirmation of order
 Order.wm - The trolley rendered as text
 Menu.wm - The menu

Link to the Payment Server

There are many companies offering secure payment services. My current personal favorite is You will need to edit Confirm.wm to supply the correct details to your chosen server.

Link back from the Payment Server

If you need to do something (like send an email) following confirmation of payment, define the method in Your

  public void confirmPayment(Melati melati) {}

This will return the template Paid.wm.

Because the callback request (typically) comes from the Payment Server, you will not have the user's shoping trolley (Session) available to them. You will therefor need to get whatever information you require from something persistent.

The alternative is to get the Payment Server to generate the emails (or whatever) for you. Most Payment Servers offer this facility.

Link into Your Application

You can add items to your shopping trolley using the following URL: http://host name /servlet zone / name /Add/product id /

This will load the product with the supplied Troid, using the method:

 load(Integer id){};    in  

Alternatively, supply the price and description as part of the request:


This has obvious security considerations (users can change the price). This mechanism is best used for prototyping or for systems where orders are checked manually before payment is taken (telephone ordering etc).


Included with this distribution are 2 examples:

  • JammyJoes Toyshop ( Source files in lib/
  • Bibliomania ( Source files in lib/