+ Start a Discussion
StephenBStephenB 

Label for pageBlockTable - seems simple?

Hi all, kind of odd - I have a pageBlockTable with some columns. If I use the standard column definition:

 

<apex:column value="{!p.End_Date__c}"/>

 

Then all is well and my header has the End Date label, etc etc. All good.

 

Now I want to use an explicit field definition in the column - ie

 

<apex:column headerValue="Start Date">
                        <apex:outputField value="{!p.Start_Date__c}">
                            <apex:inlineEditSupport disabled="true" />
                        </apex:outputField>
                    </apex:column>

 

The issue is, I have to hard code the label for the col in the headerValue. I should be able to use a variable for this, surely? I've tried using {!p.Start_Date__c} in the headerValue also but doesn't work, I need a 'label for' type definition for the field, so I can get the label for that field without hard coding. Thought something like $componentLabel but can't get this to work either.

 

Seems so simple, but I'm stumped! Anyone got an idea??

 

Thanks, S

 

Best Answer chosen by Admin (Salesforce Developers) 
Rahul SharmaRahul Sharma

Its possible with accessing $ObjectType global variable in visualforce page.

 

For dynamically accessing Account Name's Label you need to use example like following inside your value :

 

{!$ObjectType.Account.Fields.Name.Label}

 With above you can directly retrieve the Label of field from object and best part is it changes with Field's Label change dynamically. :)

All Answers

Rahul SharmaRahul Sharma

Its possible with accessing $ObjectType global variable in visualforce page.

 

For dynamically accessing Account Name's Label you need to use example like following inside your value :

 

{!$ObjectType.Account.Fields.Name.Label}

 With above you can directly retrieve the Label of field from object and best part is it changes with Field's Label change dynamically. :)

This was selected as the best answer
StephenBStephenB

Thanks Rahul! Exactly what I was looking for.

 

Thanks also Chamil, but was trying to do this without needing to resort to a describe in Apex, since there is a limit to the number of those.

 

Thanks,

Stephen