com.waveset.ui.util
Class GenericEditForm

java.lang.Object
  extended bycom.waveset.ui.util.PageProcessor
      extended bycom.waveset.ui.util.GenericEditForm
Direct Known Subclasses:
GenericNoButtonEditForm

public class GenericEditForm
extends PageProcessor

An implementation of PageProcessor that supports the editing of any object that can expose itself as a GenericObject "view" with a Form object that describes the layout of the page.

This can serve as the foundation for many editing pages. The class has a number of methods that are called during normal control flow to allow sublcasses to insert custom behavior.


Field Summary
static java.lang.String CMD_CANCEL
           
static java.lang.String CMD_OK
           
static java.lang.String CMD_RECALCULATE
           
static java.lang.String CMD_RECALCULATE_AND_VALIDATE
           
static java.lang.String CMD_SAVE
          Command button identifiers.
static java.lang.String CMD_SAVE_NO_VALIDATE
           
static java.lang.String code_id
           
static java.lang.String FORM_BUTTON
          The name of a magic post data parameter that may be used to hold a form button name distinct from the command name.
static java.lang.String URL_GENERATE
          A special URL that can be returned from the preProcess method to indicate that we should skip processing and go directly to form generation.
 
Fields inherited from class com.waveset.ui.util.PageProcessor
_command, _trace, trace
 
Constructor Summary
GenericEditForm()
          Create the edit form.
 
Method Summary
 void addButtons(com.waveset.ui.util.html.HtmlPage page)
          Add the standard button and extended button sets.
 void addExtendedButtons(com.waveset.ui.util.html.Panel panel)
          Called by generate() to let the subclass add command buttons to the bottom of the form.
 void assimilatePostData()
          Called immediately after post data for items defined in the Form have been assimilated back into the _view.
 ViewSource createViewSource()
          Create a new view source.
 com.waveset.ui.util.html.HtmlPage generate()
          Generate the form.
 FormConverter getFormConverter()
          Build a FormConverter if we don't already have one.
 java.lang.Object getMessage(java.lang.Throwable t, java.util.Locale locale)
           
 java.lang.String getMessageConfirmationButtonText()
          Return the text to be displayed in the confirmatino button when status messages are displayed after a SAVE command.
 java.lang.String getNiceMessage(java.lang.Throwable t, java.util.Locale locale)
          Get the localized message from an excpetion.
 java.lang.Object getNiceMessageObject(java.lang.Throwable t, java.util.Locale locale)
          Get the localized message from an excpetion.
 java.lang.String getNicerLockMessage(java.lang.Throwable t, java.util.Locale locale)
           
 GenericObject getView()
          Convenience method to get the view from the view source.
 ViewSource getViewSource()
          Return the known ViewSource object, or create a new one.
 boolean isAdminSubject(LighthouseContext context)
          Helper method that checks to see if an Administrator is logged in to the session.
 java.lang.String postProcess(java.lang.String nextURL)
          Called immediately after all processing has finished, and we're about to calculate the next URL.
 java.lang.String preProcess()
          Called immediately prior to processing.
 java.lang.String process(RequestState reqState)
          Process the form produced by the generate() method.
 java.lang.String processCommand()
          Process an extended command.
 java.lang.String processResult(WavesetResult result)
          This will walk a WavesetResult object and set the _error attributes.
protected  void refreshViewIfNeeded()
           
 void setAlwaysRefresh(boolean b)
          Set the option to always refresh the view rather than cache it in the HttpSession.
 void setOption(java.lang.String name, java.lang.Object value)
          Set a view option.
 void setResultAttribute(java.lang.String name)
           
 void setSessionAttribute(java.lang.String name)
          Set the HttpSession attribute used to store this view.
 void setViewId(java.lang.String s)
          Called to specify the view id of the object to create or edit.
 void setViewSource(ViewSource vs)
          Allow a ViewSource to be given to us.
 
