You need to sign in to do that
Don't have an account?
iKnowSFDC
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
Change the line
public Integer amount{get; set;}
to
public Integer amount{get; }
and try.. Hope this will work
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.
Hey JoAnn,
Did you solve this problem?
/Mats
Have not yet solved it. Any ideas?
JoAnn