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
anna425912anna425912 

inputCheckbox not propogating to controller from PageBlockTable

I have a search page that returns a list in a PageBlockTable using a wrapper class.  It has an inputCheckbox and a number input.  Once selected the user clicks a commandButton to decide what to do with the checked rows.  However, not all of the checked rows are being returned and the changed quantities are also not being returned for all the rows. If I select rows without selecting the top one, then it doesn't register that any have been chosen.  The odd thing is that it is working perfectly in one of my sandboxes, but once I moved it to another (same exact code, I swear), it's no longer working. So I decided to try another sandbox and it seems to behave differently there as well.  I've been banging my head against a wall about this for a few days so I appreciate any help!! Thanks!

Here are portiosn of the code which are causing me issues: 

part of the visualforce with pageblocktable:
<apex:pageBlock mode="detail" id="results">
    <div style="width: 100%; overflow:hidden;">
        <div style="align:center;">
            <table>
                <tr>
                    <td>
                        <apex:commandButton action="{!additemSelections}" value="Add Selected items" style="width:150px" status="loading"/>
                        <div class="divider"/>
                        <apex:commandButton action="{!goToOpp}" value="Return to Opportunity" style="width:150px"/>
                    </td>
                </tr>
            </table>
        </div>
    </div>                                        
    <div style="width: 100%; overflow:hidden;">                                       
        <p style="font-size:20px; color:#585858">
        <apex:actionStatus id="loading" startText="Loading..." />
        </p>
    </div>
    <apex:pageBlockTable value="{!finalzlist}" var="z" id="itemtable">
        <apex:column width="55px" id="column2">
            <apex:facet name="header">
                <apex:commandLink value="{!selectTitle}" rerender="results,debug" id="selectAll" action="{!selectAll}" status="loading"/>
            </apex:facet>
        <!-- Input checkbox that is not always working -->
            <apex:inputCheckbox id="cbid" value="{!z.cb}" disabled="{!z.disabled}" onchange="checkValidation({!z.idx},{!z.Inventory_Available1},{!z.name1})"/>
        </apex:column>                                                     
        <apex:column >
            <apex:facet name="header">
                Quantity
            </apex:facet>
            <div id="{!z.name1}div" style="color:red; font-weight:bold"></div>
        <!-- Input number that is not always working -->
            <apex:input type="number" value="{!z.quantity}" id="quanId" onchange="validation({!z.idx},{!z.Inventory_Available1},{!z.name1});" disabled="{!z.disabled}" />
        </apex:column>                                           
    </apex:pageBlockTable>
</apex:pageBlock>
Javascript that runs onchange:
<script type="text/javascript">
        function validation(index,avail,item) {
            var divid = item + 'div';
            var newid = 'j_id0:f:results:itemtable:'+index+':quanId';
            var quan = document.getElementById(newid).value;
            if(quan > avail) {
                var errormessage = 'Quantity must be '+avail+' or less. item will not be added to cart.';
                document.getElementById(divid).innerHTML = errormessage;
                document.getElementById(newid).style.color = "red";
            } else {
                document.getElementById(divid).innerHTML = "";
                document.getElementById(newid).style.color = "black";
            }
        }
        function checkValidation(index,avail,item) {
            var checkboxId = 'j_id0:f:results:itemtable:'+index+':cbid';
            var checked = document.getElementById(checkboxId).checked;
            if(checked) {
                var quanId = 'j_id0:f:results:itemtable:'+index+':quanId';
                quan = document.getElementById(quanId).value;
                var divid = item + 'div';
                if(quan == 0) {
                    var errormessage = 'Please enter a quantity greater than 0. item will not be added to cart.';
                    document.getElementById(divid).innerHTML = errormessage;
                    document.getElementById(quanId).style.color = "red";
                } 
            } else {
                validation(index,avail,item);
            }
        }
    </script>

Controller: 
 
