FormattedTextView
Use
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.
Implementation Details
| Runtime Class | CL_WD_FORMATTED_TEXT_VIEW |
Properties in View Designer
For more information, see FormattedTextView Properties.
| 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 |
| height | STRING | Yes | |
| styleClassName | STRING | 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 |
|---|---|---|
|
0..n |
Events in View Designer
| Name |
|---|
Dynamic Programming
For dynamic programming, the same properties, events, and aggregations as in the View Designer are available. But note that the spelling format and use of upper/lower case is different.
Dynamic Programming of Properties
| View Designer Name | Runtime Name | Type |
|---|---|---|
|
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 |
|
|
CONTEXT_MENU_ID |
WDY_MD_UI_ELEMENT_REFERENCE |
|
|
DATA_SOURCE |
OBJECT |
|
|
ENABLED |
WDY_BOOLEAN |
|
|
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 |
|
| styleClassName | STYLE_CLASS_NAME | STRING |
|
TEXT |
WDY_MD_TRANSLATABLE_TEXT |
|
|
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 |
WDY_MD_TRANSLATABLE_TEXT |
|
|
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 |
|---|---|
|
ON_ACTION |
Dynamic Programming of Aggregations
| View Designer Name | Runtime Name | Cardinality |
|---|---|---|
|
FIELDS |
0..n |
Conversion of SAPscript Texts into Formatted Texts
You can convert SAPscript texts into formatted texts by calling static method CL_WD_FORMATTED_TEXT=> CREATE_FROM_SAPSCRIPT.
Example
|
data
formatted_text cl_wd_formatted_text. formatted_text = cl_wd_formatted_text=> create_from_sapscript( sapscript_head = sapscript_head sapscript_lines = sapscript_lines ). wd_context->set_attribute( name = my_formatted_text_attrtyperefto " convert from context " set it into the context 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 |
|
Tab (rendered as 4 spaces) |
|
|
SYMBOL_BEGIN |
& |
Symbol Begin & End |
|
|
SYMBOL_BEGIN |
Icon |
||
|
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
. formatted_text->validate( ). cx_wd_general ex. … ex->msg …trycatchinto endtry. |
Dynamic Creation of Formatted Text
An interface is provided for creating formatted texts dynamically.
XML_TEXT parameters require a valid formatted text (with markups, and so on).
Example
f1 cl_wd_formatted_text. f2 cl_wd_formatted_text. f3 cl_wd_formatted_text. f cl_wd_formatted_text. f1 = cl_wd_formatted_text=>make_text( inner_text = tag = cl_wd_formatted_text=>e_tag-em ). f2 = cl_wd_formatted_text=>make_sap_field( name = ). f2 = cl_wd_formatted_text=>make_text( inner_formatted_text = f2 tag = cl_wd_formatted_text=>e_tag- ). f3 = cl_wd_formatted_text=>make_sap_field( name = ). f = cl_wd_formatted_text=>make_text( inner_text = ). f->replace_placeholder( name = formatted_text = f1 ). f->replace_placeholder( name = formatted_text = f2 ). f->replace_placeholder( name = formatted_text = f3 ). wd_context->set_attribute( name = = f->m_xml_text ).datatypereftodatatypereftodatatypereftodatatyperefto'available'"#EC NOTEXT'CONNID'code'CARRID''Places &STATE& for flight &CONNID& of line &CARRID&'"#EC NOTEXT'STATE''CONNID''CARRID''TEXT'value |
Result
|
Places <em>available</em> for flight <code><sap:field name="CONNID"/></code> of line <sap:field name="CARRID"/> |
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.