jacquard 1.12.0 by The Web Engineering Factory and Toolworks

uk.co.weft.htform
Class TableWrapperForm

java.lang.Object
  extended byjavax.servlet.GenericServlet
      extended byjavax.servlet.http.HttpServlet
          extended byuk.co.weft.maybeupload.MaybeUploadServlet
              extended byuk.co.weft.htform.Servlet
                  extended byuk.co.weft.htform.WithExceptionHandlerServlet
                      extended byuk.co.weft.htform.Page
                          extended byuk.co.weft.htform.Form
                              extended byuk.co.weft.htform.AuthenticatedForm
                                  extended byuk.co.weft.htform.TableWrapperForm
All Implemented Interfaces:
DocumentGenerator, ResourceConsumer, java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
Direct Known Subclasses:
AutoForm, Event, ServletForm, WidgetForm

public abstract class TableWrapperForm
extends AuthenticatedForm

An HTML form wrapped around a single database table to allow editing of individual records. The basic component of a database editing suite. This class (and consequently all servlets which are subclasses of this class) know about the following configuration parameters, in addition to those handled by Servlet:

allow_delete
Boolean: whether or not to allow records to be deleted. Optional. Defaults to true.
confirm_before_delete
Boolean: whether or not to require confirmation before records are deleted. Note that if allow_delete is false, confirm_before_delete is inoperative. Optional. Defaults to true.
on_drop_redirect
String: URL to redirect to following a successful drop. Optional. No default (i.e. defaults to this Servlet).
on_store_redirect
String: URL to redirect to following a successful store. Optional. No default (i.e. defaults to this Servlet).

Version:
$Revision: 1.64.4.7 $ This revision: $Author: simon $
Author:
Simon Brooke
See Also:
Serialized Form

Field Summary
protected  boolean allowDelete
          Whether the data item I represent can be deleted
protected  boolean confirmBeforeDelete
          Whether or not to use two-stage 'confirmed' delete
static java.lang.String confirmDeletionToken
          Deprecated. use CONFIRMDELETIONTOKEN
static java.lang.String CONFIRMDELETIONTOKEN
          a magic token to select the really delete stuff
static java.lang.String deletedToken
          Deprecated. use DELETEDTOKEN
static java.lang.String DELETEDTOKEN
          The magic token to say we've deleted the context
protected  ActionWidget deleteWidget
          The delete widget, created at instantiation time.
protected  java.lang.String identField
          a field in this table with user-identifying information
protected  Widget identWidget
          A hidden widget to pass through my identifier.
protected  java.lang.String keyField
          the primary key field in this table
protected  WidgetSet maybeDeleteWidgets
          An alternate set of widgets to be used for deletion if we use two-stage
protected  java.lang.String onDropRedirect
          The URL to redirect to following a successful drop
static java.lang.String ONDROPREDIRECTCONFIGTOKEN
          A token on which I shall look in my configuration for a URL to redirect to following a successful store
protected  java.lang.String onStoreRedirect
          The URL to redirect to following a successful store
static java.lang.String ONSTOREREDIRECTCONFIGTOKEN
          A token on which I shall look in my configuration for a URL to redirect to following a successful store
static java.lang.String storedToken
          Deprecated. use STOREDTOKEN
static java.lang.String STOREDTOKEN
          The magic token to say we've stored the context
static java.lang.String STOREFAILEDTOKEN
          The magic tokent to say we've failed to store the context
static java.lang.String storeFailToken
          Deprecated. use STOREFAILEDTOKEN
protected  java.lang.String table
          the table this form populates.
protected  TableDescriptor tableDescriptor
          a descriptor for that table
protected  ActionWidget updateWidget
          The update widget, created at instantiation time.
 
Fields inherited from class uk.co.weft.htform.AuthenticatedForm
allowLogout, ALLOWLOGOUTCONFIGTOKEN, AUTHENTICATEDUSERMAGICTOKEN, authenticator, AUTHENTICATORCLASSMAGICTOKEN, authentificationWidgets, logoutPrompt, LOGOUTPROMPTCONFIGTOKEN, logoutWidget, onLogoutRedirect
 
Fields inherited from class uk.co.weft.htform.Form
action, actionExecutedToken, ACTIONEXECUTEDTOKEN, auxiliaries, contextMenuMagicToken, CONTEXTMENUMAGICTOKEN, cssHelp, CSSHELP, cssPrompt, CSSPROMPT, defaultScriptBase, mandatoryPrompt, MIN_WIDGETS, onloadFunctionToken, ONLOADFUNCTIONTOKEN, optionalPrompt, selectedWidgetSetMagicToken, SELECTEDWIDGETSETMAGICTOKEN, showHeadline, submitMethod, SUBMITMETHODCONFIGTOKEN, SUBMITMETHODGET, SUBMITMETHODPOST, validationWhingeToken, VALIDATIONWHINGETOKEN, whingeHeader, widgets, widgetSets
 
