在单个Visualforce页面

时间:2016-06-15 18:49:24

标签: salesforce visualforce apex

我有一个visualforce页面,它显示在商机页面布局内联中。目标是显示与机会关联的每个机会订单项(OLI)和数量输入字段。我需要能够从VF页面更改OLI的数量。我有一个从标准机会控制器扩展的控制器,一切都正确显示,但当我尝试使用自定义保存方法保存时,页面刷新,并且不更新字段的更改。任何帮助表示赞赏!

VF PAGE:

<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 with sharing 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;

}

}

1 个答案:

答案 0 :(得分:0)

问题解决了;

只需添加来自&#34; get&#34;的数据从控制器到OLIController sc的OLIlist2的一部分。请参阅下面的修改代码。

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;

}

}