内联编辑无法更新自定义控制器Apex中的数据

时间:2015-01-27 09:26:19

标签: controller salesforce inline-editing

我需要使用自定义控制器更新来自顶点的内联编辑的数据,并且Everything似乎很好,但无法更新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) }"/>  

                &nbsp;&nbsp;  

                <!-- 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();

2 个答案:

答案 0 :(得分:0)

不要使用<apex:column>标记,因为它包含列表中的最新元素,而是使用<apex:outputfield>来保持记录的字段独立。 问题可能是<apex:column>只包含列表中的最后一个元素,因此只会更新该元素。

答案 1 :(得分:-1)

尝试使用CommandLink而不是commandButton来执行!save操作