1

The docs for <apex:column /> states that the default behavior of the headerValue displays the field label when using an <apex:inputField/> or an <apex:outputField/> tag.

Note also that specifying a value for this attribute overrides the default header label that appears if you use an inputField or outputField in the column body.

However the header value is blank when I do so.

<apex:pageBlockTable value="{!productsToInsert}" var="p" id="orderItemTable" >
    <apex:column>
        <apex:inputField value="{!p.Name}" />
    </apex:column>
    <apex:column>
        <apex:inputField value="{!p.Family}">
    </apex:inputField>
    </apex:column>
    <apex:column>
        <apex:inputField value="{!p.isActive}" />
    </apex:column>
    <apex:column >
        <apex:inputField value="{!p.Initial_Inventory__c}" />
    </apex:column>
</apex:pageBlockTable>

How is this supposed to work with nesting inputFields inside the Apex Column body?

  • Yeah, the docs have the same text for the headerValue attribute and the facet attribute. If it's not displaying a label it seems like it may be a bug. Does it work when you use outputField or when you use the value attribute? – IllusiveBrian Dec 26 '17 at 2:19
  • @IllusiveBrian when I use the value attribute on the column it shows a label, but for this case I want input from the User. Specifying the value attribute only displays the data. I think this is a bug too, or just bad documentation. – Programmatic Dec 26 '17 at 15:35
1

I think you misread the documentation.

From apex:column docs

Note that if you specify an sObject field as the value attribute for an , the associated label for that field is used as the column header by default.

It's clear that we don't need to supply headerValue when we set the value attribute of apex:column. However, when we add tags like apex:inputField or apex:outputField, we need to supply headerValue which can be done as follows without actually hardcoding the label text.

<apex:pageBlockTable value="{!productsToInsert}" var="p" id="orderItemTable" >
    <apex:column headerValue="{!$ObjectType.Product2.Fields.Name.Label}">
        <apex:inputField value="{!p.Name}" />
    </apex:column>
    <apex:column headerValue="{!$ObjectType.Product2.Fields.Family.Label}">
        <apex:inputField value="{!p.Family}" />
    </apex:column>
    <apex:column headerValue="{!$ObjectType.Product2.Fields.IsActive.Label}">
        <apex:inputField value="{!p.IsActive}" />
    </apex:column>
</apex:pageBlockTable>

We can use $ObjectType global merge field to access object/field schema in Visualforce.

Hope this helps.

  • I did read that section, but on the field description for headerValue it states "The text that should be displayed in the column header. If you specify a value for this attribute, you cannot use the column's header facet. Note also that specifying a value for this attribute overrides the default header label that appears if you use an inputField or outputField in the column body." In the column body it should use the inputField's field label to generate the header value. But this works, thank you @jagmohan – Programmatic Dec 24 '17 at 20:46
  • I edited the question that highlights the specific note that says it should use the inputField's label. – Programmatic Dec 24 '17 at 20:48
  • @Programatic Please accept the answer if that's what helped you work around the issue. Thanks. – jagmohan Dec 26 '17 at 1:25
  • I will keep this open for now. Your answer is a work around but does not answer the question. – Programmatic Dec 26 '17 at 2:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.