2

I have a component which contains a pageBlockTable. I am trying to add checkboxes to the pageBlockTable.

The component is as follows: MyComponent

<apex:component controller="ComponentController">
   <apex:pageBlock>
      <apex:pageBlockTable value="{!wrapperClassList}" var="wrapperObject">
         <apex:column headerValue="Select">
            <apex:inputCheckbox value="{!wrapperObject.selected}"/>
         </apex:column>
         .
         .
         other columns
      </apex:pageBlockTable>
   </apex:pageBlock>
</apex:component>

I have created a wrapper class to handle the usage of checkbox in the corresponding controller

public with sharing class ComponentController { 
   public List<SObjectWrapperClass> wrapperClassList {get; set;}

   public ComponentController() {
      wrapperClassList = new List<SObjectWrapperClass>();
   }
   .
   // other code 
   .
   //happens couple of times in the code
   wrapperClassList.add(new SObjectWrapperClass(sobj, false); 
   .
   //wrapper class
   public class SObjectWrapperClass {
      public Sobject sobj {get; set;}
      public Boolean selected {get; set;}

      public sObjectWrapperClass(Sobject sobj, Boolean isSelected) {
        this.sobj = sobj;
        this.selected = isSelected;
      }
   }

}

The problem is when i refresh the page where this component is being used, it gives me the following error:

Content cannot be displayed: c:MyComponent must occur between tags

Now when I comment out the column holding the checkbox, everything works fine and the table is displayed. I dont know what "tags" I am missing. I am pretty sure this issue is due to the checkbox since if I just comment the checkbox line like,

<apex:column headerValue="Select">
   <!--<apex:inputCheckbox value="{!wrapperObject.selected}"/>-->
</apex:column>

it just shows a empty Select column.

Am I doing it wrong or is there some other issue. Help is appreciated. Thanks.

0

1 Answer 1

1

<apex:inputCheckbox> should be wrapped by <apex:form>

     <apex:form>
     <apex:pageBlockTable value="{!wrapperClassList}" var="wrapperObject">
             <apex:column headerValue="Select">
                <apex:inputCheckbox value="{!wrapperObject.selected}"/>
             </apex:column>
             .
             .
             other columns

     </apex:pageBlockTable>
   </apex:form>
3
  • Its not working, gives me this error: Error: <apex:column> must be the direct child of either <apex:dataTable> or <apex:pageBlockTable> Jun 18, 2013 at 14:22
  • could you try moving the form tag before pageBlockTable ? Jun 18, 2013 at 14:25
  • Ooops, my bad, I was putting the form inside the table. It worked now. Thanks for the help. Jun 18, 2013 at 14:27

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.