+ Start a Discussion
NishhNishh 

Problem in Select List and wrapper class

I am getting problem in my select List of product2 object. and i want to use that select list value in query
How can i get value of selectValue in controller from visualforce page?

<apex:pageBlockTable value="{!wrapList}" var="w">
<apex:column headerValue="Product Name">
<apex:selectList id="products" value="{!w.selectValue}" size="1" title="Select Value">
  <apex:selectOptions value="{!products}"></apex:selectOptions>
  <apex:actionSupport action="{!ProductValue}" event="onchange" reRender="price" status="status"/>
</apex:selectList>
</apex:column>
</apex:pageBlockTable>
public void ProductValue()
{
priceGridList = [Select Id, Name From Quantity_Price_Grid__c Where Product__c =: selectValue];
}

public class Wrapper
{
public OpportunityLineItem OLI {get;set;}
public Integer rowIndex {get;set;}
public String selectValue {get; set;}
}
bob_buzzardbob_buzzard
You can't use the selected value in the SOQL query like that - you are assuming a single value, but the selected value is stored per-instance of wrapper class. You'll need to figure out which instance of the wrapper class has been updated when the actionsupport fires. I'd use an apex:param inside the actionSupport that contains the rowIndex, if that is unique, otherwise use the id of the opportunitylineitem.

<apex:actionSupport action="{!ProductValue}" event="onchange" reRender="price" status="status">
  <apex:param name="rowIdx" value="{!w.rowIndex}" assignTo="{!selectedRowIdx}" />
</apex:actionSupport>
Then in the controller, figure out the entry for the selected wrapper:

public Integer selectedRowIdx {get; set;}

public void ProductValue()
{
   Wrapper wrap=null
   Integer idx=0;
   while ( (null==wrap) && (idx<wraplist.size()) )
   {
      if (wraplist[idx].rowIndex=selectedRowIdx)
      {
        wrap=wraplist[idx];
      }
      else
      {
        idx++;
      }
   }

   if (null!=wrap)
   {
     priceGridList = [Select Id, Name From Quantity_Price_Grid__c Where Product__c =:wrap.selectValue];
   }
}