public with sharing class itemSearchController{

    public String oppId{
        get { return System.currentPageReference().getParameters().get('oppId'); }
        set;
    }
    public List<Inventory_Object__c> newitems {get;set;}
    public List<Inventory_Object__c> itemCodes {get;set;}
    public String soql {get;set;}
    public Integer removeitemIDX {get; set;}
    public Decimal totalInventory {get; set;}
    public Decimal totalInventoryActive {get; set;}
    public Decimal totalSelectedQuantity {get; set;}
    public Map<String,Id> zMap { get; set; }
    public String selectTitle {get; set;}
    public List<item_Code_Selection__c> newZCSList {get; set;}
    public Boolean isSubmitting {get; set;}
    public List<itemCodeClass> finalzlist {get; set;}
    public List<itemToAdd> itemsToAdd {get; set;}
    public Decimal totalConfirmPrice {get; set;}
    public Integer totalConfirmQuantity {get; set;}

    public class itemCodeClass {
        public String name1 {get; set;}
        public String msa1 {get; set;}
        public String city1 {get; set;}
        public String state1 {get; set;}
        public String id1 {get; set;}
        public Decimal Inventory_Available1 {get; set;}
        public Boolean cb {get; set;}
        public Boolean disabled {get; set;}
        public Integer quantity {get; set;}
        public Decimal Inventory_Active1 {get; set;}
        public Decimal List_Price1 {get; set;}
        public Integer idx {get; set;}
        public itemCodeClass(String name1, String msa1, String city1, String state1, String id1, Decimal Inventory_Available1, Boolean cb, Boolean disabled, Integer quantity, Decimal Inventory_Active1, Decimal List_Price1, Integer idx) {
            this.name1 = name1;
            this.msa1 = msa1;
            this.city1 = city1;
            this.state1 = state1;
            this.id1 = id1;
            this.Inventory_Available1 = Inventory_Available1;
            this.cb = cb;
            this.disabled = disabled;
            this.quantity = quantity;
            this.Inventory_Active1 = Inventory_Active1;
            this.List_Price1 = List_Price1;
            this.idx = idx;
        }
    }
    public itemSearchController() {
        selectTitle = 'Select All';
        totalSelectedQuantity = 0;
        isSubmitting = false;
        if(oppId == null) {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'In order to add items, please access this page through the Opportunity.'));
        }
    }

    public PageReference additemSelections() {
        Map<Id,itemCodeClass> itemM2 = new Map<Id,itemCodeClass>();
        if(finalzlist != null ) {
            for(itemCodeClass z :finalzlist) {
                if(z.cb == true && z.quantity > 0 && z.quantity <= z.Inventory_Available1) {
                    itemM2.put(z.Id1,z);
                } else if (z.cb == true && z.quantity == 0) {
                    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please make sure all selected items have a quantity greater than 0.'));
                    return null;
                }
            }
            List<item_Code_Selection__c> zcslist = new List<item_Code_Selection__c>();
            List<itemToAdd> zs = new List<itemToAdd>();
            if(itemM2.size() == 0 ) {
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please select at least 1 item code with a quantity less than or equal to the availability.'));
                return null;
            } else {
                isSubmitting = true;
                Inventory_Object__c[] zca = [SELECT Id FROM Inventory_Object__c WHERE Id in :itemM2.keyset()];
                RecordType rna = [SELECT Id, Name FROM RecordType WHERE sObjectType = 'item_Code_Selection__c' and Name = 'New - Inventory'];
                Decimal tcp = 0.0;
                Integer tcq = 0;
                for(Inventory_Object__c za :zca ) {
                    itemCodeClass zcc = itemM2.get(za.Id);
                    item_Code_Selection__c z = new item_Code_Selection__c(Opportunity__c=oppId,Inventory_Object__c=za.Id,RecordTypeId=rna.Id,Discount__c=0.0,Quantity__c=zcc.quantity);
                    Decimal tp = zcc.quantity*zcc.List_Price1;
                    tcp = tcp + tp;
                    tcq = tcq + zcc.quantity;
                    zs.add(new itemToAdd(zcc.name1,zcc.quantity,zcc.List_Price1,tp)); 
                    zcslist.add(z);                
                }
                itemsToAdd = zs;
                totalConfirmQuantity = tcq;
                totalConfirmPrice = tcp;
            }
            if(zcslist.size() > 0 ) {
                newZCSList = zcslist;            
            } 
            return null; 
        } else {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error,'Please search for and select at least 1 item code.'));
            return null;
        }

    }

}




 
Andy BoettcherAndy Boettcher
Either I'm just not seeing it - or where are you actually populating "finalzlist"?  I see the get/set, but I don't see where you populate it?
anna425912anna425912
I didn't include all of the controller. There's a search portion that queries a custom object and then creates the instances of the wrapper class. 
​finalzlist.add(new itemCodeClass(z.name,z.msa__c,z.city__c,z.state__c,z.id,z.Inventory_Available__c,false,disabled,quan,z.Inventory_Active__c,z.List_Price__c,index));