1

This is my class

public class Displayprods1
{
    public List<OpportunityLineItem> proList{get;set;}
    List<OpportunityLineItemwrapper> OppList  {get;set;}
    public Displayprods1(ApexPages.StandardController controller)
    {
        OppList = new List<OpportunityLineItemwrapper>();
    }
    public void populate()
    {
        list<OpportunityLineItem > plist = [select id,Quantity,ListPrice,TotalPrice from OpportunityLineItem limit10];
        for(OpportunityLineItem pr:plist)
        {
            OpportunityLineItemwrapper w1 = new OpportunityLineItemwrapper();
            w1.name = pr.name;
            w1.Quantity = Integer.valueOf(pr.Quantity);
            w1.ListPrice = pr.ListPrice;
            w1.TotalPrice = pr.TotalPrice;
            OppList.add(w1);
        }
    }
}
wrapper class
public class OpportunityLineItemwrapper {
// all the line record instance create
        public OpportunityLineItem pro{get; set;} 
        public  string name {get;set;}
        public  integer Quantity {get;set;} 
        public  decimal ListPrice {get;set;} 
        public  decimal TotalPrice {get;set;} 
        public  Boolean selected {get; set;} 
        public OpportunityLineItemwrapper()
        {      
               name  = '';
               Quantity = 0;
               ListPrice = 0 ;
               TotalPrice = 0;
        }

}

visual force page

<apex:page standardController="Opportunity" extensions="Displayprods1"> 
    <apex:form>
    <apex:pageblock>
     <apex:repeat value="{!OppList}" var="a">
       <apex:inputField value = "{!a.name}"/>
         <apex:inputField value = "{!a.Quantity}"/>
         <apex:inputField value = "{!a.ListPrice}"/>
         <apex:inputField value = "{!a.TotalPrice}"/>
        </apex:repeat>    
    </apex:pageblock>
        <apex:pageBlockButtons>
        <apex:commandButton value = "populate" action="{!populate}"/>
        </apex:pageBlockButtons>
    </apex:form>
</apex:page>
0

Your OppList variable is not at least public, as the default for a variable or method with no access modifier is private. This means that Visualforce cannot "see" the variable. Adding the public keyword will fix this problem.

  • Could not resolve the entity from <apex:inputField> value binding '{!a.name}'. <apex:inputField> can only be used with SObjects, or objects that are Visualforce field component resolvable. – bingi Jun 11 '16 at 3:49
  • problem showing – bingi Jun 11 '16 at 3:51
  • @bingi You should be binding to a record (in your wrapper, is pro), like this: <apex:inputField value="{!a.pro.name}" />. – sfdcfox Jun 11 '16 at 5:29
0

There are lot of problems in the code.

I have tried to rectify that.

public class Displayprods1{
public List<OpportunityLineItem> proList{get;set;}
public List<OpportunityLineItemwrapper> OppList  {get;set;}
private final Opportunity objOpportunity;
public Displayprods1(ApexPages.StandardController controller)
{
    OppList = new List<OpportunityLineItemwrapper>();
    this.objOpportunity = (Opportunity) controller.getRecord();
}
public void populate()
{
    list<OpportunityLineItem> plist = [select id,Name, Quantity,ListPrice,TotalPrice from OpportunityLineItem where OpportunityId=:objOpportunity.Id limit 10];
    for(OpportunityLineItem pr:plist)
    {
        OpportunityLineItemwrapper w1 = new OpportunityLineItemwrapper();
        w1.name = pr.name;
        w1.Quantity = Integer.valueOf(pr.Quantity);
        w1.ListPrice = pr.ListPrice;
        w1.TotalPrice = pr.TotalPrice;
        OppList.add(w1);
    }
}

}

visualforce page:

<apex:page standardController="Opportunity" extensions="Displayprods1"> 
<apex:form >
     <apex:pageblock >   
     <apex:repeat value="{!OppList}" var="a">
       <apex:inputField value="{!a.pro.name}"/>
         <apex:inputField value="{!a.pro.Quantity}"/>
         <apex:inputField value="{!a.pro.ListPrice}"/>
         <apex:inputField value="{!a.pro.TotalPrice}"/>
     </apex:repeat>    

    <apex:pageBlockButtons >
        <apex:commandButton value="populate" action="{!populate}"/>
    </apex:pageBlockButtons>
    </apex:pageblock>     
</apex:form>

Atleast now it is workable. If you are happy please mark the answer.

You can refer Visualforce in practice for learning and referencing.

  • Would you mark the answer or up vote if you are satisfied – Santanu Boral Jun 12 '16 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.