Show TOC

 FormattedTextViewLocate this document in the navigation structure

This UI element is used to display formatted text using a simple, XML-compatible syntax. You can use a FormattedTextView to simply and quickly format larger sections of texts, for example, an introduction or copyright information. The text may contain links, images or structured lists.

The XML format of the FormattedTextView supports an XHTML subset as well as some SAP-specific tags (see Supported Tags ). The XHTML tags must not contain any attributes.

The service class CL_WD_FORMATTED_TEXT is for use with FormattedTextView. One instance of this class represents one formatted text.

Note

To enable the development of accessible applications, the tooltip property is not checked during the syntax check.

A tooltip does not necessarily have to be set for this UI element, but it could make sense to set it if it contains detailed semantic information.

Runtime Class

CL_WD_FORMATTED_TEXT_VIEW

Properties in the View Designer

Name Type Initial Value Bindable

id

STRING

(automatic)

No

contextMenuBehaviour

WDUI_CONTEXT_MENU_BEHAVIOUR

inherit

No

contextMenuId

WDY_MD_UI_ELEMENT_REFERENCE

No

dataSource

Context node

Yes

enabled

WDY_BOOLEAN

true

Yes

hAlign

WDUI_INPUT_FIELD_ALIGNMENT

auto

Yes

text

Translatable text

Yes

textDirection

WDUI_TEXT_DIRECTION

inherit

Yes

tooltip

Translatable text

Yes

visible

WDUI_VISIBILITY

visible

Yes

Aggregations in the View Designer

Name Cardinality Type

Field

0..n

AbstractFormattedTextField

Events in the View Designer

Name

onAction

Note

Other properties that can be inherited are defined in the associated higher-level classes. The associated UI elements are:

Dynamic Programming

For dynamic programming, the same properties, events, and aggregations as in the View Designer are available. Bear in mind the different spellings.

Dynamic Programming of Properties

View Designer Name Runtime Name Type

contextMenuBehaviour

CONTEXT_MENU_BEHAVIOUR

WDUI_CONTEXT_MENU_BEHAVIOUR

 contextMenuBehaviour: inherit

CL_WD_FORMATTED_TEXT_VIEW=>E_CONTEXT_MENU_BEHAVIOUR-INHERIT

 contextMenuBehaviour: provide

CL_WD_FORMATTED_TEXT_VIEW=>E_CONTEXT_MENU_BEHAVIOUR-PROVIDE

 contextMenuBehaviour: suppress

CL_WD_FORMATTED_TEXT_VIEW=>E_CONTEXT_MENU_BEHAVIOUR-SUPPRESS

contextMenuId

CONTEXT_MENU_ID

WDY_MD_UI_ELEMENT_REFERENCE

dataSource

DATA_SOURCE

OBJECT

enabled

ENABLED

WDY_BOOLEAN

hAlign

H_ALIGN

WDUI_INPUT_FIELD_ALIGNMENT

 hAlign: auto

CL_WD_FORMATTED_TEXT_VIEW=>E_H_ALIGN-AUTO

 hAlign: beginOfLine

CL_WD_FORMATTED_TEXT_VIEW=>E_H_ALIGN-BEGIN_OF_LINE

 hAlign: center

CL_WD_FORMATTED_TEXT_VIEW=>E_H_ALIGN-CENTER

 hAlign: endOfLine

CL_WD_FORMATTED_TEXT_VIEW=>E_H_ALIGN-END_OF_LINE

 hAlign: forcedLeft

CL_WD_FORMATTED_TEXT_VIEW=>E_H_ALIGN-FORCED_LEFT

 hAlign: forcedRight

CL_WD_FORMATTED_TEXT_VIEW=>E_H_ALIGN-FORCED_RIGHT

text

TEXT

WDY_MD_TRANSLATABLE_TEXT

textDirection

TEXT_DIRECTION

WDUI_TEXT_DIRECTION

textDirection inherit

CL_WD_FORMATTED_TEXT_VIEW=>E_TEXT_DIRECTION-INHERIT

textDirection ltr

CL_WD_FORMATTED_TEXT_VIEW=>E_TEXT_DIRECTION-LTR

textDirection rtl

CL_WD_FORMATTED_TEXT_VIEW=>E_TEXT_DIRECTION-RTL

tooltip

TOOLTIP

WDY_MD_TRANSLATABLE_TEXT

visible

VISIBLE

WDUI_VISIBILITY

visible: none

CL_WD_FORMATTED_TEXT_VIEW=>E_VISIBLE-NONE

visible: visible

CL_WD_FORMATTED_TEXT_VIEW=>E_VISIBLE-VISIBLE

Dynamic Programming of Events

View Designer Name Runtime Name

onAction

ON_ACTION

Dynamic Programming of Aggregations

View Designer Name Runtime Name Cardinality

Field

FIELDS

0..n

You can convert SAPscript texts into formatted texts by calling static method CL_WD_FORMATTED_TEXT=> CREATE_FROM_SAPSCRIPT.

Example

data formatted_text type ref to cl_wd_formatted_text. " convert from context formatted_text = cl_wd_formatted_text=> create_from_sapscript(   sapscript_head  = sapscript_head   sapscript_lines = sapscript_lines ). " set it into the context wd_context->set_attribute(   name  = my_formatted_text_attr


  value = formatted_text->m_xml_text ). cl_wd_formatted_text=>write_sapscript_tokens( ).

Note that not all SAPscript properties and formats are valid with FormattedTextView. The following list shows how SAPscript escape sequences are converted into formatted texts.

Type Subtype Replacement Description

PARAGRAPH_BEGIN

U1

<h1>

U1 Header

PARAGRAPH_BEGIN

U2

<h2>

U2 Header

PARAGRAPH_BEGIN

U3

<h3>

U3 Header

PARAGRAPH_BEGIN

U4

<h4>

U4 Header

PARAGRAPH_BEGIN

U5

<h5>

U5 Header

PARAGRAPH_BEGIN

UT

<h6>

UT Header

PARAGRAPH_BEGIN

AS

<p>

AS Default paragraph

PARAGRAPH_BEGIN

*

<p>

* Default paragraph

PARAGRAPH_BEGIN

PE

<pre>

PE Default paragraph

PARAGRAPH_BEGIN

B1

<ul>

B1 Bullet list item

PARAGRAPH_BEGIN

B2

<ul>

B2 Bullet list item (2)

PARAGRAPH_BEGIN

BL

<dd>

BL Bullet / list comment

PARAGRAPH_BEGIN

D1

<dl>

D1 Definition list

PARAGRAPH_BEGIN

N1

<ol>

N1 Numbered list item

PARAGRAPH_BEGIN

N2

<ol>

N2 Numbered list item (2)

CTAG_BEGIN

AB

<code>

AB ABAP language

CTAG_BEGIN

DS

<acronym>

DS DSYS reference

CTAG_BEGIN

EX

<samp>

EX ABAP example

CTAG_BEGIN

GL

<dfn>

GL Glossary reference

CTAG_BEGIN

LB

<kbd>

LB User input

CTAG_BEGIN

LS

<var>

LS Screen element

CTAG_BEGIN

NP

<code>

NP Fixed width font

CTAG_BEGIN

PF

<strong><kbd>

PF Function key

CTAG_BEGIN

SE

<em>

SE SAP expression

CTAG_BEGIN

ZG

ZG Protected

CTAG_BEGIN

PF

<strong>

ZH Emphasized

CTAG_BEGIN

ZK

<em>

ZK Italic

CTAG_BEGIN

ZU

<em>

ZU Underlined (not supported)

CTAG_BEGIN

ZV

ZV Hidden

COMMENT

Comment

ELEMENT_BEGIN

Element

LINE_BEGIN

Line

STRING

String

OPTION

Option -> Not supported (just printed)

SAP_CHAR

SAPChar -> Not supported (just printed)

TEMPLATE_STRING

Template string -> Not supported (just printed)

TAB

&nbsp;&nbsp;&nbsp; 

Tab (rendered as 4 spaces)

SYMBOL_BEGIN

&amp;

Symbol Begin & End

SYMBOL_BEGIN

Symbol

CTAG_BEGIN

Comment

PARAGRAPH_BEGIN

<p>

Generic paragraph

LTAG_BEGIN

Link (<a>)

URL_BEGIN

URL (<a>)

PREFIX_BEGIN

Prefix -> Not supported (just printed)

SUFFIX_BEGIN

Suffix -> Not supported (just printed)

COMMAND_BEGIN

Command -> Not supported (ignored)

TEXT_END

Text end -> Not supported (ignored)

COMMAND

Command -> Not supported (just printed)

PARAGRAPH_BEGIN

U1

<h1>

U1 Header

Validation of Formatted Text

You can call method VALIDATE for a formatted text object to check the object's validity. If there is an error, the exception CX_WD_GENERAL is triggered. The error text is contained in the MSG attribute of the exception.

Example

  try.       formatted_text->validate( ).     catch cx_wd_general into ex.       … ex->msg …
   endtry.
Dynamic Creation of Formatted Text

An interface is provided for creating formatted texts dynamically.

Note

FORMATTED_TEXT parameters require an object of type CL_WD_FORMATTED_TEXT.

TEXT parameters require that the text is provided with a toggle character for switching the code ("escaped text").

XML_TEXT parameters require a valid formatted text (with markups, and so on).

Example

  data f1 type ref to cl_wd_formatted_text.   data f2 type ref to cl_wd_formatted_text.   data f3 type ref to cl_wd_formatted_text.   data f  type ref to cl_wd_formatted_text.   f1 = cl_wd_formatted_text=>make_text(     inner_text = 'available' "#EC NOTEXT     tag        = cl_wd_formatted_text=>e_tag-em   ).   f2 = cl_wd_formatted_text=>make_sap_field( name = 'CONNID' ).   f2 = cl_wd_formatted_text=>make_text(     inner_formatted_text = f2     tag = cl_wd_formatted_text=>e_tag-code ).   f3 = cl_wd_formatted_text=>make_sap_field( name = 'CARRID' ).   f = cl_wd_formatted_text=>make_text( inner_text = 'Places &STATE& for flight &CONNID& of line &CARRID&' ). "#EC NOTEXT   f->replace_placeholder( name = 'STATE'  formatted_text = f1 ).   f->replace_placeholder( name = 'CONNID' formatted_text = f2 ).   f->replace_placeholder( name = 'CARRID' formatted_text = f3 ).   wd_context->set_attribute( name = 'TEXT' value = f->m_xml_text ).

Result

Places <em>available</em> for flight <code><sap:field name="CONNID"/></code> of line <sap:field name="CARRID"/>
Note

Note that in productive applications the texts, "available" and "places" must come from a source that can be converted. In the example above these texts are hard coded only so that they can be read more easily.

Use method REPLACE_PLACEHOLDER to replace placeholders in formatted texts with a text or a formatted text. This method helps to embed formatted text in "normal" text. Moreover, there is no risk of distorting the XML through the conversion.

Example

You can find examples in the system in the Web Dynpro application demo_uiel_formatted_text_edit. You can switch between the FormattedTextView and the FormattedTextEdit using a button.