|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.arsdigita.bebop.parameters.ParameterModel
Represents the abstract model for a form parameter object. This class must be subclassed for each specific data type.
Field Summary | |
protected Object |
m_defaultValue
The default value of this ParameterModel. |
protected boolean |
m_locked
A boolean indicating if this ParameterModel is locked, as per the Lockable interface |
protected String |
m_name
The name of this ParameterModel. |
protected List |
m_parameterListeners
A List of Listeners to validate this parameter. |
static String |
versionId
|
Constructor Summary | |
protected |
ParameterModel(String name)
Construct a new Parameter Model with the specified name |
Method Summary | |
void |
addParameterListener(ParameterListener listener)
Adds a validation listener, implementing a custom validation check that applies to this Parameter. |
ParameterData |
createParameterData(javax.servlet.http.HttpServletRequest request)
|
ParameterData |
createParameterData(javax.servlet.http.HttpServletRequest request,
boolean isSubmission)
Create a ParameterData for this ParameterModel with the supplied request If this tranformation throws an exception, mark the corresponding ParameterData as unTransformed and set its value to null. |
ParameterData |
createParameterData(javax.servlet.http.HttpServletRequest request,
Object defaultValue,
boolean isSubmission)
Create a ParameterData for this ParameterModel with the supplied request If this tranformation throws an exception, mark the corresponding ParameterData as unTransformed and set its value to null. |
boolean |
getDefaultOverridesNull()
Return true if default values are used when the value
in the request is null . |
Object |
getDefaultValue()
Get the default value for this parameter. |
String |
getName()
Returns the name of this parameterModel |
Class |
getValueClass()
Return the class that all values produced by the model will have. |
boolean |
isLocked()
Return whether an object is locked and thus immutable, or can still be modified. |
boolean |
isPassIn()
The "pass in" property determines whether the value for this parameter is generally passed in from the outside. |
void |
lock()
Lock the model, blocking any further modifications. |
String |
marshal(Object value)
Produce a string representation of the given value. |
void |
setDefaultOverridesNull(boolean v)
Controls how default values are used. |
void |
setDefaultValue(Object defaultValue)
Sets a default value for this parameter. |
void |
setName(String name)
Sets the name of this ParmeterModel. |
void |
setPassIn(boolean v)
Set whether this parameter should be treated as a "pass in" parameter. |
protected Object |
transformSingleValue(javax.servlet.http.HttpServletRequest request)
Helper method for implementing transformValue . |
abstract Object |
transformValue(javax.servlet.http.HttpServletRequest request)
Transform string parameter values in the HTTP request into an appropriate Java object associated with the particular implementing class. |
Object |
unmarshal(String encoded)
Reconstruct the parameter value from an encoded string produced by marshal . |
protected void |
validate(ParameterData data)
Call parameter validation listeners that have been added to this ParameterModel . |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final String versionId
protected String m_name
protected Object m_defaultValue
protected List m_parameterListeners
protected boolean m_locked
Constructor Detail |
protected ParameterModel(String name)
name
- String used to identify this parameter. Name is used
as the name of the associated widget, and is the name of the
variable in the requestMethod Detail |
public final void setDefaultOverridesNull(boolean v)
false
(which it is initially), default values are only
used for requests that are not user submissions as
indicated by the isSubmission
parameter to createParameterData(javax.servlet.http.HttpServletRequest)
. This is the behavior that is useful for
forms, since it makes it possible for the user to get rid of default
form entries by erasing them.
If this property is set to true
, the default value
is used whenever transformValue(javax.servlet.http.HttpServletRequest)
returns null
.
This behavior is mainly useful for processing requests that are
generated automatically, and is used by PageState
to maintain state information across
requests.
v
- true
if default values should be used
when the value in the request is null
.setDefaultValue(java.lang.Object)
public final boolean isPassIn()
true
, the model always tries to get the parameter value from
the request, no matter whether the isSubmission
parameter to
createParameterData(javax.servlet.http.HttpServletRequest)
is true or not.
If this property is false
, the parameter value is only
read from the request if the isSubmission
parameter to
createParameterData(javax.servlet.http.HttpServletRequest)
is true.
By default, this property is true
.
true
if an attempt should always be made to retrieve
the parameter value from the request.public final void setPassIn(boolean v)
This defaults to true
; if a passed-in value is available,
it should be used.
v
- true
if this parameter is a pass in parameter.isPassIn()
public final boolean getDefaultOverridesNull()
true
if default values are used when the value
in the request is null
. This property is initially
false
.
true
if default values are used when the value
in the request is null
.setDefaultOverridesNull(boolean)
,
setDefaultValue(java.lang.Object)
public final String getName()
public final void setName(String name)
name
- The name of this parameter model.public void addParameterListener(ParameterListener listener)
listener
- An instance of a class that implements the
FormValidationListener
interface.public void setDefaultValue(Object defaultValue)
defaultValue
- a default value for this parameter that
appears if there is no value in the request or specified by an
initialization listenerpublic final Object getDefaultValue()
public abstract Object transformValue(javax.servlet.http.HttpServletRequest request) throws IllegalArgumentException
request
- The HttpServletRequest of the form submission.
IllegalArgumentException
- if there is an
error transforming form/URL variables to an object.protected final Object transformSingleValue(javax.servlet.http.HttpServletRequest request)
transformValue
. Calls unmarshal
, passing in the
request parameter, if there is a nonempty request parameter with the
models name, and returns null
otherwise.
request
- the current request
unmarshalling
the
request parameter, or null
if there is no nonempty
request parameter with the model's name.public ParameterData createParameterData(javax.servlet.http.HttpServletRequest request)
public ParameterData createParameterData(javax.servlet.http.HttpServletRequest request, boolean isSubmission)
request
- the HttpServletRequest from which to extract and
transform the valueisSubmission
- boolean indicating whether this ParameterData
is being created as part of a form submission. If this is part of
a form submission, we do not want default values to overwrite
null values from the submission.public ParameterData createParameterData(javax.servlet.http.HttpServletRequest request, Object defaultValue, boolean isSubmission)
request
- the HttpServletRequest from which to extract and
transform the valuedefaultValue
- an additional default value that may
be specified dynamically, to override the static default
value associated with this ParameterModel object.isSubmission
- boolean indicating whether this ParameterData
is being created as part of a form submission. If this is part of
a form submission, we do not want default values to overwrite
null values from the submission.public void lock()
lock
in interface Lockable
protected void validate(ParameterData data) throws FormProcessException
ParameterModel
. Note that this is decoupled from
the getValue
method because the form data object may
be initialized with data prior to processing the HTTP request.
data
- A ParameterData object associated with this
parameterModel for a given request. The ParameterData contains
the value and errors of this parameter
FormProcessException
public String marshal(Object value)
o
so that
value.equals(o)
.
value
- a value previously produced by this parameter model
null
public Object unmarshal(String encoded)
marshal
. This is an optional operation, which needs
to be implemented by specific subclasses; this implementation just
throws an UnsupportedOperationException
.
The contract between marshal
and
unmarshal
is that for any possible object
obj
this parameter model can produce
obj.equals(unmarshal(marshal(obj))
.
encoded
- a string produced by marshal
encoded
public Class getValueClass()
Object.class
public final boolean isLocked()
Lockable
isLocked
in interface Lockable
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |