Show TOC

 Creating Formatted TextLocate this document in the navigation structure

To display text in a FormattedTextView or a FormattedTextEdit, you have to provide the content that you want to display as type FormattedText. For the FormattedTextView, you can set the content to be displayed by choosing . For a string to be converted into FormattedText, it must contain a well-formed and valid XML document.

To create this type, use the WDFormattedTextFactory.

The WDFormattedTextFactory provides two methods to create a FormattedText from a string:

  • IWDFormattedText valueOf(Stringtext)

Use this method to create FormattedTextfrom a markup language-formatted string.

  • IWDFormattedText fromPlainText(String text)

    Use this method to create FormattedText from plain text. The following escape sequences will be ignored.

    \b

    backspace

    \n

    newline

    \f

    formfeed

    \r

    carriage return

    \t

    horizontal tabulator

Procedure
  1. In your Web Dynpro DC, navigate to the corresponding view and insert a FormattedTextView or a FormattedTextEdit.
  2. Select the Context tab and create an attribute called text of type FormattedText .
  3. Bind the relevant property to this context attribute:
    • For FormattedTextView, bind property text
    • For FormattedTextEdit, bind property value
  4. Insert the following source code into the wdDoInit method of your view controller:
    wdDoInit()

    String htmlText = "<strong>hello I'm bold!</strong>";

    IWDFormattedText formattedText = WDFormattedTextFactory.valueOf(htmlText);

    wdContext.currentContextElement().setText(formattedText);

Result

The following screenshot illustrates the result: