[Previous slide] [Next slide] Java and Database Connectivity

Example Jacquard Form

import javax.servlet.*;
import javax.servlet.http.*;
import uk.co.weft.dbutil.*;
import uk.co.weft.htform.*;
import java.util.Stack;

/** an example form which allows you to enter and manipulate WORKSHOP
 *  records */
public class WorkshopForm extends TableWrapperForm
{
    /** Initialise me. Principally, set up my widgets */
    public void init( Context config)
        throws InitialisationException
    {
        table = "WORKSHOP";        // set up my table
        keyField = "Workshop";     // and my primary key

        addWidget( new 
            Widget( "Tutor", "Tutor", 
            "The Tutor of this workshop"));
                // add a simple text widget for the
                // tutor's name

        Widget w = addWidget( new 
            Widget( "Title", "Title", 
            "The title of this wokshop."));
                            // another simple text input fo the title  
        w.setSize( 80);     // which is extra long...
        w.setMandatory( "You must supply a title for this wokshop");
                // and which you must complete before proceding

        addWidget( new 
            SimpleDataMenuWidget( "Venue", "Venue", 
                  "The venue for this workshop",
                  "VENUE", "Venue", "Name"));
                // a menu constructed from another
                // table for the venue
    
        addWidget( new DateWidget( "Date", "Date", 
                   "The date of this workshop"));
                // a date, oddly enough!

        addWidget( new 
           LinkTableWidget( "ATTENDANCE", "Attendees",
                 "People who are expected to take part in this workshop.", 
                 false, 7,
                 "WORKSHOP", "ATTENDEE", "Workshop", 
                 "Attendee", "Name"));
                                // and a link-table widget to set up attendees

        super.init( config);    // finally do my superclass configuration
    }

    /** When a workshop is deleted from the database, we don't want to
     *  leave orphanced attendances hanging about. So drop my
     *  attendance links before dropping me! Note
     *  that you don't need methods like this if the database supports
     *  proper referential integrity checks and triggers - which good
     *  databases do.
     *
     *  @param context the context which contains the identifier of
     *  the record to be dropped
     *  @exception throws DataStoreException if delete fails.
     */
    protected void drop( PageContext context)
        throws DataStoreException, ServletException
    {
        Stack drops = new Stack();
        Object id = context.get( keyField);

        drops.push( "delete from ATTENDANCE " + 
                    "where ATTENDANCE.Workshop = " +
                    id.toString());
                                // it's a stack, so push them in reverse order

        super.drop( context, id, drops);
    }
}

 


give me feedback on this page // show previous feedback on this page