无法将SOQL查询中的行输出到<apex:repeat> </apex:repeat>

时间:2012-12-14 21:22:28

标签: salesforce apex-code visualforce soql

我收到了这个错误:

Description Resource    Path    Location    Type
Save error: Unknown property 'OpportunityStandardController.getLines'   AlexHelloWorld.page /SFDC/src/pages line 0  Force.com save problem

VF页面:

<apex:page standardController="Opportunity" extensions="AlexHelloWorld">
    <apex:form >
        <apex:pageBlock title="Edit account for {!$User.FirstName}">
            <apex:pageMessages />
            <apex:pageBlockButtons >

            </apex:pageBlockButtons>
            <apex:pageBlockSection >
                <apex:outputText value="Test - {!retVal}">
                </apex:outputText>
            </apex:pageBlockSection>
            <apex:pageBlockSection >
                <apex:outputText value="OppId - {!opportunity.id}" />
                <apex:outputText value="UserId - {!$User.Id}" />
            </apex:pageBlockSection>
            <apex:pageBlockSection>
                <apex:repeat value="{!getLines}" var="line" id="theRepeat">
                    <tr>
                        <td valign="top"><apex:outputField value="{!line.Id}" /></td>
                        <td valign="top"><apex:outputField value="{!line.OpportunityId}" /></td>
                        <td valign="top"><apex:outputField value="{!line.PricebookEntryId}" /></td>
                        <td valign="top"><apex:outputField value="{!line.Quantity}" /></td>
                    </tr>
                </apex:repeat>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

控制器:

public with sharing class AlexHelloWorld {

    public boolean  showFedEx{get;set;}
    public String   mystr{get;set;}
    public Id       opportunityId{get;set;}

    //public Opportunity opportunity{get;set;}
    public Decimal retVal{get;set;}

    //Main controller class
    public AlexHelloWorld(ApexPages.StandardController controller)
    {
        mystr = [SELECT Email from User where Id =:Userinfo.getUserId()].Email;
        showFedEx = true;
        retVal = 5*5;
        System.debug('zzzzz');
    }

    public List<OpportunityLineItem> getLines()
    {       
        List<OpportunityLineItem> oli = [SELECT Id, OpportunityId, PricebookEntryId, Quantity FROM OpportunityLineItem where id =:System.currentPageReference().getParameters().get('id')];

        return oli;     
    }
}

1 个答案:

答案 0 :(得分:2)

简单错误:)您应该跳过函数名称中的“get / set”。我同意这不是世界上最明确的错误信息。

您的VF页面应该调用{!lines},而不是{!getLines}(Visualforce不区分大小写,Apex也不是)。然后它会编译得很好。

...
<apex:repeat value="{!lines}" var="line" id="theRepeat">
...

这是如此根本我甚至不确定在文档中链接到哪里(没有冒犯),也许http://www.salesforce.com/us/developer/docs/pages/index_Left.htm#StartTopic=Content/pages_quick_start_controller_getter_methods.htm


一个小问题 - 如果您有机会standard controller,您可能希望在构造函数中执行此操作:

Opportunity opp = (Opportunity) controller.getRecord();

实际上,您可以忽略整个控制器端并直接从Visualforce显示相关项列表(但如果您想要对它们进行排序,这对您没有帮助。)

<apex:repeat value="{!Opportunity.OpportunityLineItems}" var="line" id="theRepeat">
    <tr>
        <td valign="top"><apex:outputField value="{!line.Id}" /></td>
        <td valign="top"><apex:outputField value="{!line.OpportunityId}" /></td>
        <td valign="top"><apex:outputField value="{!line.PricebookEntryId}" /></td>
        <td valign="top"><apex:outputField value="{!line.Quantity}" /></td>
    </tr>
</apex:repeat>