| java.lang.Object simpleorm.simplewebapp.core.WFieldNode simpleorm.simplewebapp.core.WField
All known Subclasses: simpleorm.simplewebapp.scalarFields.WFieldDate, simpleorm.simplewebapp.scalarFields.WFieldImage, simpleorm.simplewebapp.scalarFields.WFieldLong, simpleorm.simplewebapp.scalarFields.WFieldString, simpleorm.simplewebapp.scalarFields.WFieldBoolean, simpleorm.simplewebapp.scalarFields.WFieldInteger,
WField | abstract public class WField extends WFieldNode (Code) | | The data field properties.
Each instance represents one crud or list field in a form.
Subtypes implement different data types and validation, eg. WFieldString.
This class stores the rawText entered by the user
(normally via the HttpRequest.parameter).
When this is Validated it is Parsed to produce a typed value.
If the parse fails then the rawText value is retained so that
the user can edit it and re-submit the form.
Note that if it does parse, then this.text is nulled, so that
this.value is the source of truth.
getText returns either the non-null thus non-validated text, or a
formatted version of getValue.
It is tempting to split out the different widgets (vs data type) into a separate
delegated hierarchy. But that is not necessary, the jstl .tags render them
and the few special properties required do NOT warant that complexity.
Just merge per widget properties in WField, maybe add a Properties later.
It is also tempting to split out the data source into a separate heirarchy, so
that tight integration with an ORM can be achieved.
However, that again is unnecessary as it is far better to achieve the integration
with a simple generate approach rather than direct references involving complex
inheritance rules.
It took quite a while to get this class simple!
|
Method Summary | |
void | checkRequired() | abstract protected String | format() Convert the value to a string.
The is called by getText to set the INPUT value= etc. | public String | getAnchorHRef() | public boolean | getBooleanValue(boolean defalt) Interpret the field as a boolean, mainly for checkbox widgets.
Implemented for Strings, Integers etc. | public boolean | getBooleanValue() | public Object | getDataField() | public String | getDataName() Name used to idenify the column in a data source. | public int | getDisplayLength() | public Object | getExtraProperties() | public int | getMaxLength() | public List | getOptions() | public String | getText() Return the text representation of this field. | public Object | getValue() Just casts value to correct type.
Nulls returned as nulls, including booleans. | public T | getValue(T defalt) | abstract public Class | getValueClass() Returns the class for which the value must be a subclass.
Also used to find the set*() method of the bean by WBeanUtils. | public String | getWidget() The widget, eg radiobutton, text, select... | public boolean | isNotRetrieved() | public boolean | isReadOnly() | public boolean | isRequired() | protected void | onValidateAlways() Always called regardless of whether form wasSubmitted() or value is null. | protected void | onValidateNotNull() Override this method to add extra validation.
Called after required and data checks but before
all other fields have been validated. | abstract protected void | parse(String rawText) Parse text and store it as the value. | public void | setAnchorHRef(String anchorHRef) | public WField | setDataField(Object dataField) | public WField | setDataName(String dataName) | public F | setDisplayLength(int displayLength) | public WField | setExtraProperties(Object extraProperties) | public F | setMaxLength(int maxLength) | public WField | setNotRetrieved(boolean notRetrieved) | public void | setOptions(List options) | public WField | setPostedText(String text) Sets the initial value of the raw text field,
typically directly from a HttpRequest.parameter.
Called by the framework or test cases between
doInitialize and doProcess, the latter which then
parses it to a getValue.
Also trims spaces and converts "" to null. | public F | setReadOnly(boolean readOnly) | public F | setRequired(boolean required) | public WField | setValue(Object value) Set the value, must be the correct type,
eg. | public void | setWidget(String widget) | public String | toString() | void | validateField() Called by doProcess to validates the field and parses it into the value. |
RADIO_VERTICAL | final public static String RADIO_VERTICAL(Code) | | |
anchorHRef | String anchorHRef(Code) | | If non-null, wrap the (list) field with an anchor with HRef= this.
|
dataField | Object dataField(Code) | | Reference to a field in an external ORM etc.
Not directly used by SimpleWebApp.
|
dataName | String dataName(Code) | | Used by auto List to access the columns/data field, defaults to name.
todo this usage conflicts with dataField, only one of these should be used.
|
displayLength | int displayLength(Code) | | Default display length, in chars, mainly for input boxes.
|
extraProperties | Object extraProperties(Code) | | Arbitrary extra properties
Not used directly by SimpleWebApp.
|
maxLength | int maxLength(Code) | | Enforced max length of the raw text, in 16 bit UTF char lengths. -1 means no limit.
|
notRetrieved | boolean notRetrieved(Code) | | Can be set to indicate that a parameter should not be retrieved
by WPage.retrieveParameters.
|
options | List options(Code) | | For Select/Option, radio buttons etc.
|
rawText | protected String rawText(Code) | | The raw value retrieved from HtmlRequest.
This is what is referenced by the .jsps.
See class docs.
|
readOnly | boolean readOnly(Code) | | Cannot be changed by the end user.
Normally rendered as a Hidden <Input> with
the actual value shown in a <span>
Mainly for database keys.
|
required | boolean required(Code) | | End user must not leave the field null *
|
value | protected Object value(Code) | | The parsed and processed value, eg. an Integer.
Used by code, but Not used by the .jsps, see class docs.
|
checkRequired | void checkRequired()(Code) | | |
format | abstract protected String format()(Code) | | Convert the value to a string.
The is called by getText to set the INPUT value= etc. so
it should return a value that can be parsed in a subsequent
post.
|
getBooleanValue | public boolean getBooleanValue(boolean defalt)(Code) | | Interpret the field as a boolean, mainly for checkbox widgets.
Implemented for Strings, Integers etc. as well as Booleans
because databases do not support booleans cleanly.
|
getBooleanValue | public boolean getBooleanValue()(Code) | | |
getDataName | public String getDataName()(Code) | | Name used to idenify the column in a data source.
Defaults to name if null.
|
getDisplayLength | public int getDisplayLength()(Code) | | |
getMaxLength | public int getMaxLength()(Code) | | |
getText | public String getText()(Code) | | Return the text representation of this field.
Normally just format(), but if the
field failed to validate then returns the raw text
actually entered by the user.
This is what is used to set values of etc.
See class docs.
(Not cached, may involve Integer.toString etc.)
|
getValue | public Object getValue()(Code) | | Just casts value to correct type.
Nulls returned as nulls, including booleans.
|
getValue | public T getValue(T defalt)(Code) | | |
getValueClass | abstract public Class getValueClass()(Code) | | Returns the class for which the value must be a subclass.
Also used to find the set*() method of the bean by WBeanUtils.
|
getWidget | public String getWidget()(Code) | | The widget, eg radiobutton, text, select...
|
isNotRetrieved | public boolean isNotRetrieved()(Code) | | |
isReadOnly | public boolean isReadOnly()(Code) | | |
isRequired | public boolean isRequired()(Code) | | |
onValidateAlways | protected void onValidateAlways() throws Exception(Code) | | Always called regardless of whether form wasSubmitted() or value is null.
Called after onValidateNotNull.
|
onValidateNotNull | protected void onValidateNotNull() throws Exception(Code) | | Override this method to add extra validation.
Called after required and data checks but before
all other fields have been validated.
Note that this is ALWAYS called even if the form was not
submitted, but is ONLY called if the field is not NULL.
|
parse | abstract protected void parse(String rawText) throws Exception(Code) | | Parse text and store it as the value.
Should be fairly forgiving in what it accepts, and should parse
whatever format() produces.
|
setAnchorHRef | public void setAnchorHRef(String anchorHRef)(Code) | | |
setDisplayLength | public F setDisplayLength(int displayLength)(Code) | | |
setMaxLength | public F setMaxLength(int maxLength)(Code) | | |
setNotRetrieved | public WField setNotRetrieved(boolean notRetrieved)(Code) | | |
setOptions | public void setOptions(List options)(Code) | | |
setPostedText | public WField setPostedText(String text)(Code) | | Sets the initial value of the raw text field,
typically directly from a HttpRequest.parameter.
Called by the framework or test cases between
doInitialize and doProcess, the latter which then
parses it to a getValue.
Also trims spaces and converts "" to null.
|
setReadOnly | public F setReadOnly(boolean readOnly)(Code) | | |
setRequired | public F setRequired(boolean required)(Code) | | |
setValue | public WField setValue(Object value)(Code) | | Set the value, must be the correct type,
eg. String for WFieldString, Integer for WFieldInteger.
|
validateField | void validateField() throws Exception(Code) | | Called by doProcess to validates the field and parses it into the value.
A range of common formatting exceptions are converted to WValidationExceptions,
but as Java is totally inconsistent this is not clean.
But common real errors such as NullPointerException will not be converted.
(It is not fatal if some non-validation exceptions are trapped, the form
will be rejected either way. But we do not want to make implementors
of WData to be dependent on SimpleWebApp.)
throws: simpleorm.simplewebapp.core.WValidationException - to report user errors |
|
|