I've tried to make a button that would add another row to apex:repeat that has couple apex:inputField fields in it, but with no success (i'm getting "Attempt to de-reference a null object" error)
I've created a List of objects in controller and with my method I'm adding new elements to it (which should increase row count on page), I was thinking about rerender, but even then I shouldn't be getting null reference error.
I'm pretty sure that this should be possible and I'm missing something simple.
Here's code sample:
<apex:page controller="CostInvoiceController" docType="html-5.0" showHeader="false" sidebar="false" standardStylesheets="false">
<apex:stylesheet value="{!URLFOR($Resource.SLDS220,'assets/styles/salesforce-lightning-design-system-vf.css')}"/>
<html xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" lang="en"/>
<div class="clorce" name="Button List">
<div class="slds-grid slds-grid--align-center slds-text-align--center">
<div class="slds-grid slds-wrap slds-grid--pull-padded slds-m-top--medium slds-m-bottom--medium">
<apex:form >
<table class="slds-table slds-table--bordered slds-table--cell-buffer">
<thead>
<tr class="slds-text-title--caps">
<th scope="col">
<div class="slds-truncate" title="Cost Name">Cost Name</div>
</th>
</tr>
</thead>
<apex:outputPanel >
<apex:repeat value="{!costInvoices}" var="cost" id="theRepeat">
<tbody>
<tr>
<th scope="row" data-label="Cost Name">
<div class="slds-truncate" title="Date"><apex:inputField value="{!cost.Data_platnosci__c}" styleClass="slds-input"/> </div>
</th>
</tr>
</tbody>
</apex:repeat>
</apex:outputPanel>
</table><br/>
<apex:commandButton value="Dodaj line item" action="{!addInvoice}" styleclass="slds-button slds-button--brand"/>
</apex:form>
</div>
</div>
</div>
</apex:page>
Controller:
public class CostInvoiceController {
public List<Cost_Invoice__c> costInvoices {get; set;}
public void addInvoice()
{
Cost_Invoice__c NewCI = new Cost_Invoice__c(Data_wystawienia_faktury__c =date.today() ,Data_platnosci__c = date.today());
costInvoices.add(NewCI);
}
}