Methods inherited from class com.waveset.ui.util.PageProcessor
addComment, addComments, addError, addErrors, addMessage, addMessages, clearErrors, clearMessages, generateHTML, generateHTML, generateHTML, getAppBaseURL, getCancelURL, getCommand, getComments, getErrors, getHtmlFormName, getMessages, getNextURL, getObjectRef, getParameter, getPostURL, getRequestState, getSubTitle, getTitle, isCommand, isErrors, println, setAppBaseURL, setCancelURL, setCommand, setHiddenId, setHtmlFormName, setNextURL, setPostURL, setRequestState, setSubTitle, setTitle, setTrace, stripDirectory, transferPageState
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

code_id

public static final java.lang.String code_id
See Also:
Constant Field Values

CMD_SAVE

public static final java.lang.String CMD_SAVE
Command button identifiers. These are the default buttons that most forms may have. You can override these with the addButtons() method. Recalculate isn't added by default, but FormConverter may put it there.

See Also:
Constant Field Values

CMD_CANCEL

public static final java.lang.String CMD_CANCEL
See Also:
Constant Field Values

CMD_OK

public static final java.lang.String CMD_OK
See Also:
Constant Field Values

CMD_RECALCULATE

public static final java.lang.String CMD_RECALCULATE
See Also:
Constant Field Values

CMD_RECALCULATE_AND_VALIDATE

public static final java.lang.String CMD_RECALCULATE_AND_VALIDATE
See Also:
Constant Field Values

CMD_SAVE_NO_VALIDATE

public static final java.lang.String CMD_SAVE_NO_VALIDATE
See Also:
Constant Field Values

FORM_BUTTON

public static final java.lang.String FORM_BUTTON
The name of a magic post data parameter that may be used to hold a form button name distinct from the command name.

See Also:
Constant Field Values

URL_GENERATE

public static final java.lang.String URL_GENERATE
A special URL that can be returned from the preProcess method to indicate that we should skip processing and go directly to form generation.

See Also:
Constant Field Values
Constructor Detail

GenericEditForm

public GenericEditForm()
Create the edit form. You normally follow this with calls to the PageProcessor setter methods and should then call setViewId() to specify what we're editing.

Method Detail

setViewId

public void setViewId(java.lang.String s)
               throws WavesetException
Called to specify the view id of the object to create or edit. If the string is just a view type name, a new view will be created. If the string contains both a view type and an object id (e.g. User:jlarson) a view of an existing object will be checked out.

Throws:
WavesetException

setOption

public void setOption(java.lang.String name,
                      java.lang.Object value)
               throws WavesetException
Set a view option.

Throws:
WavesetException

setSessionAttribute

public void setSessionAttribute(java.lang.String name)
                         throws WavesetException
Set the HttpSession attribute used to store this view.

Throws:
WavesetException

setAlwaysRefresh

public void setAlwaysRefresh(boolean b)
                      throws WavesetException
Set the option to always refresh the view rather than cache it in the HttpSession. Typically used only for "list" views that display the results of a query.

Throws:
WavesetException

setResultAttribute

public void setResultAttribute(java.lang.String name)

setViewSource

public void setViewSource(ViewSource vs)
Allow a ViewSource to be given to us. Usually the ViewSource will be a GenericViewSource that we create, or one defined by a subclass and returned by getViewSource(). In some test environments, its easier to create a custom ViewSource without subclassing GenericEditForm, then assign it.


getViewSource

public ViewSource getViewSource()
                         throws WavesetException
Return the known ViewSource object, or create a new one. This is typically not overloaded, you usually overload createViewSource, and let this maintain the cache.

Throws:
WavesetException

createViewSource

public ViewSource createViewSource()
                            throws WavesetException
Create a new view source. Overload this if you want something other than the default.

Throws:
WavesetException

preProcess

public java.lang.String preProcess()
                            throws WavesetException
Called immediately prior to processing. We will have a ViewSource at this point, but not a view.

Throws:
WavesetException

assimilatePostData

public void assimilatePostData()
                        throws WavesetException
Called immediately after post data for items defined in the Form have been assimilated back into the _view. If the subclass has added any fields beyond those defined by the Form, the subclass must also overload this to get the posted data back into the view.

Throws:
WavesetException

processCommand

public java.lang.String processCommand()
                                throws WavesetException
Process an extended command.

Throws:
WavesetException

processResult

public java.lang.String processResult(WavesetResult result)
                               throws WavesetException
This will walk a WavesetResult object and set the _error attributes. Also looks for a result type of "nextURL" so views can redirect a page dynamically.

Need a general way to describe what we want to see from a WaveseResult and extract it. !! The WavesetResult model sucks, need to clarify what the types mean and unify how we represent errors.

If the return value is non-null, it is assumed to be the next URL.

Throws:
WavesetException

postProcess

public java.lang.String postProcess(java.lang.String nextURL)
                             throws WavesetException
Called immediately after all processing has finished, and we're about to calculate the next URL. The nextURL argument contains the value of the default nextURL, if this is null we will fall into generate()

Throws:
WavesetException

addExtendedButtons

public void addExtendedButtons(com.waveset.ui.util.html.Panel panel)
                        throws WavesetException
Called by generate() to let the subclass add command buttons to the bottom of the form.

Throws:
WavesetException

getView

public GenericObject getView()
                      throws WavesetException
Convenience method to get the view from the view source. You should not overload this, overload getViewSource if you need control over how the view is obtained.

Throws:
WavesetException

getFormConverter

public FormConverter getFormConverter()
                               throws WavesetException
Build a FormConverter if we don't already have one. The assembly of this has gotten a little complicated, so we defer it until necessary.

Throws:
WavesetException

process

public java.lang.String process(RequestState reqState)
                         throws WavesetException
Process the form produced by the generate() method. If this is the first time through, we fall immediately into generate().

Overrides:
process in class PageProcessor
Throws:
WavesetException

refreshViewIfNeeded

protected void refreshViewIfNeeded()
                            throws WavesetException
Throws:
WavesetException

getNiceMessage

public java.lang.String getNiceMessage(java.lang.Throwable t,
                                       java.util.Locale locale)
Get the localized message from an excpetion. Try to be smart about java exceptions that don't have any interesting messages.


getNiceMessageObject

public java.lang.Object getNiceMessageObject(java.lang.Throwable t,
                                             java.util.Locale locale)
Get the localized message from an excpetion. Try to be smart about java exceptions that don't have any interesting messages.


getMessage

public java.lang.Object getMessage(java.lang.Throwable t,
                                   java.util.Locale locale)

getNicerLockMessage

public java.lang.String getNicerLockMessage(java.lang.Throwable t,
                                            java.util.Locale locale)

isAdminSubject

public boolean isAdminSubject(LighthouseContext context)
Helper method that checks to see if an Administrator is logged in to the session. If this is false, then the subject must be an end-user. This also exists inside LocalSession but its private, should expose it.


generate

public com.waveset.ui.util.html.HtmlPage generate()
                                           throws WavesetException
Generate the form. The process() method is always called first, if process returns null, the calling JSP then calls generate().

If you want more control, overload the postProcessForm method.

We let FormConverter do most of the work. The balance of power between GenericEditForm and FormConverter has shifted as we we went, now its a little awkward how the form gets pre & post processed, I'm especially not happy with how buttons get added here. Need to think about this!!

Overrides:
generate in class PageProcessor
Throws:
WavesetException

getMessageConfirmationButtonText

public java.lang.String getMessageConfirmationButtonText()
Return the text to be displayed in the confirmatino button when status messages are displayed after a SAVE command. Overload this in a subclass to change the text to a more directed label like "Return to Main Menu".


addButtons

public void addButtons(com.waveset.ui.util.html.HtmlPage page)
                throws WavesetException
Add the standard button and extended button sets. This can be overloaded by the subclass if you don't want the standard buttons. If there is already a button row on the page, we use it.

Throws:
WavesetException