I tried to create account records using datable.Its worked fine when the command button is .But using immediate button in the command button (i.e)its not working
VF
<apex:page controller="accountcontroller">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:dataTable value="{!acc}" var="a" cellpadding="4" border="1" rows="3" >
<apex:column headervalue="account name" width="20" >
<apex:inputField value="{!a.name}" required="true"/>
</apex:column>
<apex:column headervalue="account site" width="20" >
<apex:inputField value="{!a.site}" required="true"/>
</apex:column>
<apex:column headervalue="account phone" width="20" >
<apex:inputField value="{!a.phone}" required="true"/>
</apex:column>
</apex:dataTable>
</apex:pageBlockSection>
<apex:pageblockButtons >
<apex:commandButton value="save" action="{!insertNewItem}" immediate="true" />
</apex:pageblockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
apex
public class accountcontroller {
public list<account> acc{get;set;}
public accountcontroller(){
acc= new list<account>();
for ( integer i = 0 ; i < 3 ;i++ ) {
account ac = new account();
acc.add(ac);
}
}
public PageReference insertNewItem() {
insert acc;
system.debug('<<<<<<<<<<<<'+acc);
acc= new list<account>();
/*
for(integer i=0 ; i<3 ;i++){
account ac = new account();
acc.add(ac);}
*/
return null;
}
}