4

I have a Visualforce custom object EDIT page with a controller extension that's used by multiple profiles. I've created a two-column layout by embedding the input fields in an <apex:pageBlockSection columns="2">. I've tried to take advantage of the <apex:inputField> 's obedience to field level security (FLS) settings so some of my fields will display with one profile but not another.

The problem I'm having is with the column wrapping feature of the pageBlockSection. If the field level security determines that a field cannot be displayed then it just displays the next field along. I would prefer to use the next field (down) from the right column rather than just the next field along (i.e. left). How can I prevent this default wrapping?

Code below - I have appended a COL_A / COL_B suffix to the ID just to indicate where I want the field to appear. If my FLS says I should not see "List_Price_Unit__c", then the next field just wraps into that position. Really I would prefer the columns to be fixed so the Requested_Net_Price_Unit__c label is pulled up one instead.

<apex:pageBlockSection title="Product Information" columns="2" id="speditsect">

<apex:inputField value="{!MyProduct__c.ProductName__c}" id="product_COL_A" required="true" taborderhint="1" />

<apex:inputField value="{!MyProduct__c.List_Price_Unit__c}" id="listprice_COL_B" required="true" taborderhint="2"  />

<apex:inputField value="{!MyProduct__c.Enclosure__c}" id="enclosure_COL_A" required="true" />

<apex:outputText value="" label="{!$ObjectType.MyProduct__c.fields.Requested_Net_Price_Unit__c.Label}" id="newnetnetprice_COL_B" />

<apex:inputField value="{!MyProduct__c.Content_Price_Unit__c}" id="contentprice_COL_A" required="true"  taborderhint="6"  />

1 Answer 1

4

You can nest <apex:pageblocksection> elements with a columns="1" attribute to achieve this.

<apex:pageBlockSection title="Product Information" columns="2" id="speditsect">

    <!-- First Column Section -->
    <apex:pageblocksection columns="1">
        <apex:inputField value="{!MyProduct__c.ProductName__c}" id="product_COL_A" required="true" taborderhint="1" />
        <apex:inputField value="{!MyProduct__c.Enclosure__c}" id="enclosure_COL_A" required="true" />
        <apex:inputField value="{!MyProduct__c.Content_Price_Unit__c}" id="contentprice_COL_A" required="true"  taborderhint="6"  />
    </apex:pageblocksection>

    <!-- Second Column Section -->
    <apex:pageblocksection columns="1">
        <apex:inputField value="{!MyProduct__c.List_Price_Unit__c}" id="listprice_COL_B" required="true" taborderhint="2"  />
        <apex:outputText value="" label="{!$ObjectType.MyProduct__c.fields.Requested_Net_Price_Unit__c.Label}" id="newnetnetprice_COL_B" />
    </apex:pageblocksection>

</apex:pageblocksection>
2
  • Yes! I hadn't thought about doing that - good job, thanks!
    – collymitch
    Commented Jun 26, 2013 at 7:11
  • That's great, but it changes the formatting of this pageblocksection, aligning the fields differently than in pageblocksections without nesting. Commented Sep 7, 2016 at 15:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .