I'm new to visualforce programming and I would appreciate your advice on this matter.

Basically, I'm trying to create a dynamic VF page that will change its content when a button is clicked. My VF page gets a list of custom objects called project__c and I would like to let the user dynamically choose which list of projects he wants to view.

So I though of creating a button that will change the following line of code:

<apex:pageBlockTable value="{!projectList1}" var="item">


<apex:pageBlockTable value="{!projectList2}" var="item">

Can anyone explain on the overall process and how could this be achieved?


You've barely included any code, but the easiest way to do this is to have a "currentList" instead:

<apex:pageBlockTable value="{!currentList}" var="item">

And in your controller:

public void switchToList1() {
    currentList = projectList1;
public void switchToList2() {
    currentList = projectList2;

A reference to another list costs virtually no memory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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