You need to sign in to do that
Don't have an account?
Ethan Hotz
Saving a list of custom objects using a custom controller
So I've been stuck on this for way too long; I've scoured the forums and made every change I could think of, but I have no idea why I'm not getting the save to function. I've tried using the standard controller's save, and the current setup using the custom save method. The way I've got it set now, the developer console shows that there are DML calls being made, but the changes aren't sticking.
If someone could tell me where I'm going wrong, I'd really appreciate it.
The VF page:
If someone could tell me where I'm going wrong, I'd really appreciate it.
The VF page:
<apex:page standardController="WeeklyDevStats__c" recordSetVar="weeklyDevList" extensions="MaxHoursController2"> <apex:pageBlock > <apex:pageMessages /> <apex:pageBlockSection > <apex:form > <apex:selectList label="Week" value="{!selectedWeek}" size="1" multiselect="false" > <apex:actionSupport event="onchange" action="{!changeWeek}" /> <apex:selectOptions value="{!weeks}" /> </apex:selectList> </apex:form> </apex:pageBlockSection> <apex:pageBlockSection > <apex:dataTable value="{!weeklyDevList}" var="dev" columnsWidth="150"> <apex:column headerValue="Developer"> <apex:outputField value="{!dev.Dev_name__c}"/> </apex:column> <apex:column headerValue="Max Hours"> <apex:form ><apex:inputField value="{!dev.MaxHours__c}"> </apex:inputField></apex:form> </apex:column> </apex:dataTable> </apex:pageBlockSection> </apex:pageBlock> <apex:form ><apex:commandButton value="Save" action="{!saveHours}"/></apex:form> </apex:page>The controller:
public class MaxHoursController2 { public String selectedWeek { get; set; } public List<SelectOption> weeks { get; set; } public List<WeeklyDevStats__c> weeklyDevList {get; set;} public Apexpages.standardsetcontroller sc; public MaxHoursController2(ApexPages.StandardSetController controller) { sc = controller; selectedWeek = CalendarClass.getInstance().getMonday().format(); weeks = new List<SelectOption>(); setWeekList(); setWeeklyDevList(Date.parse(selectedWeek)); } public PageReference changeWeek() { setWeeklyDevList(Date.valueOf(selectedWeek)); return null; } public PageReference saveHours() { try { update weeklyDevList; } catch(DMLException e) { Apexpages.addmessages(e); } return null; } public void setWeekList() { for (Date day : CalendarClass.getInstance().getNextMondays(8)) { weeks.add(new SelectOption(String.valueOf(day), String.valueOf(day))); } } public void setWeeklyDevList(Date week) { weeklyDevList = [SELECT Dev_name__c, MaxHours__c FROM WeeklyDevStats__c WHERE Week_dev__c = :week]; } public List<WeeklyDevStats__c> getWeeklyDevList() { return weeklyDevList; } }
May I know why you need multiple <apex:form> in your page? Perhaps you can just use one, but move the closing </form> to the last line before your </apex:page>. The code will look something like this:
All Answers
May I know why you need multiple <apex:form> in your page? Perhaps you can just use one, but move the closing </form> to the last line before your </apex:page>. The code will look something like this: