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
iKnowSFDCiKnowSFDC 

Having trouble with Setter Methods

I have a page that is giving the user the option to add line items to a catalog order. I'm able to display the catalog items, my debug code is showing that the setter is getting the integer entered into the input field, but either no line items get added or all items are added, not just the ones that have a value entered in the field.  I'm not seeing the issue and am hoping that the community sees something I"m missing. 

 

Here is my controller: 

public with sharing class selectableProduct {

    public Material_Order__c record;
    public Integer amount{get; set;}
    public Product_vod__c prod{get;set;}
    public List<Product_vod__c> productList=new List<Product_vod__c>();
    public List<Material_Order_Line_Item__c> linesToAdd=new List<Material_Order_Line_Item__c>();

    //set current material order in focus
    public selectableProduct(ApexPages.StandardController stdController){
        record = [SELECT id, Name, Date__c, Status__c, Notes__c
                    FROM Material_Order__c 
                    WHERE id =:ApexPages.currentPage().getParameters().get('id')];

    }
    
    //get list of available products to order
    public List<Product_vod__c> getProductList(){
        productList = [SELECT id, Name, Image__c FROM Product_vod__c WHERE Product_Type_vod__c = 'Order' ORDER BY Name ASC];
        return productList;
    }
    
    public Integer getAmount(){
        return amount;
      }
   public void setAmount(Integer a){
       this.amount = a;
       }
    
    //set amounts of selected items and insert line items on material order
    public pageReference placeOrder(){
    
        pageReference orderQtys = new PageReference('/'+record.id);
 
        for(Product_vod__c ps : productList){

            Material_Order_Line_Item__c newLine = new Material_Order_Line_Item__c();
          
           if((amount != NULL) || (amount != 0)){
            newLine.Products__c = ps.id;
            newLine.Quantity__c = amount;
            newLine.Material_Order__c = record.id;

            linesToAdd.add(newLine);
            }
        }
        insert linesToAdd;
        return orderQtys;
    }
    
}

 

And here is the VF Code: 

<apex:page standardController="Material_Order__c" extensions="selectableProduct">
<apex:form >
<apex:pageBlock title="Products">
  <apex:pageBlockButtons >
    <apex:commandButton action="{!placeOrder}" value="Submit"/>
  </apex:pageBlockButtons>
<apex:pageBlockSection title="Available Line Items" columns="1">
  <apex:dataTable value="{!productList}"  var="prod" width="95%" cellpadding="5">
    <apex:column width="10%" headerValue="Amount">
      <apex:facet name="header"/>
      <apex:inputText value="{!amount}"/>
    </apex:column>
    <apex:column width="20%">
      <apex:facet name="header">Product</apex:facet>
      <apex:outputText value="{!prod.Name}"/>
    </apex:column>
    <apex:column width="70%">
      <apex:facet name="header">Image</apex:facet>
      <apex:outputField value="{!prod.Image__c}"/>
    </apex:column>
  </apex:dataTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

 

Thanks for your help in advance!

JoAnn

priyanka.mv26priyanka.mv26

Change the line

 

public Integer amount{get; set;}

 

to 

 

public Integer amount{get; }

 

and try.. Hope this will work

iKnowSFDCiKnowSFDC

No, that doesn't work as if I don't have the setter method it won't accept any input in the VF page and just reloads the page instead of taking the user back to the Material Order page.  

Mats ErikssonMats Eriksson

Hey JoAnn,

 

Did you solve this problem?

 

/Mats

iKnowSFDCiKnowSFDC

Have not yet solved it.  Any ideas?  

 

JoAnn

dmchengdmcheng

First: amount is confusing to me since that means "dollar amount" to me.  Better to use "qty".

 

Second: qty is not in your  product object, so even though are you are displaying on the same line, when you loop through the product list, you can't get qty, and it has no relationship to the product list.

 

You need to make a wrapper class that includes the product record and the qty field so that they are associated.  you display the wrapper class fields on the vf page, then loop through the wrapper class results, extract the product info, and do your calcs / updates on product object.