function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
BridgetreeBridgetree 

pageBlockTable and coloumn reprtion.

Hiiiiiiii

 

         I have a pageBlockTable and a addRow function. Everything is working fine. But There is a lookup field in row. Once the field is filled up with data i have written a prog to get its other details and fill in other column of the table. Now if i create a row again, The lookup field is automatically filled which i donn't want to happen. 

 

Can anyone suggest how to do that

 

Thanks in advance.

bob_buzzardbob_buzzard

It sounds like you are cloning an earlier row if the lookup value is filled in.  Is a bit tricky to say for sure without sight of the code.  

BridgetreeBridgetree
public Product2 prodRecord=new Product2(Name='@',Tax_Value__c=0);
    public Integer rCount = 0;
    public List<SalesInvoice__c> prdts {get; set;}
    
    
    public invoiceController(ApexPages.StandardController controller) {
        prdts = new List<SalesInvoice__c>();
        prdts.add(new SalesInvoice__c());
   }
public string CopyProdInfo()
   {
   Product2 prodinfo= [Select p.Price__c From Product2 p where id =:prods.Product__c];
   if(prodinfo.Price__c !=null)
   {
     prodRecord.Price__c=prodinfo.Price__c;
   }
   return null;
   }
public void addrow(){
        prdts.add(rCount,new Salesinvoice__c());
        
        rCount=rCount+1;
        
    }
<apex:dataTable value="{!prdts}" var="a" id="table">
                <apex:facet name="footer">
                    <apex:commandLink value="Add Row" action="{!addRow}" rerender="table,error"/>
                </apex:facet>
                
                <apex:column headerValue=" Product Name">
                <apex:actionRegion >
                  <apex:inputField value="{!productss.Product__c}" id="prodname">
                  <apex:actionSupport event="onblur" action="{!CopyProdInfo}" />
                         
                 </apex:inputField>
         </apex:actionRegion>
                
                </apex:column>
                   
                <apex:column headerValue=" QTY">
                   <apex:inputText size="5" id="qty"/>
                </apex:column>
                <apex:column headerValue=" Unit Price">
                  <apex:inputText value="{!prodRecord.Price__c}" id="unitprice" disabled="true" size="5" />
                  
                   
                </apex:column>
</apex:dataTable>
bob_buzzardbob_buzzard

I'm guessing the lookup is this piece:

 

  <apex:inputField value="{!productss.Product__c}" id="prodname">

 

The problem here is that the field isn't coming from the records you are iterating, but from another property called productss (that isn't in the code).  

BridgetreeBridgetree

ya i know the prpoblem is that.. but i need to have that to execute my query. The look up need to fetch other data of the record in actionSupport. 

BridgetreeBridgetree

i have put this code...

 

    

 public SalesInvoice__c getproductss()
    {
        return prods;

}

bob_buzzardbob_buzzard

As you effectively have a single field backing every instance of this column, the lookup will be the same across all of them.  You'll need to change this so that the lookup comes from the instance of the list you are iterating.  I reckon you want to use a wrapper class to encapsulate the record and its position in the list, then you can pass that back as an apex:param to the actionfunction.

BridgetreeBridgetree

thanks for the reply...

 

could you pls give me some hint on how to do as you suggested...

 

some lines of code would be very helpful...

bob_buzzardbob_buzzard

Here goes:

 

The wrapper class would look something like:

 

public class ProductWrapper
{
    SalesInvoice__c product {get; set;}
    Integer idx {get; set;}
}

The idx is simply a unique number.  You'd then back the table with a list of these objects rather than the list of SalesInvoice__c.  In your actionfunction you pass the idx back:

 

<apex:dataTable value="{!wraps}" var="wrap" id="table">
                <apex:facet name="footer">
                    <apex:commandLink value="Add Row" action="{!addRow}" rerender="table,error"/>
                </apex:facet>
                
                <apex:column headerValue=" Product Name">
                <apex:actionRegion >
                  <apex:inputField value="{!wrap.Product__c}" id="prodname">
                  <apex:actionSupport event="onblur" action="{!CopyProdInfo}">
                    <apex:param name="idx" assignTo="{!chosenIdx}" value="{!wrap.idx}"/>
                  </apex:actionSupport>
                         
                 </apex:inputField>
         </apex:actionRegion>
                
                </apex:column>
                   
                <apex:column headerValue=" QTY">
                   <apex:inputText size="5" id="qty"/>
                </apex:column>
                <apex:column headerValue=" Unit Price">
                  <apex:inputText value="{!prodRecord.Price__c}" id="unitprice" disabled="true" size="5" />
                  
                   
                </apex:column>
</apex:dataTable>

 and in your controller method you'd iterate the list of wrapper classes, find the element where chosenIdx=wrapper.idx and retrieve the appropriate information.