+ Start a Discussion
azzaniazzani 

My Setter Method is never called

Hi All,

I am overriding the "Add Product" button and I am constructing the "Product Selection table". To do that I used the markup and custom controller getter and setter below. I also created a class that represent a PricebookEntry record along with a checkbox element. The getter works fine but my setter is never called when the user click the "select" button. I need the setter to parse returned result to know which Products were selected and update the class List for selected Price book entries. This is very time critical issue so I will really appreciate prompt help.

Thanks,

Aref

Code:
<apex:form >  
  <apex:outputPanel id="ProductsTable">    
   <apex:pageblock > 
    <apex:pageBlockButtons >
     <apex:commandButton action="{!selectProducts}" value="Select"/>
     <apex:commandButton action="{!cancelSelection}" value="Cancel"/>
    </apex:pageBlockButtons>       
    <apex:pageBlockTable value="{!pricebookEntries}" var="pricebookEntry" >       
     <apex:column >    
      <apex:facet name="header"></apex:facet>                 
           <apex:inputCheckbox value="{!pricebookEntry.pbeIsSelected}"/> 
          </apex:column>
        <apex:column >
           <apex:facet name="header">{!$ObjectType.Product2.fields.name.label}</apex:facet>  
           <a href="/{!pricebookEntry.pbeProduct2Id}">       
            {!pricebookEntry.pbeName}
           </a>           
         </apex:column>
         <apex:column >
           <apex:facet name="header">{!$ObjectType.pricebookEntry.fields.ProductCode.label}</apex:facet>          
           <apex:outputText value="{!pricebookEntry.pbeProductCode}"/>           
         </apex:column>
         <apex:column >
           <apex:facet name="header">{!$ObjectType.pricebookEntry.fields.UnitPrice.label}</apex:facet>          
           <apex:outputText value="{!pricebookEntry.pbeUnitPrice}"/>           
         </apex:column>
         <apex:column >
           <apex:facet name="header">{!$ObjectType.Product2.fields.Description.label}</apex:facet>          
           <apex:outputText value="{!pricebookEntry.pbeProductDescription}"/>           
         </apex:column>               
      </apex:pageBlockTable>           
     </apex:pageblock> 
    </apex:outputPanel>      
 </apex:form>  

 and thid controller getter and setter:

Code:
 //-----------------------------------------
 //OverrideAddProduct Page
 //Accessor Methods for <apex:pageBlockTable value="{!pricebookEntries}" var="pricebookEntry" > control
    
    public List<PricebookEntryUIElement> getPricebookEntries() 
    {   
     List<PricebookEntryUIElement> pricebookEntryUIElements = new List<PricebookEntryUIElement>();
       
        List<PricebookEntry> pricebookEntries = [Select Id, IsActive, Name, Pricebook2Id, Product2Id, 
Product2.Description, Product2.Family, ProductCode, UnitPrice
from PricebookEntry where IsActive = true and Product2.Family = :productFamily]; for(PricebookEntry pricebookEntry: pricebookEntries){ PricebookEntryUIElement pricebookEntryUIElement = new PricebookEntryUIElement(); pricebookEntryUIElement.setPbeIsSelected(false); pricebookEntryUIElement.setPbeId(pricebookEntry.Id); pricebookEntryUIElement.setPbeName(pricebookEntry.Name); pricebookEntryUIElement.setPbePricebook2Id(pricebookEntry.Pricebook2Id); pricebookEntryUIElement.setPbeProduct2Id(pricebookEntry.Product2Id); pricebookEntryUIElement.setPbeProductDescription(pricebookEntry.Product2.Description); pricebookEntryUIElement.setPbeProductFamily(pricebookEntry.Product2.Family); pricebookEntryUIElement.setPbeProductCode(pricebookEntry.ProductCode); pricebookEntryUIElement.setPbeUnitPrice(pricebookEntry.UnitPrice); pricebookEntryUIElements.add(pricebookEntryUIElement); } return pricebookEntryUIElements; } public void setPricebookEntries(List<PricebookEntryUIElement> pricebookEntryUIElements) { System.debug('setPricebookEntries visited'); this.selectedPricebookEntries = new List<PricebookEntryUIElement>(); for(PricebookEntryUIElement pricebookEntryUIElement:pricebookEntryUIElements){ if(pricebookEntryUIElement.getPbeIsSelected()){ this.selectedPricebookEntries.add(pricebookEntryUIElement); } } }

 




Message Edited by azzani on 07-08-2008 01:52 AM

Message Edited by azzani on 07-08-2008 01:55 AM
aballardaballard

For repeated constructs like datatable, you need a getter to obtain the list that is iterated over, as you have done. 

But VF does not call a setter providing a list of all elements when the page is submitted.   Instead it will call the individual setters for the elements being iterated over. 

i.e., pbeIsSelected will be called for each priceBookEntry with the value from the corresponding row.

aalazzaniaalazzani
Thanks aballard for your reply.

So can you please suggest which changes I need to make for my specific requirement (know which products were selected). I tried setting the ID of the checkbox to be the PricebookEntry Id, but the id cannot be of expression value. Do you suggest using different VF component?

Aref