Class InputElement
- All Implemented Interfaces:
Serializable,Cloneable,org.zkoss.zk.ui.Component,org.zkoss.zk.ui.ext.Disable,org.zkoss.zk.ui.ext.Readonly,org.zkoss.zk.ui.ext.Scope,org.zkoss.zk.ui.sys.ComponentCtrl,Constrainted
- Direct Known Subclasses:
FormatInputElement,Textbox
Events: onChange, onChanging, onFocus, onBlur, onSelection.
- Author:
- tomyeh
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.zkoss.zk.ui.HtmlBasedComponent
org.zkoss.zk.ui.HtmlBasedComponent.ExtraCtrlNested classes/interfaces inherited from class org.zkoss.zk.ui.AbstractComponent
org.zkoss.zk.ui.AbstractComponent.Children, org.zkoss.zk.ui.AbstractComponent.ForwardInfo, org.zkoss.zk.ui.AbstractComponent.TargetInfo -
Field Summary
FieldsFields inherited from class org.zkoss.zk.ui.HtmlBasedComponent
_zclassFields inherited from interface org.zkoss.zk.ui.Component
APPLICATION_SCOPE, COMPONENT_SCOPE, DESKTOP_SCOPE, PAGE_SCOPE, REQUEST_SCOPE, SESSION_SCOPE, SPACE_SCOPEFields inherited from interface org.zkoss.zk.ui.sys.ComponentCtrl
AFTER_CHILD_ADDED, AFTER_CHILD_REMOVED, AFTER_CLONED, AFTER_PAGE_ATTACHED, AFTER_PAGE_DETACHED, AFTER_PARENT_CHANGED, CE_BUSY_IGNORE, CE_DUPLICATE_IGNORE, CE_IMPORTANT, CE_NON_DEFERRABLE, CE_REPEAT_IGNORE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidChecks whether user entered a wrong value (and not correct it yet).voidClears the error message.voidclearErrorMessage(boolean revalidateRequired) Clears the error message.clone()protected abstract ObjectcoerceFromString(String value) Coerces the value passed tosetText(java.lang.String).protected abstract StringcoerceToString(Object value) Coerces the value passed tosetText(java.lang.String).intgetCols()Returns the cols.Returns the constraint, or null if no constraint at all.Returns the raw constraint string value if any.Returns the class name of the custom style applied to the errorbox icon of this component.Returns the class name of the custom style applied to the errorbox of this component.Returns the error message that is caused when user entered invalid value, or null if no error at all.Returns the additional attributes which is set bysetInputAttributes(Map<String, String> inputAttributes).booleanReturns true if onChange event is sent as soon as user types in the input component.intReturns the maxlength.getName()Returns the name of this component.Returns the placeholder textorg.zkoss.zk.ui.sys.PropertyAccessgetPropertyAccess(String prop) Returns the text directly without checking whether any error message not yet fixed.Returns the raw value directly with checking whether any error message not yet fixed.protected ObjectReturns the value in the targeting type.getText()Returns the value in the String format.getType()Returns the type.protected booleanNot childable.booleanReturns whether it is disabled.booleanReturns whether enable the inplace-editing.booleanReturns true if onChange event is sent as soon as user types in the input component.booleanReturns whether it is multiline.booleanReturns whether it is readonly.booleanisValid()Returns the current content of this input is correct.protected ObjectMarshall value to be sent to the client if needed.org.zkoss.zk.ui.WrongValueExceptiononWrongValue(org.zkoss.zk.ui.WrongValueException ex) protected voidrenderProperties(org.zkoss.zk.ui.sys.ContentRenderer renderer) voidselect()Selects the whole text in this input.voidservice(org.zkoss.zk.au.AuRequest request, boolean everError) Processes an AU request.voidsetCols(int cols) Sets the cols which determines the visible width, in characters.voidsetConstraint(String constr) voidsetConstraint(Constraint constr) Sets the constraint.voidsetDisabled(boolean disabled) Sets whether it is disabled.voidsetErrorboxIconSclass(String iconSclass) Sets the class name of the custom style to be applied to the errorbox icon of this component.voidsetErrorboxSclass(String sclass) Sets the class name of the custom style to be applied to the errorbox of this component.voidsetErrorMessage(String errmsg) Associates an error message to this input.voidsetInplace(boolean inplace) Sets to enable the inplace-editing function that the look and feel is like a label.voidsetInputAttributes(String inputAttributes) Sets some additional attributes to the input html tag in the component.voidsetInputAttributes(Map<String, String> inputAttributes) Sets some additional attributes to the input html tag in the component.voidsetInsertedText(String text) Inserts the text at the current cursor position.voidsetInstant(boolean instant) Sets the instant attribute.voidsetMaxlength(int maxlength) Sets the maxlength.voidSets the name of this component.voidsetPlaceholder(String placeholder) Sets the placeholder text that is displayed when input is empty.voidsetRawValue(Object value) Sets the raw value directly.voidsetReadonly(boolean readonly) Sets whether it is readonly.voidsetSelectedText(int start, int end, String newtxt, boolean isHighLight) Sets the text of this InputElement to the specified text which is beginning with the new start point and ending with the new end point.voidsetSelectionRange(int start, int end) Sets the selection end to the specified position and the selection start to the specified position.voidSets the value in the String format.protected voidsetValueDirectly(Object value) Sets the value directly.protected org.zkoss.zk.ui.WrongValueExceptionshowCustomError(org.zkoss.zk.ui.WrongValueException ex) Shows the error message in the custom way by calling (CustomConstraint.showCustomError(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.WrongValueException), if the constraint implementsCustomConstraint.protected Objectunmarshall(Object value) Unmarshall value returned from client if needed.protected voidValidates the value returned bycoerceFromString(java.lang.String).Methods inherited from class org.zkoss.zul.impl.XulElement
getContext, getCtrlKeys, getPopup, getTooltip, setContext, setContext, setContextAttributes, setCtrlKeys, setPopup, setPopup, setPopupAttributes, setTooltip, setTooltip, setTooltipAttributesMethods inherited from class org.zkoss.zk.ui.HtmlBasedComponent
addSclass, evalCSSFlex, focus, getAction, getClientAction, getDraggable, getDroppable, getExtraCtrl, getHeight, getHflex, getLeft, getRenderdefer, getSclass, getSkeleton, getStyle, getTabindex, getTabindexInteger, getTooltiptext, getTop, getVflex, getWidth, getZclass, getZindex, getZIndex, removeSclass, removeSclass, setAction, setClass, setClientAction, setDraggable, setDroppable, setFocus, setHeight, setHeight0, setHeightDirectly, setHflex, setHflex0, setHflexDirectly, setLeft, setLeftDirectly, setRenderdefer, setSclass, setSkeleton, setStyle, setTabindex, setTabindex, setTooltiptext, setTop, setTopDirectly, setVflex, setVflex0, setVflexDirectly, setWidth, setWidth0, setWidthDirectly, setZclass, setZindex, setZIndex, setZIndexDirectlyMethods inherited from class org.zkoss.zk.ui.AbstractComponent
addAnnotation, addCallback, addClientEvent, addEventHandler, addEventListener, addEventListener, addForward, addForward, addForward, addForward, addMoved, addRedrawCallback, addScopeListener, addShadowRoot, addShadowRootBefore, addSharedEventHandlerMap, appendChild, applyProperties, beforeChildAdded, beforeChildRemoved, beforeParentChanged, destroyIndexCacheMap, detach, didActivate, didActivate, didDeserialize, didDeserialize, disableBindingAnnotation, disableClientUpdate, disableHostChanged, enableBindingAnnotation, enableHostChanged, getAnnotatedProperties, getAnnotatedPropertiesBy, getAnnotation, getAnnotations, getAnnotations, getAttribute, getAttribute, getAttribute, getAttributeOrFellow, getAttributes, getAttributes, getAuService, getAutag, getCallback, getChildren, getClientAttribute, getClientDataAttribute, getClientEvents, getDefaultMold, getDefinition, getDesktop, getEventHandler, getEventHandlerNames, getEventListenerMap, getEventListeners, getFellow, getFellow, getFellowIfAny, getFellowIfAny, getFellows, getFirstChild, getForwards, getId, getIndexCacheMap, getLastChild, getMold, getNextSibling, getPage, getParent, getPreviousSibling, getRedrawCallback, getRoot, getShadowFellowIfAny, getShadowRoots, getShadowVariable, getShadowVariable, getShadowVariable0, getSpaceOwner, getSpecialRendererOutput, getStubonly, getStubonlyDescendants, getSubBindingAnnotationCount, getTemplate, getTemplateNames, getUuid, getWidgetAttributeNames, getWidgetClass, getWidgetListener, getWidgetListenerNames, getWidgetOverride, getWidgetOverrideNames, hasAttribute, hasAttribute, hasAttribute, hasAttributeOrFellow, hasBindingAnnotation, hasFellow, hasFellow, hasSubBindingAnnotation, initIndexCacheMap, insertBefore, invalidate, isDisabledHostChanged, isInitialized, isInvalidated, isListenerAvailable, isVisible, onChildAdded, onChildRemoved, onPageAttached, onPageDetached, onParentChanged, query, queryAll, redraw, redrawChildren, removeAttribute, removeAttribute, removeAttribute, removeCallback, removeChild, removeEventListener, removeForward, removeForward, removeRedrawCallback, removeScopeListener, removeShadowRoot, render, render, render, renderPropertiesOnly, replace, response, response, response, service, sessionDidActivate, sessionWillPassivate, setAttribute, setAttribute, setAttribute, setAuService, setAutag, setClientAttribute, setClientDataAttribute, setDefinition, setDefinition, setId, setMold, setPage, setPageBefore, setParent, setStubonly, setStubonly, setStubonlyDescendants, setSubBindingAnnotationCount, setTemplate, setVisible, setVisibleDirectly, setWidgetClass, setWidgetListener, setWidgetOverride, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdateWidgetListener, smartUpdateWidgetOverride, toString, updateByClient, updateSubBindingAnnotationCount, willPassivate, willPassivate, willSerialize, willSerialize
-
Field Details
-
_value
The value. -
_cols
protected int _cols
-
-
Constructor Details
-
InputElement
public InputElement()
-
-
Method Details
-
getPlaceholder
Returns the placeholder text- Since:
- 6.5.0
-
setPlaceholder
Sets the placeholder text that is displayed when input is empty. Only works for browsers supporting HTML5.- Since:
- 6.5.0
-
setInplace
public void setInplace(boolean inplace) Sets to enable the inplace-editing function that the look and feel is like a label.- Since:
- 5.0.0
-
isInplace
public boolean isInplace()Returns whether enable the inplace-editing.default: false.
- Since:
- 5.0.0
-
isDisabled
public boolean isDisabled()Returns whether it is disabled.Default: false.
- Specified by:
isDisabledin interfaceorg.zkoss.zk.ui.ext.Disable
-
setDisabled
public void setDisabled(boolean disabled) Sets whether it is disabled.- Specified by:
setDisabledin interfaceorg.zkoss.zk.ui.ext.Disable
-
isReadonly
public boolean isReadonly()Returns whether it is readonly.Default: false.
- Specified by:
isReadonlyin interfaceorg.zkoss.zk.ui.ext.Readonly
-
setReadonly
public void setReadonly(boolean readonly) Sets whether it is readonly.- Specified by:
setReadonlyin interfaceorg.zkoss.zk.ui.ext.Readonly
-
getName
Returns the name of this component.Default: null.
Don't use this method if your application is purely based on ZK's event-driven model.
The name is used only to work with "legacy" Web application that handles user's request by servlets. It works only with HTTP/HTML-based browsers. It doesn't work with other kind of clients.
-
setName
Sets the name of this component.Don't use this method if your application is purely based on ZK's event-driven model.
The name is used only to work with "legacy" Web application that handles user's request by servlets. It works only with HTTP/HTML-based browsers. It doesn't work with other kind of clients.
- Parameters:
name- the name of this component.
-
getErrorMessage
Returns the error message that is caused when user entered invalid value, or null if no error at all.The error message is set when user has entered a wrong value, or setValue is called with a wrong value. It is cleared once a correct value is assigned.
If the error message is set, we say this input is in the error mode. Any following invocation to
getText()or getValue will throw any exception. Example,Textbox.getValue()andIntbox.getValue(). -
setErrorMessage
Associates an error message to this input. It will cause the given error message to be shown at the client.Notice that the application rarely invokes this method. Rather, throw
WrongValueExceptioninstead.Notice it does not invoke
CustomConstraint.showCustomError(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.WrongValueException)even ifgetConstraint()implementsCustomConstraint.- Since:
- 5.0.4
-
clearErrorMessage
public void clearErrorMessage(boolean revalidateRequired) Clears the error message.The error message is cleared automatically, so you rarely need to call this method. However, if a constraint depends on multiple input fields and the error can be corrected by changing one of these fields, then you may have to clear the error message manually by invoking this method.
For example, assume you have two
Intboxand want the value of the first one to be smaller than that of the second one. Then, you have to call this method for the second intbox once the validation of the first intbox succeeds, and vice versa. Otherwise, the error message for the second intbox remains if the user fixed the error by lowering down the value of the first one Why? The second intbox got no idea to clear the error message (since its content doesn't change).- Parameters:
revalidateRequired- whether to re-validate the current value whengetText()or others (such asIntbox.getValue()) is called. If false, the current value is assumed to be correct and the following invocation togetText()or others (such asIntbox.getValue()) won't check the value again. Note: when an input element is constructed, the initial value is assumed to be "not-validated-yet".- Since:
- 3.0.1
-
clearErrorMessage
public void clearErrorMessage()Clears the error message. It is the same as clearErrorMessage(false). That is, the current value is assumed to be correct.getText()or others (such asIntbox.getValue()) won't re-validate it again.The error message is cleared automatically, so you rarely need to call this method.
- See Also:
-
getText
Returns the value in the String format. In most case, you shall use the setValue method instead, e.g.,Textbox.getValue()andIntbox.getValue().It invokes
checkUserError()to ensure no user error.It invokes
coerceToString(java.lang.Object)to convert the stored value into a string.- Throws:
org.zkoss.zk.ui.WrongValueException- if user entered a wrong value
-
setText
Sets the value in the String format. In most case, you shall use the setValue method instead, e.g.,Textbox.setValue(java.lang.String)andIntbox.setValue(java.lang.Integer).It invokes
coerceFromString(java.lang.String)first and thenvalidate(java.lang.Object). Derives might override them for type conversion and special validation.- Parameters:
value- the value; If null, it is considered as empty.- Throws:
org.zkoss.zk.ui.WrongValueException
-
coerceFromString
Coerces the value passed tosetText(java.lang.String).Deriving note:
If you want to store the value in other type, say BigDecimal, you have to overridecoerceToString(java.lang.Object)andcoerceFromString(java.lang.String)to convert between a string and your targeting type.Moreover, when
Textboxis called, it calls this method with value = null. Derives shall handle this case properly.- Throws:
org.zkoss.zk.ui.WrongValueException
-
coerceToString
Coerces the value passed tosetText(java.lang.String).Default: convert null to an empty string.
Deriving note:
If you want to store the value in other type, say BigDecimal, you have to overridecoerceToString(java.lang.Object)andcoerceFromString(java.lang.String)to convert between a string and your targeting type. -
validate
Validates the value returned bycoerceFromString(java.lang.String).Default: use
getConstraint()'sConstraint.validate(org.zkoss.zk.ui.Component, java.lang.Object), if not null.You rarely need to override this method.
- Throws:
org.zkoss.zk.ui.WrongValueException
-
showCustomError
protected org.zkoss.zk.ui.WrongValueException showCustomError(org.zkoss.zk.ui.WrongValueException ex) Shows the error message in the custom way by calling (CustomConstraint.showCustomError(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.WrongValueException), if the constraint implementsCustomConstraint.Derived class shall call this method before throwing
WrongValueException, such that the constraint, if any, has a chance to show the error message in a custom way.- Parameters:
ex- the exception, or null to clean up the error.- Returns:
- the exception (ex)
-
getMaxlength
public int getMaxlength()Returns the maxlength.Default: 0 (non-positive means unlimited).
-
setMaxlength
public void setMaxlength(int maxlength) Sets the maxlength.The length includes the format, if specified.
-
getCols
public int getCols()Returns the cols.Default: 0 (non-positive means the same as browser's default).
-
setCols
public void setCols(int cols) throws org.zkoss.zk.ui.WrongValueException Sets the cols which determines the visible width, in characters.- Throws:
org.zkoss.zk.ui.WrongValueException
-
getInstant
public boolean getInstant()Returns true if onChange event is sent as soon as user types in the input component.Default: false
- Since:
- 6.0.0
-
isInstant
public boolean isInstant()Returns true if onChange event is sent as soon as user types in the input component.Default: false
- Since:
- 8.0.0
-
setInstant
public void setInstant(boolean instant) Sets the instant attribute. When the attribute is true, onChange event will be fired as soon as user type in the input component.- Since:
- 6.0.0
-
isMultiline
public boolean isMultiline()Returns whether it is multiline.Default: false.
-
getType
Returns the type.Default: text.
-
select
public void select()Selects the whole text in this input. -
setConstraint
-
setConstraint
Description copied from interface:ConstraintedSets the constraint.Default: null (means no constraint all all).
- Specified by:
setConstraintin interfaceConstrainted
-
getConstraint
Description copied from interface:ConstraintedReturns the constraint, or null if no constraint at all.- Specified by:
getConstraintin interfaceConstrainted
-
getConstraintString
Returns the raw constraint string value if any.- Since:
- 10.0.0
-
getTargetValue
Returns the value in the targeting type. It is used by the deriving class to implement the getValue method. For example,Intbox.getValue()is the same as this method except with a different signature.It invokes
checkUserError()to ensure no user error.- Throws:
org.zkoss.zk.ui.WrongValueException- if the user entered a wrong value- See Also:
-
getRawValue
Returns the raw value directly with checking whether any error message not yet fixed. In other words, it does NOT invokecheckUserError().Note: if the user entered an incorrect value (i.e., caused
WrongValueException), the incorrect value doesn't be stored so this method returned the last correct value. -
getRawText
Returns the text directly without checking whether any error message not yet fixed. In other words, it does NOT invokecheckUserError().Note: if the user entered an incorrect value (i.e., caused
WrongValueException), the incorrect value doesn't be stored so this method returned the last correct value.- See Also:
-
setRawValue
Sets the raw value directly. The caller must make sure the value is correct (or intend to be incorrect), because this method doesn't do any validation.If you feel confusing with setValue, such as
Textbox.setValue(java.lang.String), it is usually better to use setValue instead. This method is reserved for developer that really want to set an 'illegal' value (such as an empty string to a textbox with no-empty constraint).Note: since 3.0.1, the value will be re-validate again if
getText()or others (such asIntbox.getValue()) is called. In other words, it is assumed that the specified value is not validated yet -- the same state when this component is created. If you want to avoid the re-validation, you have to invokeclearErrorMessage().Like setValue, the result is returned back to the server by calling
getText().- See Also:
-
setValueDirectly
Sets the value directly. Note: UnlikesetRawValue(java.lang.Object)(nor setValue), this method assigns the value directly without clearing error message or synchronizing with the client.It is usually used only the constructor. Though it is also OK to use
setRawValue(java.lang.Object)in the constructor, this method has better performance.- Since:
- 3.0.3
-
isValid
public boolean isValid()Returns the current content of this input is correct. If the content is not correct, next call to the getValue method will throws WrongValueException. -
setSelectedText
Sets the text of this InputElement to the specified text which is beginning with the new start point and ending with the new end point.- Parameters:
start- the start position of the text (included)end- the end position of the text (excluded)newtxt- the new text to be set.isHighLight- Sets whether it will represent highlight style or cursor style.If the start point same with the end point always represent cursor style.
-
setSelectionRange
public void setSelectionRange(int start, int end) Sets the selection end to the specified position and the selection start to the specified position. The new end point is constrained to be at or after the current selection start. If the new start point is different with the new end point, then will represent the result of highlight in this text.Set both arguments to the same value to move the cursor to the corresponding position without selecting text.
- Parameters:
start- the start position of the text (included)end- the end position of the text (excluded)
-
setInsertedText
Inserts the text at the current cursor position. It would trigger focus and change event.- Parameters:
text- the text to be inserted- Since:
- 8.5.1
-
checkUserError
protected void checkUserError() throws org.zkoss.zk.ui.WrongValueExceptionChecks whether user entered a wrong value (and not correct it yet). Since user might enter a wrong value and moves on to other components, this method is called whengetText()orgetTargetValue()is called.Derives rarely need to access this method if they use only
getText()andgetTargetValue().- Throws:
org.zkoss.zk.ui.WrongValueException
-
getErrorboxSclass
Returns the class name of the custom style applied to the errorbox of this component.- Returns:
- Sclass
- Since:
- 8.0.1
-
setErrorboxSclass
Sets the class name of the custom style to be applied to the errorbox of this component.- Parameters:
sclass-- Since:
- 8.0.1
-
getErrorboxIconSclass
Returns the class name of the custom style applied to the errorbox icon of this component.- Returns:
- Sclass
- Since:
- 8.0.1
-
setErrorboxIconSclass
Sets the class name of the custom style to be applied to the errorbox icon of this component.- Parameters:
iconSclass-- Since:
- 8.0.1
-
getInputAttributes
Returns the additional attributes which is set bysetInputAttributes(Map<String, String> inputAttributes).- Returns:
- inputAttributes a Map with attribute names as the keys.
- Since:
- 8.6.1
-
setInputAttributes
Sets some additional attributes to the input html tag in the component. This will only reset the additional attributes that are set by this method.- Parameters:
inputAttributes- a Map with attribute names as the keys.- Since:
- 8.6.1
-
setInputAttributes
Sets some additional attributes to the input html tag in the component. This will only reset the additional attributes that are set by this method.- Parameters:
inputAttributes- a String of attribute separate by ";" and follow name=value rule. for example: "spellcheck=true;autocorrect=on"- Since:
- 8.6.1
-
isChildable
protected boolean isChildable()Not childable.- Overrides:
isChildablein classorg.zkoss.zk.ui.AbstractComponent
-
onWrongValue
public org.zkoss.zk.ui.WrongValueException onWrongValue(org.zkoss.zk.ui.WrongValueException ex) - Specified by:
onWrongValuein interfaceorg.zkoss.zk.ui.sys.ComponentCtrl- Overrides:
onWrongValuein classorg.zkoss.zk.ui.AbstractComponent
-
marshall
Marshall value to be sent to the client if needed.Overrides it if the value to be sent to the client is not JSON Compatible.
- Parameters:
value- the value to be sent to the client- Returns:
- the marshalled value
- Since:
- 5.0.5
-
unmarshall
Unmarshall value returned from client if needed.Overrides it if the value returned is not JSON Compatible.
- Parameters:
value- the value returned from client- Returns:
- the unmarshalled value
- Since:
- 5.0.5
-
service
public void service(org.zkoss.zk.au.AuRequest request, boolean everError) Processes an AU request.Default: in addition to what are handled by
HtmlBasedComponent.service(org.zkoss.zk.au.AuRequest, boolean), it also handles onChange, onChanging and onError.- Specified by:
servicein interfaceorg.zkoss.zk.ui.sys.ComponentCtrl- Overrides:
servicein classorg.zkoss.zk.ui.HtmlBasedComponent- Since:
- 5.0.0
-
renderProperties
- Overrides:
renderPropertiesin classXulElement- Throws:
IOException
-
getPropertyAccess
- Specified by:
getPropertyAccessin interfaceorg.zkoss.zk.ui.sys.ComponentCtrl- Overrides:
getPropertyAccessin classXulElement
-
clone
- Specified by:
clonein interfaceorg.zkoss.zk.ui.Component- Overrides:
clonein classXulElement
-