+ Start a Discussion

Add functionality for the Accountobject

I had created a prgrame in such a way that,if i click on the add, the data entered in the input filed will bind to the list.. 
note: the code is working fine, but the issue is for the first record is not getting added, may i know why ?? onclicking on next time the record is getting ading.
apex code as follows:

public class accountexample {
  public account ac{get;set;}

   public list<account> lstacc{get;set;}
    public  accountexample(){
    lstacc= new list<account>();
    ac = new account();
      public void addtolist(){
       ac = new account();

Visuaforce page:
<apex:page controller="accountexample">
  <apex:form >
   <apex:pageblock >
     <apex:pageblockSection >
       <apex:inputField value="{!ac.name}"/>
       <apex:inputField value="{!ac.phone}"/>
       <apex:inputField value="{!ac.rating}"/>
      <apex:pageblockButtons >
        <apex:commandButton value="add" action="{!addtolist}" reRender="t" />
    <apex:pageblock >
    <apex:pageBlockTable value="{!lstacc}" var="a" id="t">
        <apex:column headerValue="Name">{!a.name}</apex:column>
        <apex:column headerValue="Phone">{!a.phone}</apex:column>
         <apex:column headerValue="Rating">{!a.rating}</apex:column>

note: for the 1st time the record is not getting added,but for the second and thrid and soon on the data is getting added.