1

I'm trying to display the selected checkbox row's values in vf page using wrapper class concept. But instead of the selected records, it is displaying all records values. here is my code.

Controller:

public class WrapperCls {

public List<myWrapper> wrapList {get;set;}
public List<Account> accList {get;set;}

public WrapperCls () {
wrapList = new List<myWrapper>();
for(Account a : [SELECT Name,Phone FROM Account])
  wrapList.add(new myWrapper(a));
}

public void SelectedBox() {
accList = new List<Account>();
for(myWrapper myWrap : wrapList) {    
 if(myWrap.isSelected = true) { 
   accList.add(myWrap.acc);
 }
}
}

//Wrapper Class formation
public class myWrapper {
public Account acc{get;set;}
public Boolean isSelected{get;set;}

public  myWrapper(Account a) {
acc = a;
isSelected = false;
}  

}
}

VF Page:

<apex:page controller="WrapperCls">
<apex:form >
<apex:pageBlock >
  <apex:pageBlockButtons >
    <apex:commandButton value="ShowDetails" action="{!SelectedBox}" rerender="tableId"/>
  </apex:pageBlockButtons>
  <apex:pageBlockSection columns="2">
    <apex:pageblockTable value="{!wrapList}" var="w">
      <apex:column >
        <apex:facet name="Header">
          <apex:inputcheckbox />
        </apex:facet>
        <apex:inputCheckbox value="{!w.isSelected}"/> 
      </apex:column>  
      <apex:column value="{!w.acc.Name}"/>
    </apex:pageblockTable>
    <apex:pageBlockTable value="{!accList}" var="a" id="tableId">
      <apex:column value="{!a.Name}"/>
      <apex:column value="{!a.Phone}"/>
    </apex:pageBlockTable>
  </apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
0
0

I found what the issues is . In if condition it should be '==' not '='.

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