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.


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) { 

//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:pageBlockSection columns="2">
    <apex:pageblockTable value="{!wrapList}" var="w">
      <apex:column >
        <apex:facet name="Header">
          <apex:inputcheckbox />
        <apex:inputCheckbox value="{!w.isSelected}"/> 
      <apex:column value="{!w.acc.Name}"/>
    <apex:pageBlockTable value="{!accList}" var="a" id="tableId">
      <apex:column value="{!a.Name}"/>
      <apex:column value="{!a.Phone}"/>

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.