|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Widget
Interface to be implemented by Widgets. In CForms, a form consists of a number of widgets. Each widget:
getId()
.getParent()
.getValue()
.readFromRequest(FormContext)
.validate()
.When a request is submitted, first the readFromRequest(FormContext)
method of all widgets
will be called so that they can read their value(s). Next, the validate()
method will
be called. Doing this in two steps allows the validation to compare values between widgets.
See also the method Form.process(FormContext)
.
A Widget is created by calling the createInstance method on the a
WidgetDefinition
. A Widget holds all the data that is specific for
a certain use of the widget (its value, validationerrors, ...), while the
WidgetDefinition holds the data that is static accross all widgets. This
keeps the Widgets small and light to create. This mechanism is similar to
classes and objects in Java.
Field Summary | |
---|---|
static char |
PATH_SEPARATOR
Widget-Separator used in path-like notations |
Method Summary | |
---|---|
void |
addValidator(WidgetValidator validator)
|
void |
broadcastEvent(WidgetEvent event)
Broadcast an event previously queued by this widget to its event listeners. |
void |
generateLabel(ContentHandler contentHandler)
Generates SAX events for the label of this widget. |
void |
generateSaxFragment(ContentHandler contentHandler,
Locale locale)
Generates an XML representation of this widget. |
Object |
getAttribute(String name)
Retrieves an attribute on this widget. |
WidgetState |
getCombinedState()
Get the widget's combined state, which is the strictest of its own state and parent state. |
WidgetDefinition |
getDefinition()
Get this widget's definition. |
Form |
getForm()
|
String |
getFullName()
|
String |
getId()
|
Location |
getLocation()
Get the location of this object |
String |
getName()
|
Widget |
getParent()
|
String |
getRequestParameterName()
|
WidgetState |
getState()
Get the widget's own state. |
Object |
getValue()
Get the value of a widget. |
Widget |
getWidget(String id)
Deprecated. getWidget got removed, use lookupWidget or getChild instead. |
void |
initialize()
Called after widget's environment has been setup, to allow for any contextual initalization such as looking up case widgets for union widgets. |
boolean |
isRequired()
|
boolean |
isValid()
Return the current validation state. |
Widget |
lookupWidget(String path)
Finds a widget relative to this one based on a path-like string (/-delimted) into the widget-tree structure. |
void |
readFromRequest(FormContext formContext)
Lets this widget read its data from a request. |
void |
removeAttribute(String name)
Removes the named attribute from this widget. |
boolean |
removeValidator(WidgetValidator validator)
|
void |
setAttribute(String name,
Object value)
Sets an attribute on this widget. |
void |
setParent(Widget widget)
This method is called on a widget when it is added to a container. |
void |
setState(WidgetState state)
Set the widget's own state. |
void |
setValue(Object value)
Sets the value of this widget. |
boolean |
validate()
Validates this widget and returns the outcome. |
Field Detail |
---|
static final char PATH_SEPARATOR
lookupWidget(String)
,
Constant Field ValuesMethod Detail |
---|
void initialize()
Location getLocation()
Locatable
getLocation
in interface Locatable
String getName()
null
Top-level container widgets (like 'form') should return ""
String getId()
null
Top-level container widgets (like 'form') should return ""
Widget getParent()
void setParent(Widget widget)
Form getForm()
Form
to which this widget belongs. The form is the top-most ancestor
of the widget.WidgetDefinition getDefinition()
WidgetState getState()
getCombinedState()
void setState(WidgetState state)
state
- the new wiget stateWidgetState getCombinedState()
WidgetState.strictest(WidgetState, WidgetState)
String getFullName()
String getRequestParameterName()
Widget getWidget(String id)
UnsupportedOperationException
- indicating this method has been
deprecated from the API, and will be removed from future releases.Widget lookupWidget(String path)
null
if allong the traversal
of the path an invalid section was encountered.void readFromRequest(FormContext formContext)
boolean validate()
generateSaxFragment(ContentHandler, Locale)
method.
true
to indicate all validations were ok,
false
otherwisevoid addValidator(WidgetValidator validator)
boolean removeValidator(WidgetValidator validator)
boolean isValid()
validate()
.
The validation process is not started again. If the value of this widget has
changed since the latest call to validate()
, the result of this method
is out of date.
validate()
.void generateSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException
SAXException
void generateLabel(ContentHandler contentHandler) throws SAXException
SAXException
Object getValue() throws UnsupportedOperationException
Not all widgets do have a value (notably ContainerWidget
s,
but this method is provided here as a convenience to ease writing and avoiding casts.
UnsupportedOperationException
- if this widget doesn't have a value.void setValue(Object value) throws UnsupportedOperationException
Not all widgets do have a value (notably ContainerWidget
s,
but this method is provided here as a convenience to ease writing and avoiding casts.
value
- the new widget's value.
UnsupportedOperationException
- if this widget doesn't have a value.boolean isRequired()
getValue()
,
for some widgets this may not make sense, those should return false here.void broadcastEvent(WidgetEvent event)
Object getAttribute(String name)
name
- of the attribute to lookup
null
if none was found with that name.void setAttribute(String name, Object value)
void removeAttribute(String name)
name
- of the attribute
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |