Class WText

    • Constructor Detail

      • WText

        public WText()
        Creates an empty WText.
      • WText

        public WText​(String text,
                     Serializable... args)
        Creates a WText with the given initial text.
        Parameters:
        text - the text to display, using MessageFormat syntax.
        args - optional arguments for the message format string.
         // Will display the text "Hello world"
         new WText("Hello world");
         
         // Will display "Secret agent James Bond, 007"
         new WText("Secret agent {0}, {1,number,000}", "James Bond", 7);
         
    • Method Detail

      • getData

        public Object getData()
        Returns the data for this component. The following are searched in order:
        • a value set explicitly in the ui context using WBeanComponent.setData(Object);
        • if a bean is available; the bean's value; or
        • the value set on the shared model.
        Specified by:
        getData in interface DataBound
        Overrides:
        getData in class WBeanComponent
        Returns:
        the current value of this component for the given context
      • getText

        public String getText()
        Returns:
        the current text.
      • setText

        public void setText​(String text,
                            Serializable... args)

        Sets the text.

        NOTE: If the text is dynamically generated, it may be preferable to override getText() instead. This will reduce the amount of data which is stored in the user session.

        Parameters:
        text - the text to set, using MessageFormat syntax.
        args - optional arguments for the message format string.
         // Changes the text to "Hello world"
         myText.setText("Hello world");
         
         // Changes the text to "Secret agent James Bond, 007"
         new WText("Secret agent {0}, {1,number,000}", "James Bond", 7);
         
      • isEncodeText

        public boolean isEncodeText()
        Indicates whether the heading text needs to be encoded.
        Returns:
        true if the text needs to be encoded, false if not.
      • setEncodeText

        public void setEncodeText​(boolean encodeText)

        Sets whether the text needs to be encoded.

        When setting encodeText to false, it then becomes the responsibility of the application to ensure that the text does not contain any characters which need to be escaped.

        WARNING: If you are using WText to display "user entered" or untrusted data, use of this method with encodeText set to false may result in security issues.

        WARNING: Avoid using WText to add excessive amounts of HTML mark-up to the UI. Embedded mark-up is more likely to break in future WComponent releases. If you are attempting to use WText for layout purposes, consider using a LayoutManager instead. For example, new WText("<br>") could be rewritten to use the FlowLayout layout with a vertical layout direction.

        Parameters:
        encodeText - true if the text needs to be encoded, false if not.
      • setSanitizeOnOutput

        public void setSanitizeOnOutput​(boolean sanitize)
        Pass true if you need to run the HTML sanitizer on any output. This is only needed if the text is not encoded as other cases the output will be XML encoded.
        Parameters:
        sanitize - true if output sanitization is required.
      • isSanitizeOnOutput

        public boolean isSanitizeOnOutput()
        Returns:
        true if this text area is to be sanitized on output.
      • sanitizeOutputText

        protected String sanitizeOutputText​(String text)
        Parameters:
        text - the output text to sanitize
        Returns:
        the sanitized text
      • toString

        public String toString()
        Description copied from class: AbstractWComponent
        Creates a String representation of this component; usually for debugging purposes.
        Overrides:
        toString in class AbstractWComponent
        Returns:
        a String representation of this component, for debugging purposes.
      • getOrCreateComponentModel

        protected WText.TextModel getOrCreateComponentModel()
        Retrieves the model for this component so that it can be modified. If this method is called during request processing, and a session specific model does not yet exist, then a new model is created. Subclasses may override this method to narrow the return type to their specific model type.
        Overrides:
        getOrCreateComponentModel in class WBeanComponent
        Returns:
        the model for this component
      • getComponentModel

        protected WText.TextModel getComponentModel()
        Returns the effective component model for this component. Subclass may override this method to narrow the return type to their specific model type.
        Overrides:
        getComponentModel in class WBeanComponent
        Returns:
        the effective component model