You need to sign in to do that
Don't have an account?

adding multiple row in vf page dynamically
I have a vf page where i want to add rows every time "add row" button is clicked..but i am facing some error..when a new row is created previous row's values are automatically copied ..
here is my controller class-
public class SayanTest{
public Service_Type__c acc{get;set;}
public Service_Request__c sr{get;set;}
public Service_Line_Item__c slt;
public List<Service_Line_Item__c> cont{get;set;}
//public List<Work_Order__c> wo{get;set;}
public List<Work_Order__c> wod=new List<Work_Order__c>();
public List<Service_Type__c > accl{get;set;}
//public List<Service_Line_Item__c> cont1{get;set;}
public Boolean showBank{get;set;}
public Boolean showCard{get;set;}
public Boolean showOther{get;set;}
public Boolean showTransfer{get;set;}
public boolean displayPopup {get; set;}
public boolean flag1 {get;set;}
public String selected {get;set;}
public Boolean tenkservice{get;set;}
public Boolean engineoiltype{get;set;}
public Boolean clutchtype{get;set;}
public Boolean tyretype{get;set;}
public Boolean fanbelt{get;set;}
public Boolean coolant{get;set;}
public Boolean newRow{get;set;}
public Boolean estimation{get;set;}
public Decimal engrate{get;set;}
public Decimal clutchrate{get;set;}
public Decimal tyrerate{get;set;}
public Decimal fanrate{get;set;}
public Decimal coolrate{get;set;}
public Decimal englbr{get;set;}
public Decimal clutchlbr{get;set;}
public Decimal tyrelbr{get;set;}
public Decimal fanlbr{get;set;}
public Decimal coollbr{get;set;}
public Decimal allRateSpare{get;set;}
public Decimal allRateLabour{get;set;}
public Decimal sum{get;set;}
public Decimal count{get;set;}
public Decimal total{get;set;}
public Boolean tyrecount;
public Boolean engcount;
public Boolean clutchcount;
public Boolean fanbeltcount;
public Boolean coolantcount;
public Boolean oilfiltertype{get;set;}
public Decimal s;
public decimal engspare;
public Decimal englabour;
public Decimal engqty{get;set;}
public Decimal englbrqty{get;set;}
public Decimal clutchspare;
public Decimal clutchlabour;
public Decimal clutchspareqty{get;set;}
public Decimal clutchlbrqty{get;set;}
public Decimal tyrespare;
public Decimal tyrelabour;
public Decimal tyrespareqty{get;set;}
public Decimal tyrelbrqty{get;set;}
public Decimal fanbeltspare;
public Decimal fanbeltlabour;
public Decimal fanbeltspareqty{get;set;}
public Decimal fanbeltlbrqty{get;set;}
public Decimal coolantspare;
public Decimal coolantlabour;
public Decimal coolantspareqty{get;set;}
public Decimal coolantlbrqty{get;set;}
public Decimal allspare;
public Decimal alllabour;
public Decimal allspareqty{get;set;}
public Decimal alllbrqty{get;set;}
public Decimal oilfilterspareqty{get;set;}
public Decimal oilfiltersparerate{get;set;}
public Decimal oilfilterlabourqty{get;set;}
public Decimal oilfilterlabourrate{get;set;}
public Integer jobcount;
public Integer i=0;
public SayanTest(ApexPages.StandardController controller) {
acc= (Service_Type__c)controller.getRecord();
showBank = false;
showCard = false;
showTransfer = false;
tenkservice=false;
engineoiltype=false;
clutchtype=false;
tyretype=false;
fanbelt=false;
coolant=false;
showOther=false;
newRow=false;
estimation=false;
sum=0;
s=0;
count=0;
total=0;
engcount=false;
clutchcount=false;
engrate=0;
clutchrate=0;
tyrerate=0;
fanrate=0;
coolrate=0;
allRateSpare=0;
englbr=0;
clutchlbr=0;
tyrelbr=0;
fanlbr=0;
coollbr=0;
allRateLabour=0;
tyrecount=false;
fanbeltcount=false;
coolantcount=false;
engspare=0;
englabour=0;
clutchspare=0;
clutchlabour=0;
tyrespare=0;
tyrelabour=0;
fanbeltspare=0;
fanbeltlabour=0;
engqty=0;
englbrqty=0;
clutchspareqty=0;
clutchlbrqty=0;
tyrespareqty=0;
tyrelbrqty=0;
fanbeltspareqty=0;
fanbeltlbrqty=0;
coolantspareqty=0;
coolantlbrqty=0;
allspare=0;
allspareqty=0;
alllabour=0;
alllbrqty=0;
jobcount=0;
acc = new Service_Type__c ();
cont = new List<Service_Line_Item__c>();
accl=new List<Service_Type__c >();
// wo=new List<Work_Order__c>();
//wod=new Work_Order__c();
//cont1= new List<Service_Line_Item__c>();
// slt=new Service_Line_Item__c();
AddRow();
}
public PageReference AddRow(){
//Service_Type__c s=new Service_Type__c ();
Service_Line_Item__c sli=new Service_Line_Item__c();
cont.add(sli);
return null;
}
}
here is my controller class-
public class SayanTest{
public Service_Type__c acc{get;set;}
public Service_Request__c sr{get;set;}
public Service_Line_Item__c slt;
public List<Service_Line_Item__c> cont{get;set;}
//public List<Work_Order__c> wo{get;set;}
public List<Work_Order__c> wod=new List<Work_Order__c>();
public List<Service_Type__c > accl{get;set;}
//public List<Service_Line_Item__c> cont1{get;set;}
public Boolean showBank{get;set;}
public Boolean showCard{get;set;}
public Boolean showOther{get;set;}
public Boolean showTransfer{get;set;}
public boolean displayPopup {get; set;}
public boolean flag1 {get;set;}
public String selected {get;set;}
public Boolean tenkservice{get;set;}
public Boolean engineoiltype{get;set;}
public Boolean clutchtype{get;set;}
public Boolean tyretype{get;set;}
public Boolean fanbelt{get;set;}
public Boolean coolant{get;set;}
public Boolean newRow{get;set;}
public Boolean estimation{get;set;}
public Decimal engrate{get;set;}
public Decimal clutchrate{get;set;}
public Decimal tyrerate{get;set;}
public Decimal fanrate{get;set;}
public Decimal coolrate{get;set;}
public Decimal englbr{get;set;}
public Decimal clutchlbr{get;set;}
public Decimal tyrelbr{get;set;}
public Decimal fanlbr{get;set;}
public Decimal coollbr{get;set;}
public Decimal allRateSpare{get;set;}
public Decimal allRateLabour{get;set;}
public Decimal sum{get;set;}
public Decimal count{get;set;}
public Decimal total{get;set;}
public Boolean tyrecount;
public Boolean engcount;
public Boolean clutchcount;
public Boolean fanbeltcount;
public Boolean coolantcount;
public Boolean oilfiltertype{get;set;}
public Decimal s;
public decimal engspare;
public Decimal englabour;
public Decimal engqty{get;set;}
public Decimal englbrqty{get;set;}
public Decimal clutchspare;
public Decimal clutchlabour;
public Decimal clutchspareqty{get;set;}
public Decimal clutchlbrqty{get;set;}
public Decimal tyrespare;
public Decimal tyrelabour;
public Decimal tyrespareqty{get;set;}
public Decimal tyrelbrqty{get;set;}
public Decimal fanbeltspare;
public Decimal fanbeltlabour;
public Decimal fanbeltspareqty{get;set;}
public Decimal fanbeltlbrqty{get;set;}
public Decimal coolantspare;
public Decimal coolantlabour;
public Decimal coolantspareqty{get;set;}
public Decimal coolantlbrqty{get;set;}
public Decimal allspare;
public Decimal alllabour;
public Decimal allspareqty{get;set;}
public Decimal alllbrqty{get;set;}
public Decimal oilfilterspareqty{get;set;}
public Decimal oilfiltersparerate{get;set;}
public Decimal oilfilterlabourqty{get;set;}
public Decimal oilfilterlabourrate{get;set;}
public Integer jobcount;
public Integer i=0;
public SayanTest(ApexPages.StandardController controller) {
acc= (Service_Type__c)controller.getRecord();
showBank = false;
showCard = false;
showTransfer = false;
tenkservice=false;
engineoiltype=false;
clutchtype=false;
tyretype=false;
fanbelt=false;
coolant=false;
showOther=false;
newRow=false;
estimation=false;
sum=0;
s=0;
count=0;
total=0;
engcount=false;
clutchcount=false;
engrate=0;
clutchrate=0;
tyrerate=0;
fanrate=0;
coolrate=0;
allRateSpare=0;
englbr=0;
clutchlbr=0;
tyrelbr=0;
fanlbr=0;
coollbr=0;
allRateLabour=0;
tyrecount=false;
fanbeltcount=false;
coolantcount=false;
engspare=0;
englabour=0;
clutchspare=0;
clutchlabour=0;
tyrespare=0;
tyrelabour=0;
fanbeltspare=0;
fanbeltlabour=0;
engqty=0;
englbrqty=0;
clutchspareqty=0;
clutchlbrqty=0;
tyrespareqty=0;
tyrelbrqty=0;
fanbeltspareqty=0;
fanbeltlbrqty=0;
coolantspareqty=0;
coolantlbrqty=0;
allspare=0;
allspareqty=0;
alllabour=0;
alllbrqty=0;
jobcount=0;
acc = new Service_Type__c ();
cont = new List<Service_Line_Item__c>();
accl=new List<Service_Type__c >();
// wo=new List<Work_Order__c>();
//wod=new Work_Order__c();
//cont1= new List<Service_Line_Item__c>();
// slt=new Service_Line_Item__c();
AddRow();
}
public PageReference AddRow(){
//Service_Type__c s=new Service_Type__c ();
Service_Line_Item__c sli=new Service_Line_Item__c();
cont.add(sli);
return null;
}
}
Try commenting add row in the constructor. In my opinion you are trying to create a new line item on click of a button where you will call add row.
Check this link : http://www.forcetree.com/2015/03/dynamically-addremove-rows-from-table.html
Let me know if either of them solve the issue.