|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.click.control.AbstractControl net.sf.click.control.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.registerActionEvent()
label
attribute, its
error
attribute if defined, and the Fields toString()
method.
To assist with rendering valid HTML Field subclasses can use the
HtmlStringBuffer
class.
AbstractControl.getMessage(String)
AbstractControl.getMessage(String, Object)
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 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 |
validate
The validate Field value onProcess() invokation flag. |
protected String |
value
The Field value. |
Fields inherited from class net.sf.click.control.AbstractControl |
actionListener, attributes, listener, listenerMethod, messages, name, parent, styles |
Fields inherited from interface net.sf.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. |
protected String |
getRequestValue()
Return the field's value from the request. |
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 |
isValid()
Return true if the Field is valid after being processed, or false otherwise. |
void |
onInit()
This method does nothing. |
boolean |
onProcess()
This method processes the page request returning true to continue processing or false otherwise. |
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 void |
setErrorMessage(String key,
double value)
Set the error with the a label and value formatted message specified by the given message bundle key. |
protected void |
setErrorMessage(String key,
int value)
Set the error with the a label and value formatted message specified by the given message bundle key. |
protected void |
setErrorMessage(String key,
Object 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 |
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 |
setReadonly(boolean readonly)
Set the Field readonly flag. |
void |
setRequired(boolean required)
Set the Field required status. |
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 |
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 net.sf.click.control.AbstractControl |
addStyleClass, appendAttributes, getActionListener, getAttribute, getAttributes, getContext, getControlSizeEst, getHtmlImports, getMessage, getMessage, getMessage, getMessages, getName, getPage, getParent, getStyle, getStyles, getTag, hasAttribute, hasAttributes, hasStyles, onDeploy, onDestroy, onRender, registerActionEvent, removeStyleClass, render, renderTagBegin, 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 boolean readonly
protected boolean required
protected int tabindex
protected String title
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()
public void setDisabled(boolean disabled)
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 examle 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 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 examle 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 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()
public void onInit()
onInit
in interface Control
onInit
in class AbstractControl
Control.onInit()
public boolean onProcess()
public boolean onProcess() { bindRequestValue(); if (getValidate()) { validate(); } registerActionEvent(); return true }
onProcess
in interface Control
onProcess
in class AbstractControl
Control.onProcess()
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 void setErrorMessage(String key, Object 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 void setErrorMessage(String key, int 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 void setErrorMessage(String key, double 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()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |