Newer Version Available
apex:outputText
Displays text on a Visualforce page. You can customize the appearance of <apex:outputText> using CSS styles, in which case the generated text is wrapped in an HTML <span> tag. You can also escape the rendered text if it contains sensitive HTML and XML characters.
Use this component to get user input for a controller method that does not correspond to a field on an sObject. Only <apex:inputfield> and apex:outfield can be used with sObject fields.
Use with nested param tags to format the text values, where {n} corresponds to the n-th nested param tag. The value attribute supports the same syntax as the MessageFormat class in Java.
Warning: Encrypted custom fields that are embedded in the <apex:outputText> component display in clear text. The <apex:outputText> component doesn't respect the View Encrypted Data permission for users. To prevent showing sensitive information to unauthorized users, use the <apex:outputField> tag instead.
This component supports HTML pass-through attributes using the "html-" prefix. Pass-through attributes are attached to the generated container <span> tag.
Basic formatting example
1<apex:page>
2 <apex:outputText style="font-style:italic" value="This is {0} text with {1}.">
3 <apex:param value="my"/>
4 <apex:param value="arguments"/>
5 </apex:outputText>
6</apex:page>The example above renders the following HTML:
1<span id="theText" style="font-style:italic">This is my text with arguments.</span>Date formatting example
1<apex:page>
2 <apex:outputText value="The unformatted time right now is: {! NOW() }" />
3 <br/>
4 <apex:outputText value="The formatted time right now is:
5 {0,date,yyyy.MM.dd G 'at' HH:mm:ss z}">
6 <apex:param value="{! NOW() }" />
7 </apex:outputText>
8</apex:page>The example above renders the following HTML:
1The unformatted time right now is: 11/20/2004 3:49 PM
2<br />
3The formatted time right now is: 2004.11.20 AD at 23:49:02 GMTCurrency formatting example
1<!-- For this example to render properly, you must associate the Visualforce page
2with a valid account record in the URL.
3For example, if 001D000000IeChM is the account ID, the resulting URL should be:
4https://Salesforce_instance/apex/myPage?id=001D000000IeChM
5See the Visualforce Developer's Guide Quick Start Tutorial for more information. -->
6
7<apex:page standardController="Account">
8It is worth:
9<apex:outputText value="{0, number, 000,000.00}">
10 <apex:param value="{!Account.AnnualRevenue}" />
11 </apex:outputText>
12</apex:page>The example above renders the following HTML:
1It is worth: 500,000,000.00Attributes
| Attribute Name | Attribute Type | Description | Required? | API Version | Access |
|---|---|---|---|---|---|
| dir | String | The direction in which the generated HTML component is read. Possible values include "RTL" (right to left) or "LTR" (left to right). | 10.0 | global | |
| escape | Boolean | A Boolean value that specifies whether sensitive HTML and XML characters should be escaped in the HTML output generated by this component. If you don’t specify escape="false", the character escape sequence displays as written. Be aware that setting this value to "false" may be a security risk because it allows arbitrary content, including JavaScript, that could be used in a malicious manner. | 10.0 | global | |
| id | String | An identifier that allows the outputText component to be referenced by other components in the page. | 10.0 | global | |
| label | String | A text value that allows to display a label next to the output text | 23.0 | ||
| lang | String | The base language for the generated HTML output, for example, "en" or "en-US". For more information on this attribute, see the W3C specifications. | 10.0 | global | |
| rendered | Boolean | A Boolean value that specifies whether the component is rendered on the page. If not specified, this value defaults to true. | 10.0 | global | |
| style | String | The style used to display the outputText component, used primarily for adding inline CSS styles. | 10.0 | global | |
| styleClass | String | The style class used to display the outputText component, used primarily to designate which CSS styles are applied when using an external CSS stylesheet. | 10.0 | global | |
| title | String | The text to display as a tooltip when the user's mouse pointer hovers over this component. | 10.0 | global | |
| value | Object | The text displayed when this component is rendered. This value supports the same syntax as the MessageFormat class in Java. | 10.0 | global |