|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.click.control.AbstractControl org.apache.click.control.Field
public abstract class Field
Provides an abstract form Field control. Field controls are contained by
the Form
control which will orchestrate the processing and
rendering of the contained fields. All Form field controls must extend this
abstract class.
onProcess()
method on all its fields. The Field onProcess() method is used
to bind the fields request value, validate the submission and invoke any
control listener method. If the onProcess() method returns true
the form will continue processing fields, otherwise the form will abort
further processing.
The body of the Field onProcess() method is detailed below.
public boolean onProcess() { bindRequestValue(); if (getValidate()) { validate(); } registerActionEvent(); return true; }The Field methods called by onProcess() include:
bindRequestValue()
getValidate()
validate()
error
property,
which can be rendered by the Form.
AbstractControl.dispatchActionEvent()
AbstractControl.render(org.apache.click.util.HtmlStringBuffer)
method to enable themselves to be rendered as HTML. With the increasing use of
AJAX, Fields should render themselves as valid XHTML, so that they may be parsed
correctly and used as the innerHtml in the DOM.
When a Form object renders a Field using autolayout, it renders the
Field in a table row using the Field's label
attribute, its
error
attribute if defined, and the Fields
AbstractControl.render(org.apache.click.util.HtmlStringBuffer)
method.
To assist with rendering valid HTML Field subclasses can use the
HtmlStringBuffer
class.
AbstractControl.getMessage(String)
AbstractControl.getMessage(String, Object...)
AbstractControl.getMessages()
setErrorMessage(String)
setErrorMessage(String, Object)
/com/mycorp/page/Login.propertiesIf you want messages to be used only for a specific Page, this is where to place them.
/click-page.propertiesIf you want messages to be used across your entire application this is where to place them.
/com/mycorp/control/CustomTextField.properties
/click-control.propertiesYou can modify these properties by copying this file into your applications root class path and editing these properties. Note when customizing the message properties you must include all the properties, not just the ones you want to override.
Field Summary | |
---|---|
protected boolean |
disabled
The Field disabled value. |
protected String |
error
The Field error message. |
protected boolean |
focus
The request focus flag. |
protected Form |
form
The parent Form. |
protected String |
help
The Field help text. |
protected String |
label
The Field label. |
protected String |
labelStyle
The field label "style" attribute value. |
protected String |
labelStyleClass
The field label "class" attribute value. |
protected String |
parentStyleClassHint
The field's parent element "class" attribute hint. |
protected String |
parentStyleHint
The field's parent element "style" attribute hint. |
protected boolean |
readonly
The Field is readonly flag. |
protected boolean |
required
The Field is required flag. |
protected int |
tabindex
The Field 'tabindex' attribute. |
protected String |
title
The Field 'title' attribute, which acts as a tooltip help message. |
protected boolean |
trim
The Field is trimmed flag, default value is true. |
protected Boolean |
validate
The validate Field value onProcess() invocation flag. |
protected String |
value
The Field value. |
Fields inherited from class org.apache.click.control.AbstractControl |
---|
actionListener, attributes, behaviors, headElements, listener, listenerMethod, messages, name, parent, styles |
Fields inherited from interface org.apache.click.Control |
---|
CONTROL_MESSAGES |
Constructor Summary | |
---|---|
Field()
Construct a new Field object. |
|
Field(String name)
Construct the Field with the given name. |
|
Field(String name,
String label)
Construct the Field with the given name and label. |
Method Summary | ||
---|---|---|
void |
bindRequestValue()
This method binds the submitted request value to the Field's value. |
|
String |
getError()
Return the validation error message if the Field is not valid, or null if valid. |
|
protected String |
getErrorLabel()
Return a normalized label for display in error messages. |
|
boolean |
getFocus()
Return true if the field has requested focus. |
|
String |
getFocusJavaScript()
Return the Field focus JavaScript. |
|
Form |
getForm()
Return the parent Form containing the Field or null if no form is present in the parent hierarchy. |
|
String |
getHelp()
Return the field help text. |
|
String |
getId()
Return the Form and Field id appended: "form-field" Use the field the "id" attribute value if defined, or the name otherwise. |
|
String |
getLabel()
Return the field display label. |
|
String |
getLabelStyle()
Return the field label "style" attribute value. |
|
String |
getLabelStyleClass()
Return the field label "class" attribute value. |
|
String |
getParentStyleClassHint()
Return the field's parent "class" attribute hint. |
|
String |
getParentStyleHint()
Return the field's parent "style" attribute hint. |
|
protected String |
getRequestValue()
Return the field's value from the request. |
|
Object |
getState()
Return the Field state. |
|
int |
getTabIndex()
Return the field "tabindex" attribute value. |
|
String |
getTextAlign()
Return the field CSS "text-align" style, or null if not defined. |
|
String |
getTitle()
Return the 'title' attribute, or null if not defined. |
|
boolean |
getValidate()
Return true if the Field should validate itself when being processed. |
|
String |
getValidationJavaScript()
Return the field JavaScript client side validation function. |
|
String |
getValue()
Return the Field value. |
|
Object |
getValueObject()
Return the object representation of the Field value. |
|
String |
getWidth()
Return the width CSS "width" style, or null if not defined. |
|
boolean |
isDisabled()
Return true if the Field is disabled. |
|
boolean |
isHidden()
Return true if the Field type is hidden (<input type="hidden"/>) or false otherwise. |
|
boolean |
isReadonly()
Return true if the Field is a readonly. |
|
boolean |
isRequired()
Return true if the Field's value is required. |
|
boolean |
isTrim()
Return true if the Field request value should be trimmed, false otherwise. |
|
boolean |
isValid()
Return true if the Field is valid after being processed, or false otherwise. |
|
boolean |
onProcess()
This method processes the page request returning true to continue processing or false otherwise. |
|
void |
removeState(Context context)
Remove the Field state from the session for the given request context. |
|
protected void |
renderTagBegin(String tagName,
HtmlStringBuffer buffer)
Render the Field tag and common attributes including name ,
id , class and style. |
|
void |
restoreState(Context context)
Restore the Field state from the session for the given request context. |
|
void |
saveState(Context context)
Save the Field state to the session for the given request context. |
|
void |
setDisabled(boolean disabled)
Set the Field disabled flag. |
|
void |
setError(String error)
Set the Field validation error message. |
|
protected void |
setErrorMessage(String key)
Set the error with the a label formatted message specified by the given message bundle key. |
|
protected
|
setErrorMessage(String key,
T value)
Set the error with the a label and value formatted message specified by the given message bundle key. |
|
void |
setFocus(boolean focus)
Set the Field request focus flag. |
|
void |
setForm(Form form)
Set the Field's the parent Form. |
|
void |
setHelp(String help)
Set the Field help text. |
|
void |
setLabel(String label)
Set the Field display caption. |
|
void |
setLabelStyle(String value)
Set the field label "style" attribute value. |
|
void |
setLabelStyleClass(String value)
Set the field label "class" attribute value. |
|
void |
setListener(Object listener,
String method)
The callback listener will only be called during processing if the Field value is valid. |
|
void |
setParent(Object parent)
Set the parent of the Field. |
|
void |
setParentStyleClassHint(String styleClassHint)
Set the field's parent "class" attribute hint. |
|
void |
setParentStyleHint(String styleHint)
Set the field's parent "style" attribute hint. |
|
void |
setReadonly(boolean readonly)
Set the Field readonly flag. |
|
void |
setRequired(boolean required)
Set the Field required status. |
|
void |
setState(Object state)
Set the Field state. |
|
void |
setTabIndex(int tabindex)
Set the field "tabindex" attribute value. |
|
void |
setTextAlign(String align)
Set the field CSS horizontal "text-align" style. |
|
void |
setTitle(String value)
Set the 'title' attribute tooltip message. |
|
void |
setTrim(boolean trim)
Set the trim flag to true if the Field request value should be trimmed, false otherwise. |
|
void |
setValidate(boolean validate)
Set the validate Field value when being processed flag. |
|
void |
setValue(String value)
Set the Field value. |
|
void |
setValueObject(Object object)
Set the value of the field using the given object. |
|
void |
setWidth(String value)
Set the the CSS "width" style attribute. |
|
void |
validate()
The validate method is invoked by onProcess() to validate the request submission. |
Methods inherited from class org.apache.click.control.AbstractControl |
---|
addBehavior, addStyleClass, appendAttributes, dispatchActionEvent, getActionListener, getAttribute, getAttributes, getBehaviors, getContext, getControlSizeEst, getHeadElements, getHtmlImports, getMessage, getMessage, getMessages, getName, getPage, getParent, getStyle, getStyles, getTag, hasAttribute, hasAttributes, hasBehaviors, hasStyles, isAjaxTarget, onDeploy, onDestroy, onInit, onRender, removeBehavior, removeStyleClass, render, renderTagEnd, setActionListener, setAttribute, setId, setName, setStyle, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected boolean disabled
protected String error
protected boolean focus
protected Form form
protected String help
protected String label
protected String labelStyle
protected String labelStyleClass
protected String parentStyleHint
protected String parentStyleClassHint
protected boolean readonly
protected boolean required
protected int tabindex
protected String title
protected boolean trim
protected Boolean validate
protected String value
Constructor Detail |
---|
public Field()
public Field(String name)
name
- the name of the Fieldpublic Field(String name, String label)
name
- the name of the Fieldlabel
- the label of the FieldMethod Detail |
---|
public void setParent(Object parent)
setParent
in interface Control
setParent
in class AbstractControl
parent
- the parent of the Control
IllegalStateException
- if AbstractControl.name
is not defined
IllegalArgumentException
- if the given parent instance is
referencing this object: if (parent == this)Control.setParent(Object)
public boolean isDisabled()
setDisabled(boolean)
public void setDisabled(boolean disabled)
Checkbox
and Radio
buttons. An HTML form POST for a
disabled checkbox/radio is the same as for an unchecked
checkbox/radio. In neither case is a value submitted to the server and
Click cannot make the distinction whether the checkbox/radio is disabled
or unchecked.
disabled
- the Field disabled flagpublic String getError()
public void setError(String error)
error
- the validation error messagepublic boolean getFocus()
public void setFocus(boolean focus)
focus
- the request focus flagpublic String getFocusJavaScript()
public Form getForm()
public void setForm(Form form)
form
- Field's parent Formpublic String getHelp()
getName() + ".help"If not found then the message will be looked up in the /click-control.properties file using the same key. For example given a CustomerPage with the properties file CustomerPage.properties:
name.label=Customer Name name.help=Full name or Business nameThe page TextField code:
public class CustomerPage extends Page { TextField nameField = new TextField("name"); .. }Will render the TextField label and title properties as:
<td><label>Customer Name</label></td> <td><input type="text" name="name"/> <span="Full name or Business name"/>/td>How the help text is rendered is depends upon the Field subclass.
public void setHelp(String help)
help
- the help text of the Fieldpublic boolean isHidden()
public String getId()
getId
in interface Control
getId
in class AbstractControl
Control.getId()
public String getLabel()
getName() + ".label"If not found then the message will be looked up in the /click-control.properties file using the same key. If a value is still not found, the Field name will be converted into a label using the method:
ClickUtils.toLabel(String)
For example given a CustomerPage with the properties file
CustomerPage.properties:
name.label=Customer Name name.title=Full name or Business nameThe page TextField code:
public class CustomerPage extends Page { TextField nameField = new TextField("name"); .. }Will render the TextField label and title properties as:
<td><label>Customer Name</label></td> <td><input type="text" name="name" title="Full name or Business name"/></td>When a label value is not set, or defined in any properties files, then its value will be created from the Fields name. For example given the TextField code:
TextField nameField = new TextField("faxNumber");Will render the TextField label as:
<td><label>Fax Number</label></td> <td><input type="text" name="faxNumber"/></td>
public void setLabel(String label)
label
- the display label of the Fieldpublic String getLabelStyle()
setLabelStyle(java.lang.String)
public void setLabelStyle(String value)
nameField.setLabelStyle("color: green; font-weight: bold");
value
- the field label "style" attribute valuepublic String getLabelStyleClass()
setLabelStyleClass(java.lang.String)
public void setLabelStyleClass(String value)
value
- the field label "class" attribute valuepublic String getParentStyleHint()
setParentStyleHint(java.lang.String)
public void setParentStyleHint(String styleHint)
nameField.setParentStyleHint("margin-bottom; 10px");Please note:The field's parent style provides a hint to Forms (or other containers) what style to render, but it is up to the Form (or container) implementation how the style will be applied. For example, Form will render the parent style on the table cells containing the field and label.
styleHint
- the field's parent "style" attribute hintpublic String getParentStyleClassHint()
setParentStyleClassHint(java.lang.String)
public void setParentStyleClassHint(String styleClassHint)
styleClassHint
- the field parent "class" attribute hintpublic void setListener(Object listener, String method)
setListener
in interface Control
setListener
in class AbstractControl
listener
- the listener object with the named method to invokemethod
- the name of the method to invokeControl.getName()
public boolean isReadonly()
public void setReadonly(boolean readonly)
readonly
- the Field readonly flagpublic boolean isRequired()
public void setRequired(boolean required)
required
- set the Field required statuspublic int getTabIndex()
public void setTabIndex(int tabindex)
tabindex
- the field "tabindex" attribute valuepublic String getTextAlign()
public void setTextAlign(String align)
align
- the CSS "text-align" value: ["left", "right", "center"]public String getTitle()
getName() + ".title"If not found then the message will be looked up in the /click-control.properties file using the same key. If still not found the title will be left as null and will not be rendered. For example given a CustomerPage with the properties file CustomerPage.properties:
name.label=Customer Name name.title=Full name or Business nameThe page TextField code:
public class CustomerPage extends Page { TextField nameField = new TextField("name"); .. }Will render the TextField label and title properties as:
<td><label>Customer Name</label></td> <td><input type="text" name="name" title="Full name or Business name"/></td>
public void setTitle(String value)
value
- the 'title' attribute tooltip messagepublic boolean isTrim()
public void setTrim(boolean trim)
trim
- true if the Field request value should be trimmed, false
otherwisepublic boolean getValidate()
Form.getValidate()
. If the Field validate attribute is not set
and the parent Form is not set this method will return true.
This method is called by the onProcess()
method to determine
whether the the Field validate()
method should be invoked.
public void setValidate(boolean validate)
validate
- the field value when processedpublic String getValidationJavaScript()
public boolean isValid()
Control.onProcess()
has been invoked it is considered to be
valid.
public String getValue()
public void setValue(String value)
value
- the Field valuepublic Object getValueObject()
public void setValueObject(Object object)
object
- the object value to setpublic String getWidth()
public void setWidth(String value)
value
- the CSS "width" style attributepublic void bindRequestValue()
ClickUtils
instead. See ClickUtils.bind(org.apache.click.control.Field)
for more details.
public Object getState()
getState
in interface Stateful
public void setState(Object state)
setState
in interface Stateful
state
- the Field state to setpublic boolean onProcess()
public boolean onProcess() { bindRequestValue(); if (getValidate()) { validate(); } registerActionEvent(); return true }
onProcess
in interface Control
onProcess
in class AbstractControl
Control.onProcess()
public void removeState(Context context)
context
- the request contextsaveState(org.apache.click.Context)
,
restoreState(org.apache.click.Context)
public void restoreState(Context context)
setState(java.lang.Object)
to set the
field restored state.
context
- the request contextsaveState(org.apache.click.Context)
,
removeState(org.apache.click.Context)
public void saveState(Context context)
getState()
to retrieve the field state
to save.
context
- the request contextrestoreState(org.apache.click.Context)
,
removeState(org.apache.click.Context)
public void validate()
error
property with the error message.
protected String getErrorLabel()
getLabel()
.
protected void setErrorMessage(String key)
getErrorLabel()
.
setErrorMessage will attempt to find a localized error message as
described here, using the following
lookup strategy:
getMessage(getName() + "." + key);
getMessage(key);
key
- the key of the localized message bundle stringprotected <T> void setErrorMessage(String key, T value)
getErrorLabel()
and the given value {1}.
Also see setErrorMessage(java.lang.String)
on how to
specify error messages for specific Field instances.
key
- the key of the localized message bundle stringvalue
- the value to format in the messageprotected String getRequestValue()
protected void renderTagBegin(String tagName, HtmlStringBuffer buffer)
name
,
id
, class and style.
renderTagBegin
in class AbstractControl
tagName
- the name of the tag to renderbuffer
- the buffer to append the output toAbstractControl.renderTagBegin(java.lang.String, org.apache.click.util.HtmlStringBuffer)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |