+ Start a Discussion
Jerry ClifftJerry Clifft 

No data to display in VF

Ok, so trying to print a table from one (1) list, normally this in a single column, but I am trying to get it in three (3) columns that are (3) three rows deep. I am not getting an error, but I am not getting any values either.

 

VF

<apex:page controller="MyController" >
  <head>
  </head>
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!MyWrappers}" var="wrap">
   <apex:column headerValue="Col 1">
      <apex:outputField value="{!wrap.myAcc1.Name}"/>
   </apex:column>
   <apex:column headerValue="Col 2">
      <apex:outputField value="{!wrap.myAcc2.Name}"/>
   </apex:column>
   <apex:column headerValue="Col 3">
      <apex:outputField value="{!wrap.myAcc3.Name}"/>
   </apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

 

Controller

public class MyController {
   public List<MyWrapper> myWrappers{get; set;}

   public class MyWrapper
   {
      public Account myAcc1 {get; set;}
      public Account myAcc2 {get; set;}
      public Account myAcc3 {get; set;}

      public Boolean checkbox1 {get; set;}
      public Boolean checkbox2 {get; set;}
      public Boolean checkbox3 {get; set;}
   }

   public MyController()
   {
      myWrappers=new List<MyWrapper>();
      Integer idx=0;
      MyWrapper wrap;
      
      for (Account acc: [select id, Name from Account limit 12])
      {
         if (0==Math.mod(idx, 3))
         {
            wrap=new MyWrapper();
            wrap.myAcc1=acc;
         
         if (1==Math.mod(idx, 3))

         wrap.myAcc2=acc;

         else if (2==Math.mod(idx, 3))

            wrap.myAcc3=acc;
        }
      }
   }
 
}

Rahul SharmaRahul Sharma

Hi 

Also there seems to be problem in logic, I think you need to show the records in alternate columns, if it is then update your controller as below:

public class MyController {
	public List<MyWrapper> myWrappers{get; set;}

	public class MyWrapper
	{
		public Account myAcc1 {get; set;}
		public Account myAcc2 {get; set;}
		public Account myAcc3 {get; set;}

		public Boolean checkbox1 {get; set;}
		public Boolean checkbox2 {get; set;}
		public Boolean checkbox3 {get; set;}
	}

	public MyController()
	{
	myWrappers=new List<MyWrapper>();
	Integer idx=0;
	MyWrapper wrap;

		for (Account acc: [select id, Name from Account limit 12])
		{
			wrap=new MyWrapper();
			if (0==Math.mod(idx, 3))
			{
				wrap.myAcc1=acc;
			}
			else if (1==Math.mod(idx, 3))
			{
				wrap.myAcc2=acc;
			}
			else if (2==Math.mod(idx, 3))
			{
				wrap.myAcc3=acc;
			}
			idx++;
			myWrappers.add(wrap);
		}
	}

}

 Kindly test this code and let me know what didn't worked.