I have a map called getMonthAndYear() where it creates values from the startDate and EndDate of an opp. I am also adding two other values so the map looks like this.
Product | Description | startMonth | ... | ... | endMonth.
I am using that Map to populate my pageBlockTable using apex:repeat. Under each columns, I need an inputfield to be binded to some objects fields as below.
Product => Schedule_Product__c.Product_Name__c
Description => Schedule_Product__c.Description__c
all Months => Shedule_Product_Month__c.Amount__c
I need to create a new record for each month that has an amount into it. If I have ex: Product | test | 1000$ | 2000$ it will than create 2 records
- Product test 1000$
- Product test 2000$
Right now, I have my VF Page displaying the header correctly but I am not able to bind the inputtext to the right Object and Field. Any help will be appreciated. See code below:
APEX:
<apex:page standardController="opportunity" extensions="ScheduleTable">
<apex:form >
<apex:pageBlock id="pb" title="Invoicing Schedule" >
<apex:pageBlockTable id="table1" value="{!columnContent}" var="cc">
<apex:repeat value="{!MonthAndYear}" var="myheader">
<apex:column >
<apex:facet name="header">
{! myheader }
</apex:facet>
<input id=??IncrementalID?? type="text" name="theTextInput"/>
</apex:column>
</apex:repeat>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Class:
public with sharing class ScheduleTable {
public Opportunity opp{get;set;}
public product_Schedule__c ps{get;set;}
public ScheduleTable(ApexPages.StandardController stdController) {
this.opp = (Opportunity)stdController.getRecord();
ps = new Product_Schedule__c();
}
public Set<String> getColumnContent() {
Set<String> columnContent = new Set<String>();
columnContent.add('<input id="theTextInput" type="text" name="theTextInput" />');
return columnContent;
}
public Set<String> getMonthAndYear() {
opp = [SELECT Id, Name, Start_Date__c, End_Date__c FROM Opportunity WHERE Id = : opp.Id];
Date d1 = opp.Start_Date__c;
Date d2 = opp.End_Date__c;
Map<Integer,String> monthNameMap=new Map<Integer, String>{1=>'Janvier', 2=>'Février', 3=>'Mars', 4=>'Avril', 5=>'Mai',
6=>'Juin', 7=>'Juillet', 8=>'Aout', 9=>'Septembre',10=>'Octobre',
11=>'Novembre', 12=>'Decembre'};
Set<String> monthYearSet = new Set<String>();
monthYearSet.add('Produits');
monthYearSet.add('Description');
while(d1 < d2)
{
monthYearSet.add(monthNameMap.get(d1.Month()) + ' ' + d1.Year());
d1 = d1.AddMonths(1);
}
return monthYearSet;
}
public PageReference save() {
update opp;
ps.opportunity__c = opp.Id;
insert ps;
return null;
}
}
Credits for the code: How to get custom table row headers and values on a Apex Page Table?
Thanks for your help!