Fields inherited from class uk.co.weft.htform.Page
DOCTYPECONFIGTOKEN, dynamicFootInclude, dynamicHeadInclude, footInclude, footIncludeURL, headInclude, headIncludeURL, imageUrlBase, layout, printStylesheet, PRINTSTYLESHEETCONFIGTOKEN, stylesheet, STYLESHEETCONFIGTOKEN, title, titleMagicToken, TITLEMAGICTOKEN
 
Fields inherited from class uk.co.weft.htform.WithExceptionHandlerServlet
EXCEPTIONHANDLERCLASSCONFIGTOKEN
 
Fields inherited from class uk.co.weft.htform.Servlet
calendar, conf, contentType, CONTENTTYPECONFIGTOKEN, cookieDomain, cookiePath, COOKIESCONFIGTOKEN, cookieTTL, dbPassword, dbUrl, dbUsername, debug, DEBUGCONFIGTOKEN, driverName, embedded, here, identity, localeMagicToken, LOCALEMAGICTOKEN, outputStreamMagicToken, OUTPUTSTREAMMAGICTOKEN, parsePathInfo, PATHINFOMAGICTOKEN, ready, redirectMagicToken, REDIRECTMAGICTOKEN, requestMagicToken, REQUESTMAGICTOKEN, resourceBundleName, responseMagicToken, RESPONSEMAGICTOKEN, servletMagicToken, SERVLETMAGICTOKEN, sessionMagicToken, SESSIONMAGICTOKEN, USEHTTPSCONFIGTOKEN, zone
 
Fields inherited from class uk.co.weft.maybeupload.MaybeUploadServlet
allowOverwrite, maxUpload, saveUploadedFilesToDisk, silentlyRename, uploadDir, uploadDirPath, uploadDirURL
 
Fields inherited from interface uk.co.weft.htform.ResourceConsumer
RESOURCEBUNDLEMAGICTOKEN
 
Constructor Summary
TableWrapperForm()
           
 
Method Summary
protected  void defaultActionHandler(Context context, Context whinges)
          The default action of a table wrapper form is to fetch the data for the current record from its table, provided there is a value for keyField in the context and the authenticator is happy.
protected  void drop(Context context)
          Wrap the deletion of objects in a method so that it can be specialised to do any tidy-up e.g.
protected  void drop(Context context, java.lang.Object id, java.util.Stack queries)
          a wrapper round drop to allow an arbitrary number of SQL queries to be evaluated first -- intended to allow the dropping of link-table or dependent records.
protected  void drop(Context context, java.lang.Object id, java.lang.String query)
          a wrapper round drop to allow an arbitrary SQL query to be evaluated first -- intended to allow the dropping of link-table or dependent records.
protected  void fetch(Context context)
          Pull my values out of the database and use them to populate me.
protected  TableDescriptor getDescriptor(Context c)
          Get my table descriptor, first caching it if necessary.
protected  java.lang.String getTitle(Context context)
          construct and return a suitable title for this form.
protected  java.lang.String identify(Context context)
          produce a string identifying this record, by printing the value of the field indicated by the identField iv.
protected  java.lang.Object inferKey(Context context)
          find the value of my keyfield in the context; if it's not in the context itself then assume what's in the pathinfo part is the keyfield, possibly with '.html' appended.
 void init(Context config)
          My initialiser; sets up the Id widget.
protected  void logout(Context c)
          Set my keyfield value to null so that I don't try to refetch values from the database over my now non-existent connection
protected  void makeReady(Context context)
          Nasty gotcha: we create the identity widget in init, at which time we don't know the name of the key field, because sub-class inits may call superclass inits first...
protected  boolean store(Context context)
          Store the current context into my table descriptor.
protected  boolean store(Context context, java.sql.Connection db)
          Store the current context into my table descriptor.
 
Methods inherited from class uk.co.weft.htform.AuthenticatedForm
login
 
Methods inherited from class uk.co.weft.htform.Form
addAuxiliary, addWidget, doBody, doHead, doHeadBodySep, fixupMagicValues, generate, getLayout, getNextActionURL, getSelectedWidgetSet, getTransformURL, getWidgetSetByName, handleAction, hasWidgets, postForm, postProcess, preForm, preProcess, selectNextWidgetSet, setContextMenuQuery
 
Methods inherited from class uk.co.weft.htform.Page
doFoot, doFoot, generateContent, getFootInclude, getFootIncludeURL, getFootIncludeURL, getHeadInclude, getHeadIncludeURL, getHeadIncludeURL, getStylesheet, getStylesheets, getTables, getTitle, outputRedirectBlock, readStringFromURL
 
