Class ComponentModel

    • Field Detail

      • VISIBLE_FLAG

        public static final int VISIBLE_FLAG
        The bit-mask for the flag that indicates whether a component is visible.
        See Also:
        Constant Field Values
      • INITIALISED_FLAG

        public static final int INITIALISED_FLAG
        The bit-mask for the flag that indicates whether a component is initialised.
        See Also:
        Constant Field Values
      • DISABLED_FLAG

        public static final int DISABLED_FLAG
        The bit-mask for the flag that indicates whether a component is disabled.
        See Also:
        Constant Field Values
      • READONLY_FLAG

        public static final int READONLY_FLAG
        The bit-mask for the flag that indicates whether a component is read only.
        See Also:
        Constant Field Values
      • MANDATORY_FLAG

        public static final int MANDATORY_FLAG
        The bit-mask for the flag that indicates whether a component is mandatory.
        See Also:
        Constant Field Values
      • VALIDATE_FLAG

        public static final int VALIDATE_FLAG
        The bit-mask for the flag that indicates whether a component needs validation.
        See Also:
        Constant Field Values
      • SUBMIT_ON_CHANGE_FLAG

        @Deprecated
        public static final int SUBMIT_ON_CHANGE_FLAG
        Deprecated.
        1.4.0 as it results in a level A accessibility problem See https://www.w3.org/TR/UNDERSTANDING-WCAG20/consistent-behavior-unpredictable-change.html.
        The bit-mask for the flag that indicates whether a component is submitted on change/click (client side).
        See Also:
        Constant Field Values
      • HIDE_FLAG

        public static final int HIDE_FLAG
        The bit-mask for the flag that indicates whether a component is rendered as "hidden" on the client side.
        See Also:
        Constant Field Values
      • USER_DATA_SET

        public static final int USER_DATA_SET

        The bit-mask for the flag that indicates whether that user data has been set. This is necessary, as some components do not contain enough values to determine this automatically. For example, WCheckBox only has two states (on/off), and could already contain two different "default" values from the shared model and a bean.

        Note: This bit mask must never be set on a component's shared model.

        See Also:
        Constant Field Values
      • ENCODE_TEXT_FLAG

        public static final int ENCODE_TEXT_FLAG
        The bit-mask for the flag that indicates whether a component's text needs to be encoded before output.
        See Also:
        Constant Field Values
      • TRACKABLE_FLAG

        public static final int TRACKABLE_FLAG
        The bit-mask for the flag that indicates whether a component is trackable via analytics.
        See Also:
        Constant Field Values
      • NAMING_CONTEXT_FLAG

        public static final int NAMING_CONTEXT_FLAG
        The bit-mask for the flag that indicates whether a component is a naming context.
        See Also:
        Constant Field Values
      • FLAGS_DEFAULT

        protected static final int FLAGS_DEFAULT
        The bit-mask for the default set of flags: visible, validation required and text encoded.
        See Also:
        Constant Field Values
    • Constructor Detail

      • ComponentModel

        public ComponentModel()
    • Method Detail

      • setAttribute

        public void setAttribute​(String key,
                                 Serializable value)
        Sets an attribute.
        Parameters:
        key - the attribute key
        value - the attribute value
      • getAttribute

        public Serializable getAttribute​(String key)
        Retrieves an attribute.
        Parameters:
        key - the attribute key
        Returns:
        the value of the attribute, or null if the attribute does not exist.
      • removeAttribute

        public Serializable removeAttribute​(String key)
        Removes an attribute.
        Parameters:
        key - the attribute key
        Returns:
        the value of the attribute that was removed, or null if the attribute did not exist.
      • equals

        public boolean equals​(Object obj)
        Indicates whether this ComponentModel is equal to the given object. Subclasses should not need to override this method, as reflection is used to read in all fields.
        Overrides:
        equals in class Object
        Parameters:
        obj - the object to check for equality.
        Returns:
        true if the other object is a ComponentModel and is equal to this model.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
        Returns:
        this model's hash code.
      • setSharedModel

        protected final void setSharedModel​(ComponentModel sharedModel)
        Sets the shared component model. If there are any unset fields, they are set from the values in the shared model.
        Parameters:
        sharedModel - the shared ComponentModel
      • copyData

        protected Object copyData​(Object data)
        Creates a copy of mutable data, to ensure updates to one component model do not update the other.
        Parameters:
        data - the data to copy
        Returns:
        a copy of the data, if it is mutable, otherwise the original data.
      • setAttributes

        protected void setAttributes​(Map<String,​Serializable> attributes)
        Parameters:
        attributes - The attributes to set.
      • getChildren

        protected List<WComponent> getChildren()
        Returns:
        Returns the children.
      • setChildren

        protected void setChildren​(List<WComponent> children)
        Parameters:
        children - The children to set.
      • getFlags

        protected int getFlags()
        Returns:
        Returns the flags.
      • setFlags

        protected void setFlags​(int flags)
        Parameters:
        flags - The flags to set.
      • getParent

        protected Container getParent()
        Returns:
        Returns the parent.
      • setParent

        protected void setParent​(Container parent)
        Parameters:
        parent - The parent to set.
      • setTemplateUrl

        @Deprecated
        public void setTemplateUrl​(String templateUrl)
        Deprecated.
        Use WTemplate instead
        Parameters:
        templateUrl - The templateUrl to set.
      • getTemplateMarkUp

        @Deprecated
        public String getTemplateMarkUp()
        Deprecated.
        Use WTemplate instead
        Returns:
        Returns the template mark-up.
      • setTemplateMarkUp

        @Deprecated
        public void setTemplateMarkUp​(String templateMarkUp)
        Deprecated.
        Use WTemplate instead
        Parameters:
        templateMarkUp - The template mark-up to set.
      • getToolTip

        protected Serializable getToolTip()
        Returns:
        Returns the tool tip text.
      • setToolTip

        protected void setToolTip​(String text,
                                  Serializable... args)
        Parameters:
        text - The tool tip to set.
        args - optional message format arguments.
      • getAccessibleText

        protected Serializable getAccessibleText()
        Returns:
        Returns the accessible text.
      • setAccessibleText

        protected void setAccessibleText​(String text,
                                         Serializable... args)
        Parameters:
        text - The accessible text to set.
        args - optional message format arguments.
      • getHtmlClass

        protected Serializable getHtmlClass()
        Returns:
        the HTML class list as a single space separated String.
      • setHtmlClass

        protected void setHtmlClass​(String text)
        Parameters:
        text - The HTML class name text to set.
      • setHtmlClass

        protected void setHtmlClass​(HtmlClassProperties className)
        Parameters:
        className - The HTML class name to set.
      • addHtmlClass

        protected void addHtmlClass​(String text)
        Parameters:
        text - The HTML class name text to set.
      • addHtmlClass

        protected void addHtmlClass​(HtmlClassProperties className)
        Parameters:
        className - The HTML class name to set.
      • getHtmlClasses

        protected Set getHtmlClasses()
        Returns:
        the set of HTML classes to add to the current component.
      • removeHtmlClass

        protected void removeHtmlClass​(String className)
        Remove a value from the HTML class name list.
        Parameters:
        className - the value to remove
      • removeHtmlClass

        protected void removeHtmlClass​(HtmlClassProperties className)
        Remove a value from the HTML class name list.
        Parameters:
        className - the property representing the value to remove
      • getLabel

        public WLabel getLabel()
        Returns:
        the label associated with this component.
      • setLabel

        public void setLabel​(WLabel label)
        Sets the label associated with this component.
        Parameters:
        label - the label to associate with this component.
      • getSharedModel

        protected ComponentModel getSharedModel()
        Returns:
        Returns the sharedModel.
      • getIdName

        protected String getIdName()
        Returns:
        the id name.
      • setIdName

        protected void setIdName​(String idName)
        Parameters:
        idName - the id name to set.
      • getContextIds

        protected Map<String,​WComponent> getContextIds()
        Returns:
        the map of registered ids for the naming context
      • setContextIds

        protected void setContextIds​(Map<String,​WComponent> contextIds)
        Parameters:
        contextIds - the map holding the registered ids for the naming context
      • readExternal

        public void readExternal​(ObjectInput in)
                          throws IOException,
                                 ClassNotFoundException

        Implementation of the Externalizable interface to ensure that we don't serialize redundant data (anything contained by the sharedModel.

        Data is obtained using reflection so that subclasses don't need concern themselves with the ComponentModel serialization mechanism.

        After the ComponentModel data is read in, some fields may be in a "unset" state. The static model needs to be supplied using setSharedModel(ComponentModel)

        Specified by:
        readExternal in interface Externalizable
        Parameters:
        in - the ObjectInput to read from.
        Throws:
        IOException - if there is an error reading from the ObjectInput
        ClassNotFoundException - If the class of a serialized object cannot be found.
      • writeExternal

        public void writeExternal​(ObjectOutput out)
                           throws IOException

        Implementation of the Externalizable interface to ensure that we don't serialize redundant data (anything contained by the sharedModel.

        Data is obtained using reflection so that subclasses don't need concern themselves with the ComponentModel serialization mechanism.

        Specified by:
        writeExternal in interface Externalizable
        Parameters:
        out - the ObjectOutput to write to.
        Throws:
        IOException - if there is an error writing to the ObjectOutput