Saturday, December 10, 2016

Visualforce - Beyond Basics Series 11 - Format using param tag

Why formatting output ?

Most of the time, you don't want to display the date, string, number in raw format to the User. It has be formatting to different standards & user conventions before displaying to user.

How to Formatting Ouput ?

When you want to format a Date, String,  Number, i have seen developers formatting them in Apex Class & showing them in Visualforce. That is not required, we can use OutputText with param tag to format the output.


What types of data can be formatted ?

you can format String, Date & Number types using OutputText tag


Where is the Code ?

<apex:page standardController="Opportunity">
<!-- Format - String -->
<apex:sectionHeader title="Formatting - String"/>
<apex:outputText value="The Opportunity Name is {0}">
<apex:param value="{!Opportunity.Name}"/>
</apex:outputText>
<!-- Format - Number -->
<apex:sectionHeader title="Formatting - Number"/>
<apex:outputText value="{0, number, 00,000.00}">
<apex:param value="{!Opportunity.Amount}"/>
</apex:outputText>
<!-- Format - Date -->
<apex:sectionHeader title="Formatting - Date"/>
<apex:outputText value="{0, date, YYYY/MM/DD}">
<apex:param value="{!Opportunity.CloseDate}"/>
</apex:outputText>
</apex:page>
view raw gistfile1.txt hosted with ❤ by GitHub



1 comment:

Thanks for reading my blog !