Class InputElement

    • Field Detail

      • _value

        protected java.lang.Object _value
        The value.
      • _cols

        protected int _cols
    • Constructor Detail

      • InputElement

        public InputElement()
    • Method Detail

      • getPlaceholder

        public java.lang.String getPlaceholder()
        Returns the placeholder text
        Since:
        6.5.0
      • setPlaceholder

        public void setPlaceholder​(java.lang.String placeholder)
        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:
        isDisabled in interface Disable
      • setDisabled

        public void setDisabled​(boolean disabled)
        Sets whether it is disabled.
        Specified by:
        setDisabled in interface Disable
      • isReadonly

        public boolean isReadonly()
        Returns whether it is readonly.

        Default: false.

        Specified by:
        isReadonly in interface Readonly
      • setReadonly

        public void setReadonly​(boolean readonly)
        Sets whether it is readonly.
        Specified by:
        setReadonly in interface Readonly
      • getName

        public java.lang.String 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

        public void setName​(java.lang.String name)
        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

        public java.lang.String 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() and Intbox.getValue().

      • 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 Intbox and 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 when getText() or others (such as Intbox.getValue()) is called. If false, the current value is assumed to be correct and the following invocation to getText() or others (such as Intbox.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 as Intbox.getValue()) won't re-validate it again.

        The error message is cleared automatically, so you rarely need to call this method.

        See Also:
        clearErrorMessage(boolean)
      • 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).

      • 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

        public java.lang.String getType()
        Returns the type.

        Default: text.

      • select

        public void select()
        Selects the whole text in this input.
      • setConstraint

        public void setConstraint​(java.lang.String constr)
      • setConstraint

        public void setConstraint​(Constraint constr)
        Description copied from interface: Constrainted
        Sets the constraint.

        Default: null (means no constraint all all).

        Specified by:
        setConstraint in interface Constrainted
      • getConstraintString

        public java.lang.String getConstraintString()
        Returns the raw constraint string value if any.
        Since:
        10.0.0
      • getTargetValue

        protected java.lang.Object getTargetValue()
                                           throws WrongValueException
        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:
        WrongValueException - if the user entered a wrong value
        See Also:
        getText()
      • getRawText

        public java.lang.String getRawText()
        Returns the text directly without checking whether any error message not yet fixed. In other words, it does NOT invoke checkUserError().

        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:
        getRawValue(), getText()
      • setRawValue

        public void setRawValue​(java.lang.Object value)
        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 as Intbox.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 invoke clearErrorMessage().

        Like setValue, the result is returned back to the server by calling getText().

        See Also:
        getRawValue()
      • setValueDirectly

        protected void setValueDirectly​(java.lang.Object value)
        Sets the value directly. Note: Unlike setRawValue(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

        public void setSelectedText​(int start,
                                    int end,
                                    java.lang.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.
        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

        public void setInsertedText​(java.lang.String text)
        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
      • getErrorboxSclass

        public java.lang.String getErrorboxSclass()
        Returns the class name of the custom style applied to the errorbox of this component.
        Returns:
        Sclass
        Since:
        8.0.1
      • setErrorboxSclass

        public void setErrorboxSclass​(java.lang.String sclass)
        Sets the class name of the custom style to be applied to the errorbox of this component.
        Parameters:
        sclass -
        Since:
        8.0.1
      • getErrorboxIconSclass

        public java.lang.String getErrorboxIconSclass()
        Returns the class name of the custom style applied to the errorbox icon of this component.
        Returns:
        Sclass
        Since:
        8.0.1
      • setErrorboxIconSclass

        public void setErrorboxIconSclass​(java.lang.String iconSclass)
        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

        public java.util.Map<java.lang.String,​java.lang.String> getInputAttributes()
        Returns the additional attributes which is set by setInputAttributes(Map<String, String> inputAttributes).
        Returns:
        inputAttributes a Map with attribute names as the keys.
        Since:
        8.6.1
      • setInputAttributes

        public void setInputAttributes​(java.util.Map<java.lang.String,​java.lang.String> inputAttributes)
        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

        public void setInputAttributes​(java.lang.String inputAttributes)
        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
      • marshall

        protected java.lang.Object marshall​(java.lang.Object value)
        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

        protected java.lang.Object unmarshall​(java.lang.Object value)
        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
      • getPropertyAccess

        public PropertyAccess getPropertyAccess​(java.lang.String prop)
        Description copied from interface: ComponentCtrl
        Returns the corresponding property access object from the given property name, if any.
        Specified by:
        getPropertyAccess in interface ComponentCtrl
        Overrides:
        getPropertyAccess in class XulElement
        Parameters:
        prop - the name of the property
        Returns:
        null it means not to support for the property name.
      • clone

        public java.lang.Object clone()
        Description copied from interface: Component
        Clones the component. All of its children and descendants are cloned. Also, ID are preserved.
        Specified by:
        clone in interface Component
        Overrides:
        clone in class XulElement
        Returns:
        the new component. Notice that it doesn't belong to any page, nor desktop. It doesn't have a parent, either.