0

my Vf page is

<apex:dataTable value="{!templook}" var="item" style="margin-left:60px;"  cellpadding="5" cellspacing="6"   >
    <apex:column headervalue="Payment For">
        {!payfor}
    </apex:column> 
    <apex:column headerValue="Unit Price">
        {!price}
    </apex:column>
</apex:datatable>

and in my constructor class

public class sitepage2 {
    public list<temp_invoice_lookup__c> templook{ get; set; }
    public sitepage2(){
        tempinvoiceid = apexpages.currentpage().getparameters().get('tempinvoiceid');
        templook = [select items_name__c,item_price__c,temp_invoice1__c from temp_invoice_lookup__c where Temp_Invoice1__c=:tempInvoiceid];
        for(integer i =0; i<templook.size();i++){
            payfor = templook[i].items_Name__c;
            price = templook[i].item_price__c;
        }
    }
    public void save(){
        for(integer i =0; i<templook.size();i++){
          itemlst.itemname = payfor;
          itemlst.Unitprice = price;
          system.debug('itemssss'+payfor +itemlst.itemname );
        } 
        itemslist.add(itemlst);
    }
}

getting only the last value in for loop....How should I overcome this issue

2

You're looping through your data in VF but never actually displaying items from the SELECT!

You display the variables payfor and price (and earlier in Apex you've carefully overwritten their values in the loop so indeed they contain only last item's data).

Change the VF to

<apex:dataTable value="{!templook}" var="item" style="margin-left:60px;"  cellpadding="5" cellspacing="6"   >
    <apex:column headervalue="Payment For">{!item.items_Name__c}</apex:column> 
    <apex:column value="{!item.item_price__c}" /> <!-- even better -->
</apex:datatable>
  • if i use like that in my external site I can't able to see those values...But internally it is running dont know y? – Eagerin Sf Nov 20 '12 at 9:30
  • Does your templook has a publicly available getter? either public List<temp_invoice_lookup__c> templook {get;private set} or maybe public List<temp_invoice_lookup__c> getTemplook()? – eyescream Nov 20 '12 at 9:33
  • public list<temp_invoice_lookup__c> templook{ get; set; } – Eagerin Sf Nov 20 '12 at 9:36
  • Weird! Can you post a bit more of your controller (the snippet you've pasted doesn't look correct because it shows a SELECT and loop that just floats in the class body (next to a save() method. Is the templook data retrieved in constructor? In another method? In your original code is the {!payfor} displayed as many times as many rows there were returned from the query (make sure for example there are 2 or more, then run the page) – eyescream Nov 20 '12 at 9:42
  • public class sitepage2 { public list<temp_invoice_lookup__c> templook{ get; set; }public sitepage2(){tempinvoiceid = apexpages.currentpage().getparameters().get('tempinvoiceid');templook = [select items_name__c,item_price__c,temp_invoice1__c from temp_invoice_lookup__c where Temp_Invoice1__c=:tempInvoiceid];for(integer i =0; i<templook.size();i++){payfor = templook[i].items_Name__c;price = templook[i].item_price__c;}}} and after this save method comes.I'm running the page when payfor is for 3 – Eagerin Sf Nov 20 '12 at 9:49

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.