Search Here

apex: outputText Component in Visualforce Page

 The <apex: outputText> is another important component for displaying text on a Visualforce page. The text generated from the <apex: outputText> is wrapped in an HTML <span> tag. However, we can customize the appearance of the <apex: outputText> by using the CSS.


The <apex: outputText> component is used to get the input from the user for the controller method that doesn't correspond to a Salesforce field.


This component supports the HTML pass-through attributes by simply adding "html-" prefix.


The <apex: outputText> component has the following attributes on the Visualforce page:


1. dir


The dir is a string-type attribute used to specify the direction in which the generated HTML component should be read. LTR and RTL are the two possible values for this attribute.


Syntax:


<apex: outputText dir="RTL"></apex:outputText>   

2. escape


The escape is a Boolean-type attribute used for specifying whether the sensitive HTML and XML characters should be escaped in the generated HTML output by this component.


Syntax:


<apex: outputText escape="true"></apex:outputText>   

3. label


The label is a string-type string used to specify the text that needs to be displayed as a label next to the output text.


Syntax:


<apex: outputText label="Output Text Label"></apex:outputText>   

4. id


The id is a string-type attribute that allows this component to be referenced by other components on the page.


Syntax:


<apex: outputText id="textId"></apex:outputText>   

5. lang

AD


The lang is a string-type attribute that specifies the base language used for the generated HTML output. The values can be "en" or "en-US" etc.


Syntax:


<apex: outputLabel language="en"></apex: outputLabel>  

6. rendered


The rendered is a Boolean-type attribute used to specify whether this component is rendered on the page. By default, its value is set to true.


Syntax:

AD


<apex: outputText rendered="true"></apex:outputText>   

7. style


The style is a string-type attribute used to specify the CSS that needs to be applied to it. Inline CSS is used as a value for this attribute.


Syntax:


<apex: outputText style="background:red;"></apex:outputText>   

8. styleClass


The styleClass is a string-type attribute used to specify the external CSS stylesheet that needs to be applied to it to display the output text.


Syntax:


<apex: outputText styleClass="ClassName"></apex:outputText>   

9. title


The title is a string-type attribute used to specify the text that needs to be displayed as a tooltip when the mouse hovers over this component


Syntax:


<apex: outputText title="button title"></apex:outputText>   

10. value


The value is an Object-type attribute used to specify the text displayed when the component is rendered on the page.


Syntax:


<apex: outputText value="Text Value"></apex:outputText>   

Let's take an example to understand how we can use the <apex: outputText> component inside the VF page:

<apex:page standardController="Account">

    <apex:pageBlock title="Account Information">

        <apex:pageBlockSection>

            <apex:outputText value="Account Name: {!Account.Name}"/>

            <br/>

            <apex:outputText value="Industry: {!Account.Industry}"/>

            <br/>

            <apex:outputText value="Annual Revenue: ${!Account.AnnualRevenue}"/>

        </apex:pageBlockSection>

    </apex:pageBlock>

</apex:page>


Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.