在单个 Visualforce 页面上更新多个机会行项目的数量

Update quantity of multiple opportunity line items on single Visualforce page

我有一个 visualforce 页面显示在机会页面布局上。目标是使用数量输入字段显示与机会关联的每个机会行项目 (OLI)。我需要能够从 VF 页面更改 OLI 的数量。我有一个从标准机会控制器扩展而来的控制器,并且一切都正确显示,但是当我尝试使用我的自定义保存方法进行保存时,页面会刷新并且对字段的更改不会更新。感谢您的帮助!

VF 页面:

<apex:page standardController="Opportunity" extensions="OLIController">
<apex:form >
<apex:pageBlock title="Opportunity Products">



    <apex:pageBlockTable var="OLI" value="{!OLIs}" id="newProduct">
        <apex:column value="{!OLI.name}"/>
        <apex:column headerValue="Quantity">

            <apex:inputfield id="Quantity" value="{!OLI.Quantity}"/>

        </apex:column>

    </apex:pageBlockTable>

    <apex:pageBlockButtons >
        <apex:commandButton value="Save" action="{!saveIt}" immediate="false"/>
    </apex:pageBlockButtons>

</apex:pageBlock>
</apex:form>

控制器: public 共享 class OLIController {

public ApexPages.StandardController sc;
public Opportunity Opp {get;set;}
private Map<Id, OpportunityLineItem> oliItems;
public List<OpportunityLineItem> OLIlist2 {get ;set;}

public OLIController(ApexPages.StandardController sc) { 
this.Opp = (Opportunity)sc.getRecord();

}


public List<OpportunityLineItem> getOLIs() {

    List<OpportunityLineItem> OLIlist2 = [Select Name, ID, Quantity, OpportunityId FROM OpportunityLineItem WHERE OpportunityId =:Opp.Id];

    return OLIlist2;

}
public PageReference saveIt() {
    List<OpportunityLineItem> listOLI = getOLIs();

    update listOLI;

    return null;

}

}

问题已解决;

只需要将来自控制器的 OLIlist2 的 "get" 部分的数据添加到 OLIController sc。请参阅下面修改后的代码。

public with sharing class OLIController {

public ApexPages.StandardController sc;
public Opportunity Opp {get;set;}
public List<OpportunityLineItem> OLIlist2 {get ;set;}

public OLIController(ApexPages.StandardController sc) { 
this.Opp = (Opportunity)sc.getRecord();
OLIlist2 = [Select Name, ID, Quantity, OpportunityId FROM OpportunityLineItem WHERE OpportunityId =:Opp.Id];
}


public List<OpportunityLineItem> getOLIs() {

    List<OpportunityLineItem> OLIlist2 = [Select Name, ID, Quantity, OpportunityId FROM OpportunityLineItem WHERE OpportunityId =:Opp.Id];

    return OLIlist2;

}
public PageReference saveIt() {
   // List<OpportunityLineItem> listOLI = getOLIs();

    update OLIlist2;

    return null;

}

}