[SalesForce] PageBlockTable with Lists of

I have a couple of lists in my controller. And i have a table. The first element in both lists correspond to each other and i want them to show up side by side on the pageblocktable. The problem is there is no iterator for them and they just print the complete list in every column for each list.

<apex:column value="{!string}" />
<apex:column value="{!date}" />

I tried making it so that is there anyway to use an iterator in the pageblocktable to achieve what i want? or will i have to use something else.

<apex:column value="{!string[i]}" />
<apex:column value="{!date[i]}" />

Best Answer

Time for the infamous 'wrapper' inner class!

Assuming there is a 1:1 correspondence between the string list and the integer list ....

Your controller (assumes the pageblocktable is displayed after the string and integer lists are instantiated; if not, the getter for myWrapperList needs adjusting)

private List<String> sList;
private List<Integer> iList;

public List<MyWrapper>  myWrapperList {
  get {
       if (myWrapperList = null) {
          myWrapperList = new List<MyWrapper> ();
          for (integer i = 0; i < sList.size(); i++)
              myWrapperList.add(new MyWrapper(sList[i],iList[i]));
      }
      return myWrapperList;
  }
 private set;
}

public class MyWrapper {
   public String str {get; set;}
   public Integer int {get; set;}
   public MyWrapper(String s, Integer i) {
      this.str = s;
      this.int = i;
}

The VF pageBlocktable thus becomes

<apex:pageblockTable value="{!myWrapperList}" var="mw">
  <apex:column value="{!mw.str}"/>
  <apex:column value="{!mw.int}"/>
</apex:pageBlockTable>