我需要使用自定义控制器从 apex 中的内联编辑更新数据,一切似乎都很好,但无法更新 PageBlockTable 中提供的值 List.该页面应该一次获取 10 条记录请帮助...
<!--Visual Forcepage-->
<apex:page controller="NativeAccountsClass">
<apex:form >
<apex:pageBlock title="Accounts with Mailing Address set to India" id="accounts_list" mode="inlineEdit" >
<apex:commandButton action="{!save}" value="Save" id="saveButton"/>
<!--
<apex:commandButton value="Cancel" id="cancelButton"/>
-->
<apex:pageBlockTable value="{! ListOfAccounts }" var="ac">
<!-- <apex:inlineEditSupport event="ondblclick" showOnEdit="saveButton"/> -->
<apex:column value="{! ac.Name }">
<apex:facet name="header">
<apex:commandLink action="{!sortByName}" reRender="accounts_list">Name
</apex:commandLink>
</apex:facet>
<!-- -->
</apex:column>
<!--
<apex:column>
<apex:facet name='header'>
<apex:commandLink action="{!sortByParent}" reRender="accounts_list">Parent
</apex:commandLink>
</apex:facet>
</apex:column>
-->
<apex:column value="{! ac.Rating}">
<apex:facet name="header">
<apex:commandLink action="{! sortByRating}" reRender="accounts_list">Rating
</apex:commandLink>
</apex:facet>
</apex:column>
<apex:column value="{! ac.NumberOfEmployees}">
<apex:facet name="header">
<apex:commandLink action="{! sortByNoOfEmployees}" reRender="accounts_list">Total Employees
</apex:commandLink>
</apex:facet>
</apex:column>
<apex:column value="{! ac.Website}">
<apex:facet name="header">
<apex:commandLink action="{! sortByWebsite}">Website
</apex:commandLink>
</apex:facet>
</apex:column>
<apex:column value="{! ac.BillingCountry }" />
</apex:pageBlockTable>
<!-- Pagination -->
<table style="width: 100%"><tr>
<td>
Page: <apex:outputText value=" {!pageNumber} of {! CEILING(resultSize/pageSize)}" />
</td>
<td align="center">
<!-- Previous page -->
<!-- active -->
<apex:commandLink action="{! Previous }" value="« Previous"
rendered="{! HasPrevious }" reRender="accounts_list" />
<!-- inactive (no earlier pages) -->
<apex:outputText style="color: #ccc;" value="« Previous"
rendered="{! NOT(HasPrevious) }"/>
<!-- Next page -->
<!-- active -->
<apex:commandLink action="{! Next }" value="Next »"
rendered="{! HasNext }" reRender="accounts_list"/>
<!-- inactive (no more pages) -->
<apex:outputText style="color: #ccc;" value="Next »"
rendered="{! NOT(HasNext) }"/>
</td>
<td align="right">
<!-- Records per page -->
</td>
</tr></table>
</apex:pageBlock>
</apex:form>
</apex:page>
控制器 :
public class NativeAccountsClass {
String country='india';
String sortOrder = 'Name';
Map<integer,List<Account>> results;
public List<Account> ListOfAccounts{get;set;}
public Integer pageSize{get;set;}
public Integer pageNumber{get;set;}
public Integer resultSize{get;set;}
Integer noOfPages;
List<Account> allRecords;
List<Account> updatedList;
Account accountobj;
public Boolean HasPrevious{get;set;}
public Boolean HasNext {get;set;}
public NativeAccountsClass(){
updatedList = new List<Account>();
HasPrevious = False;
HasNext = True;
pageSize=10;
pageNumber=1;
String accountQuery = 'Select Name,Rating,NumberOfEmployees,Website,BillingCountry ' +
'FROM Account ' +
'WHERE BillingCountry = :country ' +
'ORDER BY ' + sortOrder + ' ASC';
allRecords = Database.query(accountQuery);
resultSize = allRecords.size();
Integer recForPage;
Integer page=1,index=0;
List<Account> tempList = new List<Account>();
results = new Map<integer,List<Account>>();
noOfPages =resultSize/pageSize;
Integer div = Math.mod(resultSize,pageSize);
if(div>0)
noOfPages++;
while(page<=noOfPages){
recForPage=1;
System.debug('Pageno = '+ page );
while(recForPage<=pageSize && Index < resultSize){
tempList.add(allRecords.get(index));
recForPage++;
index++;
}
results.put(page,tempList);
tempList= new List<Account>();
page++;
}
ListOfAccounts = results.get(pageNumber);
}
public void getAccounts(){
ListOfAccounts = results.get(pageNumber);
}
public void save(){
System.debug(ListOfAccounts);
update ListOfAccounts;
getAccounts();
}
public void sortByParent(){
this.sortOrder = 'Parent';
allRecords=NULL;
getAccounts();
}
public void sortByRating(){
this.sortOrder = 'Rating';
allRecords=NULL;
getAccounts();
}
public void sortByNoOfEmployees(){
this.sortOrder = 'NumberOfEmployees';
allRecords=NULL;
getAccounts();
}
public void sortByWebsite(){
this.sortOrder = 'Website';
allRecords=NULL;
getAccounts();
}
public void sortByName(){
this.sortOrder='Name';
allRecords = NULL;
getAccounts();
}
/*
public integer getpageSize(){
return this.pageSize;
}
public integer getpageNumber(){
return this.pageNumber;
}
public Integer getresultSize(){
return resultSize;
}
*/
public void Previous(){
HasPrevious =True;
HasNext = True;
pageNumber--;
if(pageNumber == 1)
HasPrevious =false;
getAccounts();
}
public void Next(){
HasPrevious = True;
pageNumber++;
if(pageNumber == noOfPages)
HasNext = False;
else
HasNext = True;
getAccounts();
不要使用 <apex:column>
标记,因为它包含列表中的最新元素,而要使用<apex:outputfield>
,这将使记录的字段保持独立。问题可能是<apex:column>
仅包含列表中的最后一个元素,因此只会更新该元素。
尝试使用 CommandLink 而不是 commandButton 执行 !save 操作