Methods inherited from class uk.co.weft.htform.WithExceptionHandlerServlet
whinge, whinge, whinge
 
Methods inherited from class uk.co.weft.htform.Servlet
addCookie, addCookie, coerceCookiesToContext, coerceToContext, coerceToContext, coerceToContext, coerceToContext, coerceToUrl, createContext, doGet, doPost, getCalendar, getContentType, getDebug, getLocale, getOutputStream, getResource, getResourceString, getServletInfo, grs, grs, handleCookies, handleRedirect, init, setCookieValues, storeOnSession
 
Methods inherited from class uk.co.weft.maybeupload.MaybeUploadServlet
doDelete, doHead, doOptions, doPut, doTrace, getUploadDir, getUploadURL, service
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface uk.co.weft.domutil.DocumentGenerator
destroy
 

Field Detail

CONFIRMDELETIONTOKEN

public static final java.lang.String CONFIRMDELETIONTOKEN
a magic token to select the really delete stuff

See Also:
Constant Field Values

STOREDTOKEN

public static final java.lang.String STOREDTOKEN
The magic token to say we've stored the context

See Also:
Constant Field Values

STOREFAILEDTOKEN

public static final java.lang.String STOREFAILEDTOKEN
The magic tokent to say we've failed to store the context

See Also:
Constant Field Values

DELETEDTOKEN

public static final java.lang.String DELETEDTOKEN
The magic token to say we've deleted the context

See Also:
Constant Field Values

confirmDeletionToken

public static final java.lang.String confirmDeletionToken
Deprecated. use CONFIRMDELETIONTOKEN

a magic token to select the really delete stuff

See Also:
Constant Field Values

storedToken

public static final java.lang.String storedToken
Deprecated. use STOREDTOKEN

The magic token to say we've stored the context

See Also:
Constant Field Values

storeFailToken

public static final java.lang.String storeFailToken
Deprecated. use STOREFAILEDTOKEN

The magic tokent to say we've failed to store the context

See Also:
Constant Field Values

deletedToken

public static final java.lang.String deletedToken
Deprecated. use DELETEDTOKEN

The magic token to say we've deleted the context

See Also:
Constant Field Values

ONSTOREREDIRECTCONFIGTOKEN

public static final java.lang.String ONSTOREREDIRECTCONFIGTOKEN
A token on which I shall look in my configuration for a URL to redirect to following a successful store

See Also:
Constant Field Values

ONDROPREDIRECTCONFIGTOKEN

public static final java.lang.String ONDROPREDIRECTCONFIGTOKEN
A token on which I shall look in my configuration for a URL to redirect to following a successful store

See Also:
Constant Field Values

deleteWidget

protected ActionWidget deleteWidget
The delete widget, created at instantiation time. To override the default updateWidget, a specialisation must set updateWidget to an instantiation of an ActionWidget before calling super.init()


updateWidget

protected ActionWidget updateWidget
The update widget, created at instantiation time. To override the default updateWidget, a specialisation must set updateWidget to an instantiation of an ActionWidget before calling super.init()


identField

protected java.lang.String identField
a field in this table with user-identifying information


keyField

protected java.lang.String keyField
the primary key field in this table


onDropRedirect

protected java.lang.String onDropRedirect
The URL to redirect to following a successful drop


onStoreRedirect

protected java.lang.String onStoreRedirect
The URL to redirect to following a successful store


table

protected java.lang.String table
the table this form populates. Must be established at initialisation time and never changed during the lifetime of the servlet instance.


tableDescriptor

protected TableDescriptor tableDescriptor
a descriptor for that table


identWidget

protected Widget identWidget
A hidden widget to pass through my identifier.


maybeDeleteWidgets

protected WidgetSet maybeDeleteWidgets
An alternate set of widgets to be used for deletion if we use two-stage


allowDelete

protected boolean allowDelete
Whether the data item I represent can be deleted


confirmBeforeDelete

protected boolean confirmBeforeDelete
Whether or not to use two-stage 'confirmed' delete

Constructor Detail

TableWrapperForm

public TableWrapperForm()
Method Detail

init

public void init(Context config)
          throws InitialisationException
My initialiser; sets up the Id widget.

Specified by:
init in interface DocumentGenerator
Overrides:
init in class AuthenticatedForm
Throws:
InitialisationException

getDescriptor

protected TableDescriptor getDescriptor(Context c)
                                 throws DataStoreException,
                                        javax.servlet.ServletException
Get my table descriptor, first caching it if necessary. The caching is intended to improve performance but depends on (i) the table this servlet looks at not beeing changed during its instantiation, and (ii) the table structure of the underlying database not being changed during a servlets instantiation.

