2013-08-22 18 views

回答

0

在页面

<apex:dataTable value="{!accountList}" var="a" > 
<apex:column > 
    <apex:column headerValue="Action"> 
     <apex:commandLink value="Save" action="{!save}" rerender="table" > 
      <apex:param name="Id" value="{!a.Id}" /> 
     </apex:commandLink> 
</apex:column> 
</apex:dataTable> 

控制器

List<accountwrapper> accountList = new List<accountwrapper>(); 

public class accountwrapper 
{ 
    public Account acc{get; set;} 
    public string id {get; set;} 
    public accountwrapper(Account a,string id) 
    { 
     this.acc = a; 
     this.id = id; 
    } 
} 

public PageReference save() 
{ 
    string accId = ApexPages.CurrentPage().getParameters().get('id'); 
    for(accountwrapper accwrapper : accountList){ 
     if(accwrapper.id == accId) 
      upsert accwrapper.acc; 
    } 
    return null; 
}