+ Start a Discussion
fehays-wbsnfehays-wbsn 

pageBlock facet header cannot contain apex component

Hi,

 

I'm trying to put an apex:selectList inside the header facet of a pageBlock and it doesn't appear to work.  Is this something I should be able to do?


Thanks.

Best Answer chosen by Admin (Salesforce Developers) 
prageethprageeth

Hello fehays-wbsn;

I think this can be a bug of salesforce when rendering apex:facet component. You may overcome this problem by placing the <table> inside the <apex:form> as below.

 

 

<apex:page Controller="MyController">
  <apex:pageblock>
    <apex:facet name="header">
      <apex:form>
        <table>
          <tr>
            <td>
              <apex:selectList value="{!Number}" size="1">
                <apex:selectOptions value="{!Numbers}"/>
              </apex:selectList>
            </td>
          </tr>
        </table>
      </apex:form>
    </apex:facet>
  </apex:pageblock>
</apex:page>

 

 

 

All Answers

prageethprageeth

Hello fehays-wbsn;

You can insert a selectList inside the header facet as below.

 

Page:

 

<apex:page Controller="MyController">
<apex:pageblock>
    <apex:facet name="header">
        <apex:form>
            <apex:selectList value="{!Number}" size="1">
                <apex:selectOptions value="{!Numbers}"/>
            </apex:selectList>
        </apex:form>
    </apex:facet>
</apex:pageblock>
</apex:page>

 Controller:(Example)

public class MyController {
    String strNumber = '';

    public List<SelectOption> getNumbers() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('One','1'));
        options.add(new SelectOption('Two','2'));
        options.add(new SelectOption('Three','3'));
        return options;
    }
        
    public String getNumber() {
        return strNumber;
    }
        
    public void setNumber(String num) {
        this.strNumber = num;
    }
}

 


 

 

 

 

 

fehays-wbsnfehays-wbsn

I see that does work.  It turns out, that my problem has something to do with the selectList being inside of a table.

 

My page looks like this:

 

<apex:page Controller="MyController">
<apex:pageblock>
<apex:facet name="header">

<table><tr><td>
        <apex:form>
            <apex:selectList value="{!Number}" size="1">
                <apex:selectOptions value="{!Numbers}"/>
            </apex:selectList>
        </apex:form>

</td></tr></table>
    </apex:facet>


</apex:pageblock>
</apex:page>

 

This causes the page to break and the select is not rendered.  Any idea why that wouldn't work?

prageethprageeth

Hello fehays-wbsn;

I think this can be a bug of salesforce when rendering apex:facet component. You may overcome this problem by placing the <table> inside the <apex:form> as below.

 

 

<apex:page Controller="MyController">
  <apex:pageblock>
    <apex:facet name="header">
      <apex:form>
        <table>
          <tr>
            <td>
              <apex:selectList value="{!Number}" size="1">
                <apex:selectOptions value="{!Numbers}"/>
              </apex:selectList>
            </td>
          </tr>
        </table>
      </apex:form>
    </apex:facet>
  </apex:pageblock>
</apex:page>

 

 

 

This was selected as the best answer
fehays-wbsnfehays-wbsn

Yep that worked.  Thank you!