<apex:page controller="Apexclassforaccandcheck">
        <apex:dataTable value="{!acw}" var="aa">
            <apex:column><apex:inputCheckbox rendered="true" value="{!aa.checked}">
                <apex:outputText value="{!aa.nam}"/></apex:inputCheckbox>


public class Apexclassforaccandcheck{
Public List<Account> acc{set;get;}
Public List<accwrap> acw{set;get;}
Public Apexclassforaccandcheck() {
    acc=[select id,name,phone from account];
    acw=new List<accwrap>();
    for(Account a:acc){
        acw.add(new accwrap(a.name,a.id));
Public class accwrap{
    Public String nam{set;get;}
    Public String ids{set;get;}
    Public Boolean checked{set;get;}
    Public accwrap(String n,String i){

whine i click on text checkbox should enable

whine i click on text checkbox should enable

1 Answer 1


You can use html label and for attribute as below.

<label for="{!$Component['cbox']}">{!aa.nam}</label>
<apex:inputCheckbox id="cbox" rendered="true" value="{!aa.checked}">

Label for and checkbox id should match. Since visualforce changes Id attribute at runtime we use $Component to get that id.

  • visualforce page throwing error "Literal value is required for attribute id in <apex:inputCheckbox> in Apexclassforaccandcheckvf " error in <apex:inputCheckbox id="{!aa.ids}" rendered="true" value="{!aa.checked}"/>`
    – SFDC V
    Commented Jul 27, 2019 at 7:09
  • Changed answer. This actually works but have to check for repeat Commented Jul 27, 2019 at 7:22
  • thank you some mutch it working perfectly
    – SFDC V
    Commented Jul 27, 2019 at 7:38
  • Pls mark as solved if solved Commented Jul 27, 2019 at 8:10

You must log in to answer this question.

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