2

I have created a vf page in this page there is one form and one PageBlock table.My requirement is whenever I click on submit button of form a tuple will be added to the table(I am able to do this) but when I am inserting one more record and clicking on submit the current tuple is overriding the existing tuple.I want to add tuple on each submit button click.Here is my VF page:

<apex:page StandardController="TimeSheet__c" extensions="TimeSheet_Controller" showHeader="True" sidebar="false">
    <apex:form id="SfForm">
    <apex:pageblock title="Timesheet" id="pb1">
                <apex:pageblockSection id="pbs1">
                    <apex:inputField value="{!TimeSheet__c.Employee_Name__c}"/>
                    <apex:inputField value="{!TimeSheet__c.Department__c}"/>
                    <apex:inputField value="{!TimeSheet__c.Date__c}"/>
                    <apex:inputField value="{!TimeSheet__c.Today_s_Tasks__c}"/>
                    <apex:inputField value="{!TimeSheet__c.Hours__c}"/> 
                    <apex:inputField value="{!TimeSheet__c.Min__c}"/>
                    <apex:inputField value="{!TimeSheet__c.Current_Project__c}"/>
               </apex:pageblockSection>   

                <apex:pageblockButtons >
                  <apex:commandButton value="Trial" action="{!addrow}" />
                </apex:pageblockButtons>                   
    </apex:pageBlock> 

       <apex:outputPanel id="panel" > 
    <apex:pageBlock id="pb2" rendered="true">           
                <apex:pageBlockTable value="{!TimeSheet__c}"  var="tm">

                    <apex:column headervalue="Name" value="{!tm.Employee_Name__c}"/>
                    <apex:column value="{!tm.Department__c}" headerValue="Department"/>
                    <apex:column value="{!tm.Date__c}" headervalue="Date"/>
                    <apex:column value="{!tm.Hours__c}" headervalue="Hours"/>
                    <apex:column value="{!tm.Current_Project__c}" headervalue="Current Project"/>
                </apex:pageBlockTable>
    </apex:pageBlock>    

           </apex:outputPanel>             
    </apex:form>  
</apex:page>

Controller:-

public class TimeSheet_Controller{
    public timesheet__c tmst{get;set;}
    public contact cobj{get;set;}
    public List<timesheet__c> timeSheetList = new List<timesheet__c>();

        public TimeSheet_Controller(ApexPages.StandardController controller) {

        } 

        public PageReference submit(){
            return null;
        }

        public void addRow()
        {
              timeSheetList.add(new timesheet__c());
              timesheet__c ts=new timesheet__C();

        }


}

1 Answer 1

2

In your PBT

apex:pageBlockTable value="{!TimeSheet__c}"  var="tm">

In value use timesheetlist instead of timesheet__c object

2
  • When I am replacing timesheet__c from timesheetlist it is giving this error. <apex:pageBlockTable value="{!TimeSheetList}" var="tm"> Error: Unknown property 'TimeSheet__cStandardController.TimeSheetList'
    – Guru
    Commented Aug 20, 2016 at 10:50
  • @Guru declare the timesheetlist with get set so you can access it on visualforce Commented Aug 20, 2016 at 10:52

You must log in to answer this question.

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