com.waveset.ui.util
Class GenericViewSource

java.lang.Object
  extended bycom.waveset.ui.util.GenericViewSource
All Implemented Interfaces:
ViewSource

public class GenericViewSource
extends java.lang.Object
implements ViewSource

An implementation of ViewSource used to manage arbitrary view objects with the Session interface. This is the default ViewSource used by GenericEditForm.

Before it can be used to create or edit an object, you must initialize it with setViewId().


Field Summary
 Form _form
          The edited object's form.
 GenericObject _view
          The object we're editing.
static java.lang.String code_id
           
static java.lang.String DEFAULT_SESSION_ATTRIBUTE
          The default name of an attribute on the HttpSession where we hang our editing state.
static java.lang.String NEW_VIEW_PARAMETER
          A request paramter that may be set to indicate that the view should be unconditionally cleared.
static java.lang.String OP_FORM
          A request option that may be set to specify an alternate form.
static java.lang.String RESULT_CONTINUE
          A special WavesetResult item name that may be returnd by the view handler after checkin to indicate that we should continue editing the view, treating the save like a refresh instead.
static java.lang.String VIEW_ID_PARAMETER
          A request parameter that may be set to specify the view id.
static java.lang.String VIEW_TYPE_PARAMETER
          A request parameter that may be set to specify the view type so that the standard id parameter may be used to build the view id (i.e.
 
Constructor Summary
GenericViewSource(RequestState state)
           
 
Method Summary
 void addError(java.lang.Object msg)
          Add an error message to the list.
 void addErrors(java.util.List msgs)
          Add a list of errors.
 WavesetResult checkinView()
          Checkin the view.
 void clearErrors()
          Clear the error list.
 void clearView()
          Removes information about the edit view object stored on the HttpSession after we've successfully applied the changes.
 java.util.List getErrors()
          Get a list of error messages accumulated by the view source.
 Form getForm()
          Obtain the Form used with the view.
 java.util.Map getOptions()
          Get the locally specified options.
 RequestState getRequestState()
           
 java.lang.String getSessionAttribute()
           
 GenericObject getSessionView()
          Restore the view from the HttpSession.
 GenericObject getView()
          Obtain the view to be edited.
 java.lang.String getViewId()
           
 boolean hasCachedView()
          Return true if there is a view being managed.
 boolean hasValidView()
          Return true if there is a view that will remain valid on the next refresh.
 boolean isAlwaysRefresh()
           
 boolean isReadOnly()
           
 void refreshView()
          Refresh the edit view & form.
 void saveView()
          Save a new version of the view being edited in the HttpSession.
 void setAlwaysRefresh(boolean b)
          When true, the view will always be refreshed and will not be cached in the HttpSession.
 void setOption(java.lang.String name, java.lang.Object value)
          Set a view option.
 void setOptions(java.util.Map options)
          Set all view options.
 void setReadOnly(boolean b)
           
 void setRequestState(RequestState rs)
          Sets the request state for this view source.
 void setSessionAttribute(java.lang.String s)
          If this view source saves state on the HttpSession, this is the attribute it should use rather than the default.
 void setSessionView(GenericObject view)
          Save the view on the HttpSession.
 void setViewId(java.lang.String s)
          Sets the view identifier.
 void unlockView()
          Unlock the edit view object.
 
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

NEW_VIEW_PARAMETER

public static final java.lang.String NEW_VIEW_PARAMETER
A request paramter that may be set to indicate that the view should be unconditionally cleared. This is typically set when transitioning into a view page from a context that knows that a new view should be created. This ensure that stale view data is reset, even if we're editing the same object

See Also:
Constant Field Values

VIEW_ID_PARAMETER

public static final java.lang.String VIEW_ID_PARAMETER
A request parameter that may be set to specify the view id. Not currently used, but should evolve into allowing generic JSPs to edit many views.

See Also:
Constant Field Values

VIEW_TYPE_PARAMETER

public static final java.lang.String VIEW_TYPE_PARAMETER
A request parameter that may be set to specify the view type so that the standard id parameter may be used to build the view id (i.e. application:bob)

See Also:
Constant Field Values

OP_FORM

public static final java.lang.String OP_FORM
A request option that may be set to specify an alternate form.

See Also:
Constant Field Values

RESULT_CONTINUE

public static final java.lang.String RESULT_CONTINUE
A special WavesetResult item name that may be returnd by the view handler after checkin to indicate that we should continue editing the view, treating the save like a refresh instead. Used only by complex views (e.g. user view) which may want to display multiple "pages" over the same view, but still allowing each form to use the standard Save button.

See Also:
Constant Field Values

DEFAULT_SESSION_ATTRIBUTE

public static final java.lang.String DEFAULT_SESSION_ATTRIBUTE
The default name of an attribute on the HttpSession where we hang our editing state.

If you want to have more than one view active at a time, use setSessionAttribute to change the name.

See Also:
Constant Field Values

_view

public GenericObject _view
The object we're editing.


_form

public Form _form
The edited object's form. Typically this is the same as _view.getForm(), but it can be overridden.

Constructor Detail

GenericViewSource

public GenericViewSource(RequestState state)
Method Detail

setViewId

public void setViewId(java.lang.String s)
Description copied from interface: ViewSource
Sets the view identifier. If this contains a colon, it is assumed to be a full view id and an existing object will be edited. If it does not contain a colon, it is assumed to be a view type name and a new view will be created.

Specified by:
setViewId in interface ViewSource

setSessionAttribute

public void setSessionAttribute(java.lang.String s)
Description copied from interface: ViewSource
If this view source saves state on the HttpSession, this is the attribute it should use rather than the default.

Specified by:
setSessionAttribute in interface ViewSource

setRequestState

public void setRequestState(RequestState rs)
Description copied from interface: ViewSource
Sets the request state for this view source.

Specified by:
setRequestState in interface ViewSource

setReadOnly

public void setReadOnly(boolean b)

setAlwaysRefresh

public void setAlwaysRefresh(boolean b)
Description copied from interface: ViewSource
When true, the view will always be refreshed and will not be cached in the HttpSession.

Specified by:
setAlwaysRefresh in interface ViewSource

setOption

public void setOption(java.lang.String name,
                      java.lang.Object value)
Description copied from interface: ViewSource
Set a view option.

Specified by:
setOption in interface ViewSource

setOptions

public void setOptions(java.util.Map options)
Description copied from interface: ViewSource
Set all view options.

Specified by:
setOptions in interface ViewSource

getOptions

public java.util.Map getOptions()
Get the locally specified options. Subclasses occasionally overload this in order to adjust options that vary based on RequestState parameters.

Specified by:
getOptions in interface ViewSource

getRequestState

public RequestState getRequestState()

getViewId

public java.lang.String getViewId()

getSessionAttribute

public java.lang.String getSessionAttribute()

isReadOnly

public boolean isReadOnly()

isAlwaysRefresh

public boolean isAlwaysRefresh()
Specified by:
isAlwaysRefresh in interface ViewSource

clearErrors

public void clearErrors()
Description copied from interface: ViewSource
Clear the error list.

Specified by:
clearErrors in interface ViewSource

getErrors

public java.util.List getErrors()
Description copied from interface: ViewSource
Get a list of error messages accumulated by the view source. This may be non-null if something serious happened that needs to be displayed, but we recovered and were able to create the view.

Specified by:
getErrors in interface ViewSource

addError

public void addError(java.lang.Object msg)
Add an error message to the list.


addErrors

public void addErrors(java.util.List msgs)
Add a list of errors.


getSessionView

public GenericObject getSessionView()
                             throws WavesetException
Restore the view from the HttpSession. Originally this is serialized, but IDMX is now storing a Serializable GenericObject directly on the session. IDM should start using this convention too.

Throws:
WavesetException

setSessionView

public void setSessionView(GenericObject view)
                    throws WavesetException
Save the view on the HttpSession.

Throws:
WavesetException

hasCachedView

public boolean hasCachedView()
Return true if there is a view being managed.

Specified by:
hasCachedView in interface ViewSource

hasValidView

public boolean hasValidView()
Return true if there is a view that will remain valid on the next refresh. This does something similar to getView but avoids actually instantiating it.

Specified by:
hasValidView in interface ViewSource

getView

public GenericObject getView()
                      throws WavesetException
Obtain the view to be edited.

If _viewId is not set, we allow a request parameter to specify the view id. If the _viewId contains a colon, it is a full view id and we checkout an existing view. If the _viewId has no colon, it is a simple view type name and we create a new view.

Once the view has been created, we serialize it and store it on the HttpSession. This then carries the state of the edit.

This can be overridden in subclasses in case you want more control over how the views are fetched, or want to post process them after they're fetched.

Specified by:
getView in interface ViewSource
Throws:
WavesetException

getForm

public Form getForm()
             throws WavesetException
Obtain the Form used with the view.

If OP_FORM is set in checkout options, use it. This allows the .jsp to override the form, I would like this to be the universal method for customizing forms. This also ensures that the same OP_FORM option sent to checkoutView is also used in getForm.

Specified by:
getForm in interface ViewSource
Throws:
WavesetException

refreshView

public void refreshView()
                 throws WavesetException
Refresh the edit view & form.

Specified by:
refreshView in interface ViewSource
Throws:
WavesetException

checkinView

public WavesetResult checkinView()
                          throws WavesetException
Checkin the view. Ignore if his was a readOnly view.

Specified by:
checkinView in interface ViewSource
Throws:
WavesetException

saveView

public void saveView()
              throws WavesetException
Save a new version of the view being edited in the HttpSession.

Specified by:
saveView in interface ViewSource
Throws:
WavesetException

unlockView

public void unlockView()
                throws WavesetException
Unlock the edit view object. Assumes that we have one saved. Ignored for read-only views.

Specified by:
unlockView in interface ViewSource
Throws:
WavesetException

clearView

public void clearView()
Removes information about the edit view object stored on the HttpSession after we've successfully applied the changes.

Specified by:
clearView in interface ViewSource