VF Code
<apex:page controller="Buffer">
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons location="top">
<apex:commandButton value="Save" action="{!SaveMethod}"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!c}" var="t">
<apex:column headerValue="Name">
<apex:inputText value="{!t.Name}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex Code
public class Buffer
{
public List<Contact> c {get;set;}
public String ids{set;get;}
public Buffer()
{
ids=ApexPages.currentPage().getParameters().get('id');
c = new List<Contact>([select Name from Contact where id=:ids]);
}
public PageReference SaveMethod()
{
update c;
return new PageReference('/'+ids);
}
}
I am trying to change the name of the contact and click Save, but the name of the contact remains the same and doesn't get changed.
Could anyone please let me know what exact change can be done to the code so that I can edit the name of the contact and save it successfully from the vf page.
c = new List<Contact>([select Name from Contact where id=:ids]);
is redundant, as the result of a query is already a List.c = [select Name from Contact where id=:ids];
works just fine.