Throws:
DataStoreException
javax.servlet.ServletException

getTitle

protected java.lang.String getTitle(Context context)
construct and return a suitable title for this form.

Overrides:
getTitle in class Form
Returns:
the title

defaultActionHandler

protected void defaultActionHandler(Context context,
                                    Context whinges)
                             throws java.lang.Exception
The default action of a table wrapper form is to fetch the data for the current record from its table, provided there is a value for keyField in the context and the authenticator is happy.

Overrides:
defaultActionHandler in class Form
Parameters:
context - the context for this service
whinges - a context for collecting exceptions thrown by widgets; the keys should be the names of widgets throwing exceptions, the values the exceptions thrown
Throws:
java.lang.Exception

drop

protected void drop(Context context)
             throws DataStoreException,
                    javax.servlet.ServletException
Wrap the deletion of objects in a method so that it can be specialised to do any tidy-up e.g. of link tables. Specialisations should call super() to drop the object; if you don't want objects dropped don't include a delete button! This is the version of drop which really gets called, so this is the one to specialise

Throws:
DataStoreException
javax.servlet.ServletException

drop

protected void drop(Context context,
                    java.lang.Object id,
                    java.lang.String query)
             throws DataStoreException,
                    javax.servlet.ServletException
a wrapper round drop to allow an arbitrary SQL query to be evaluated first -- intended to allow the dropping of link-table or dependent records. To use this: specialise the two arg drop( Context, Object) and in that specialisation call three-arg super.drop( Context, Object, String)

Throws:
DataStoreException
javax.servlet.ServletException

drop

protected void drop(Context context,
                    java.lang.Object id,
                    java.util.Stack queries)
             throws DataStoreException,
                    javax.servlet.ServletException
a wrapper round drop to allow an arbitrary number of SQL queries to be evaluated first -- intended to allow the dropping of link-table or dependent records. To use this: specialise the two arg drop( Context, Object) and in that specialisation call three-arg super.drop( Context, Object, Stack).

Parameters:
context - the context in which this drop is being performed
id - the id of the object to be dropped
queries - a stack of SQL queries to be executed before the drop is performed. If any of the queries passed fails, the drop will be aborted and a DataFormatException thrown.
Throws:
throws - a DataFormatException if any of the passed queries fails; the drop has been aborted.
throws - a DataStoreException if the delete fails or any other more general database failure occurs
DataStoreException
javax.servlet.ServletException

fetch

protected void fetch(Context context)
              throws DataStoreException,
                     javax.servlet.ServletException
Pull my values out of the database and use them to populate me. But! Wait! What if I'm not yet authenticated? Why, then don't

Parameters:
context - the context for this service
Throws:
DataStoreException - usually indicates user is not logged in
javax.servlet.ServletException
Since:
Jacquard 1.8

identify

protected java.lang.String identify(Context context)
produce a string identifying this record, by printing the value of the field indicated by the identField iv. May be overridden.


inferKey

protected java.lang.Object inferKey(Context context)
find the value of my keyfield in the context; if it's not in the context itself then assume what's in the pathinfo part is the keyfield, possibly with '.html' appended. If it is, put it into the context

Parameters:
context - the context of this service
Returns:
the key inferred
Since:
Jacquard 1.10.9, returns Object not String

logout

protected void logout(Context c)
Set my keyfield value to null so that I don't try to refetch values from the database over my now non-existent connection

Overrides:
logout in class AuthenticatedForm

makeReady

protected void makeReady(Context context)
                  throws DataStoreException,
                         javax.servlet.ServletException
Nasty gotcha: we create the identity widget in init, at which time we don't know the name of the key field, because sub-class inits may call superclass inits first... Better if they don't, but this makes sure.

Overrides:
makeReady in class Form
Throws:
DataStoreException
javax.servlet.ServletException

store

protected boolean store(Context context)
                 throws DataStoreException,
                        javax.servlet.ServletException
Store the current context into my table descriptor. Return whether or not we actually did it. Specialisations may do sanity checking and then decide not to store it! Note that this is simply a wrapper around store( Context, null)

Parameters:
context - a Context containing the data to store
Returns:
true if the store was successful, else false
Throws:
DataStoreException
javax.servlet.ServletException

store

protected boolean store(Context context,
                        java.sql.Connection db)
                 throws DataStoreException,
                        javax.servlet.ServletException
Store the current context into my table descriptor. Return whether or not we actually did it. Specialisations may do sanity checking and then decide not to store it!

Parameters:
context - a Context containing the data to store
db - a database connection for transactions
Returns:
true if the store was successful, else false
Throws:
DataStoreException
javax.servlet.ServletException

jacquard 1.12.0 by The Web Engineering Factory and Toolworks