+ Start a Discussion
BridgetreeBridgetree 

fetch data using lookup

Hi........

 

      I have a table in visualforce refering to some custom object extending to a controller. In the coloumn i have a lookup for product. I have a custom field called 'make' in prodcuts table. 

 

Now current requirement is that, once i select a product using the lookup, it has to render me the make of the product in the other column.

 

please help me.

 

Thanks in advance !!!!

 

 

bob_buzzardbob_buzzard

You'll need to execute an action method on the controller once the user has chosen the value.  This method will need to retrieve the record for the id present in the lookup, extract the make of the product and add that to the data structure that is backing the table.

 

In theory you should be able to use the onchange event for the inputfield and make an actionfunction call to cause this to happen.  I recall that the onchange event didn't fire for lookups, as the value is set by javascript rather than by the user, though that may be fixed now.  I ended up using the onblur event handler, so when the user went elsewhere in the page the choice was submitted back, but its less than ideal.

BridgetreeBridgetree

Thanks for the reply,

 

         I did the same, but it didn't work. The VF page is lik this,

 

             <apex:actionRegion >     

<apex:pageBlockSection title="Invoice Line Items" id="Section1" >   

       <apex:pageBlockTable value="{!prdts}" var="a" id="table"> 

                                    <apex:column headerValue=" Product Name">   

                      <apex:inputField value="{!a.Product__c}">         

              <apex:actionSupport event="onblur" action="{!ProductSelected}" Status="counterStatus" reRender="Section1" />                                  </apex:inputField>   

                            <apex:actionStatus startText="pls wait" id="counterStatus" />                             

                        </apex:column>

                <apex:column headerValue=" Make">   

                        <apex:outputText value="{!pricelist}" ></apex:outputText>   

                </apex:column> </apex:pageBlockTable> 

         </apex:pageBlockSection>

  </apex:actionRegion>

 

and the controller is like this..

 

public List<Product2> lProductInfo = new List<Product2>();

public decimal pricelist {get; set;}


 public decimal getpricelist()   

{ return price;    } 

         public string ProductSelected()

               {

                lProductInfo = [Select p.Price__c From Product2 p where name =:prods.Product__c];

                for(Product2 pp:lProductInfo)         

                {

                     price=pp.Price__c;   

                 } 

        return null;       

}

 

Please let me know where i have gone wrong. Please correct me.

 

 

bob_buzzardbob_buzzard

Is this your full controller?  I can't see where the prods variable is initialised that is used to select your product info.

BridgetreeBridgetree

this is my complete controller

 

 

public class invoiceController {

    public SalesInvoice__c prods=null;
    public List<Product2> lProductInfo = new List<Product2>();
    public decimal price=0;
    public Integer rCount = 0;
    public List<SalesInvoice__c> prdts {get; set;}
    public List<SalesInvoice__c> data= new List<SalesInvoice__c>(); 
    public decimal pricelist {get; set;}
    
    public invoiceController(ApexPages.StandardController controller) {
        prdts = new List<SalesInvoice__c>();
        prdts.add(new SalesInvoice__c());
        prods=new SalesInvoice__c();
    
    }

    
       
    public decimal getpricelist()
    {
        return price;
    }
    
    public string ProductSelected()
    {
         lProductInfo = [Select p.Price__c From Product2 p where name =:prods.Product__c]; 
         for(Product2 pp:lProductInfo)
         {
           price=pp.Price__c;
           
         }
         return null;
    
    }
    
}    
   

    
    

bob_buzzardbob_buzzard

It looks to me like the problem lies with prods - this is instantiated in the controller constructor, but isn't backing anything in the page.  You'll need to traverse the prdts list and pull back the product information based on the product__c custom field for each of them.

BridgetreeBridgetree

can u provide some lines of progs where i am missing. It would of great help. please.