I have just started making this , its a small e commerce website, its just the basic at the moment i am just trying to learn.

I have the products list page below which is to display all the products available for sale. And then there is the controller for it

VF Page

<apex:page controller="productslistpage" showHeader="false">

  <Apex:form >

  <apex:outputText value="{!usermode}  {!Name}" style="float:right;font-weight:bold;color:black;font-size:16px;text-align:left;" />

        <br/><p style="font-size:19px;font-weight:bold;"> Products available today </p><br/>

            <apex:CommandLink action="{!prod1button}" ><br/>    
  <apex:image url="{!$Resource.Testprod1}" width="100" height="180"/><br/>
            <h3>Logo Shirt (Gray)</h3> 



public Class productslistpage{

    public list<inventory__c> prodlist{get; set;} 
    public string PID{get; set;}
    public string name{get; set;}
    public string usermode{get; set;}

public productslistpage(){

    this.name = ApexPages.currentPage().getParameters().get('Name');
    this.usermode = ApexPages.currentPage().getParameters().get('usermode');
    prodlist = [Select ButtonName__c,Name, Price__c, Stocks__c,productid__c from Inventory__c];

      PageReference pg = new PageReference('/apex/testprodpage');
public pagereference prod1button(){

      PID = '10004';    

      pg.getParameters().put('PID', PID);

      return pg; 

in both , I have a prodbutton method for product 1[Product 1 as in the VF page] in controller .

Now the mess is I don't want to make button method for each product as well as each hard coded code for the product in VF page.

1 Answer 1


I would expect to see an apex:repeat over the prodlist collection in the Visualforce.

You can invoke the same controller method for all the prodlist items by supplying an apex:param value. It can be tricky to get right but see e.g. apex:Param not working with CommandButton component for a detailed explanation in the accepted answer.

(PS I didn't down-vote your question; unfortunately someone else did without leaving an explanation.)

  • Thanks, let me just get through that. also thanks for not down voting, I just don't get it why people just down vote and leave without stating a reason, I make sure if all details are given or not before posting, it sucks.
    – Niknit
    Aug 9, 2017 at 4:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .