+ Start a Discussion
iKnowSFDCiKnowSFDC 

Input text field in Wrapper Class not setting value to record created

I have a wrapper class that creates a line item record on a parent record. The VF page lists the available items to add with an input text field that sets a integer with the quantity ordered.  The method is creating the record as expected, but the quantity is not being set properly. I'm not seeing what I'm missing in the process to properly set the quantity in the child record. Any suggestions? 

 

public class materialOrderWrapperClassController{

    public List<cProducvod> productList {get; set;}
    public Material_Order__c record;
    public List<Product_vod__c> availableProducts= new List<Product_vod__c>();
    public List<Material_Order_line_Item__c> linesToAdd {get;set;}
    public List<Material_Order_line_Item__c> qtysToUpdate {get;set;}
    public List<cProducvod> selectedProducts{get;set;}
    public Boolean hasProdSelect{get;set;}
    public Integer qty {get;set;}   
    
    public materialOrderWrapperClassController(ApexPages.StandardController stdController){
        record = [SELECT id, Name, Date__c, Status__c, Notes__c
                    FROM Material_Order__c 
                    WHERE id =:ApexPages.currentPage().getParameters().get('id')];
        
        selectedProducts = new List<cProducvod>();
        
       
        availableProducts = [SELECT id, Name, Image__c, Product_Type_vod__c 
                                FROM Product_vod__c 
                                WHERE Product_type_vod__c = 'Order'
                                ORDER BY Name ASC];
            //productList = new List<cProducvod>();
            if(productList == null){
              productList = new List<cProducvod>();                                        
              for(Product_vod__c p : availableProducts) {
                productList.add(new cProducvod(p));
            }
        }                                
    }
    

    public List<cProducvod> getProductList() {
         return productList;
    }
        
     public void setQty(Integer q){
         qty=q;
         }
         
     public Integer getQty(){
         return qty;
         }
         
     public pageReference processSelected(){
         selectedProducts.clear();
          hasProdSelect = false;
            for(cProducvod cProd: getProductList()) {
                if(cProd.qty > 0) {
                    selectedProducts.add(cProd);
                    system.debug('cProd qty is >>>>'+cProd.qty);
                    }
              }
        
        linesToAdd = new List<Material_Order_Line_Item__c>();
         for(cProducvod prdct : selectedProducts){
            Material_Order_line_Item__c newLine = new Material_Order_line_Item__c();
            newLine.Products__c = prdct.cProductvod.id;
            system.debug('newLine product name is>>>'+newLine.Products__c);
            newLine.Quantity__c = qty;
            system.debug('newLine qty is >>>'+newLine.Quantity__c);
            newLine.Material_Order__c = record.id;
            linesToAdd.add(newLine);
         }
         insert linesToAdd;
         
         pageReference enterAmount = new pageReference('/'+record.id);
          //pageReference enterAmount = new pageReference('/apex/enterAmt?id='+record.id);
          return enterAmount; 
         }
}

 VF Code: 

<apex:page standardController="Material_Order__c" extensions="materialOrderWrapperClassController">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton value="Process Selected" action="{!processSelected}"/>
            </apex:pageBlockButtons>
            <apex:pageBlockTable value="{!productList}" var="c" id="table">
                <apex:column >
                    <apex:inputText value="{!c.qty}"/>
                </apex:column>
            <apex:column value="{!c.cProductvod.Name}" headerValue="Product"/>
            <apex:column value="{!c.cProductvod.Image__c}" headerValue="Image"/>   
            <apex:column value="{!c.cProductvod.id}"/> 
        </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

Best Answer chosen by Admin (Salesforce Developers) 
Scott_VSScott_VS

Oh wait, 

 

<apex:inputText value="{!c.qty}"/>

 

And c is...

 

<apex:pageBlockTable value="{!productList}" var="c" id="table">

And productList is...

 

public List<cProducvod> productList {get; set;}

 

So you are not pulling the qty field that you define in 

 

public Integer qty {get;set;}   

You're pulling some qty field you have defined in the cProducvod class.

All Answers

Scott_VSScott_VS

You don't need your getQty and setQty functions. That's already taken care of in your {get;set;} in the line:

 

public Integer qty {get;set;}

 That might be what's causing the problem.

iKnowSFDCiKnowSFDC

I removed them and no change in the results.  

Scott_VSScott_VS

Oh wait, 

 

<apex:inputText value="{!c.qty}"/>

 

And c is...

 

<apex:pageBlockTable value="{!productList}" var="c" id="table">

And productList is...

 

public List<cProducvod> productList {get; set;}

 

So you are not pulling the qty field that you define in 

 

public Integer qty {get;set;}   

You're pulling some qty field you have defined in the cProducvod class.

This was selected as the best answer
iKnowSFDCiKnowSFDC

Oh good Grief - I feel so dumb!  Once I referenced the right controller it worked beautifully.  Thanks for pointing that out!

 

JoAnn

SFDC LearnerSFDC Learner
Dint understand the solution...