You need to sign in to do that
Don't have an account?
CTIT Siding
visualforce/apex issue with checkbox
Hi All,
I am having an issue with a checkbox that I added to a VF page and the corresponding Apex controller. No matter if I check the checkbox or not, the controller is getting null passed back to it as the value instead of true/false.
Here is the VF page: (The lines that I added are marked with "// SN 403714")
and here is the controller:
Thanks,
Steve A.
I am having an issue with a checkbox that I added to a VF page and the corresponding Apex controller. No matter if I check the checkbox or not, the controller is getting null passed back to it as the value instead of true/false.
Here is the VF page: (The lines that I added are marked with "// SN 403714")
<apex:component controller="VSD_Inc_New_CompetitionReportController"> <!-- SN 403714 Steve Arnold 12/9/2016 --> <!-- Don't use default headings for existing incentives --> <!-- --> <!-- SN 403714 Steve Arnold 1/13/2017 --> <!-- Add delete checkbox to detail lines --> <style> .cellHeader { color: #59a13f; font-family: "HelveticaNeueLTStdRoman"; } .resultTable td { vertical-align:middle; padding: .5em 1em .5em 1em; } .styledInput{ min-width: 175px; } </style> <div id="incentive_container"> <table class="filterTable filterTableHeader"> <tr> <th>Received By <span class="required-indicator">*</span></th> <th>Provided By <span class="required-indicator">*</span></th> <th>Received Date <span class="required-indicator">*</span></th> </tr> <tr id="filter_row"> <td><input id="f_receivedBy" type="text" class="styledInput" /> </td> <td><input id="f_progvidedBy" type="text" class="styledInput" /> </td> <td> <div class="data-subcell"> <input id="rec_date" type="date" class="styledInput futureDateInput" html-data-field="date" /> </div> </td> </tr> </table> </div> <div id="incentive_table_container"> <table class="resultTable"> <thead> <tr> <!-- <th>Product</th> --> <th>Competitive Brand</th> <th>Competitive Product</th> <th>Invoice Price</th> <th>Discount %</th> <th>Delete</th> // SN 403714 1/13/2017 </tr> </thead> <tbody id="competitiveReportTable"> </tbody> </table> </div> <div class="footer" align="right"> <div id="VSD:setRequestInfo:VSD_SetRequestHeaderInfo:requestDetailForm:j_id616" onclick="VSD_Inc_New_CompetitiveReport.setIncentives();" class="button greenButton" style="margin-top: 10px;"> <span class="buttonText">Next : Set Incentives</span> <span class="icon-white-arrow-right"></span> </div> </div> <script> var VSD_Inc_New_CompetitiveReport = new Object(); if((VSD_Inc_NewCustomer_Store.currentIncentive == null || VSD_Inc_NewCustomer_Store.currentIncentive =='') && VSD_Inc_Store.isNew_Save){ // SN 403714 12/9/2016 VSD_Inc_Store.setHeaderTitle(VSD_Inc_Store.CONSTANTS.PAGENAME.NEWINCENTIVE_VIEW.header); VSD_Inc_Store.setSubHeaderTitle(VSD_Inc_Store.CONSTANTS.PAGENAME.NEWINCENTIVE_VIEW.subHeader_competitive_report); } VSD_Inc_Store.clearHeaderButtons(); if(VSD_Inc_Store.isNew_Save) VSD_Inc_Store.setHeaderButtonHTML_Blue_Right('Cancel', '_CancelCompetitive_Btn'); j$(function() { VSD_Inc_New_CompetitiveReport.fetchCompetitiveInfoData(); VSD_Inc_Store.setDatePicker(); VSD_Inc_Store.current_PageName = _currentPageName; }); VSD_Inc_New_CompetitiveReport.fetchCompetitiveInfoData = function() { VSD_Inc_Store.showLoader(); Visualforce.remoting.Manager.invokeAction( '{!$RemoteAction.VSD_Inc_New_CompetitionReportController.fetchCompetitiveInfo}', VSD_Inc_Store.currentIncentive, function(result, event) { if (event.status) { VSD_Inc_New_CompetitiveReport.createCompetitiveInfoTable(JSON.parse(result)); } else { VSD_Inc_Store.showRemoteActionError(event); } VSD_Inc_Store.hideLoader(); }, { escape: false } ); } VSD_Inc_New_CompetitiveReport.createCompetitiveInfoTable = function(_competitiveData) { j$('#f_receivedBy').val(_competitiveData.receivedBy); j$('#f_progvidedBy').val(_competitiveData.providedBy); j$('#rec_date').val(VSD_Inc_Store.setPickerDate(_competitiveData.receivedDate)); var tableBody = j$("#incentive_table_container table tbody"); tableBody.empty(); var tableRow; var competitiveBrandlist = ''; competitiveBrandlist += '<option>Select a Brand</option>'; j$.each(_competitiveData.competitiveBrandPicklist, function(index, value) { competitiveBrandlist += '<option value="'+value.Id+'">'+value.Name+'</option>'; }); var listSize = 0; j$.each(_competitiveData.competitiveInfo, function(index, value) { ++listSize; tableRow = j$("<tr class=\"competitionReportInfo\"></tr>"); var temp = ''; tableRow.append("<input id=\"f_id\" value='" + value.id + "' type=\"hidden\" class=\"styledInput hiddenId\" />"); temp = value.competitiveProduct !=null ? value.competitiveProduct : '' tableRow.append("<td class=\"competitiveRepoData\"><div style=\"white-space: nowrap;\"><select id='comp_" + index + "' value='" + value.competitiveBrand + "' class=\"competBrand\">" + competitiveBrandlist + "</select><span id='Span_Comp_" + index + "' class=\"required-indicator\" style=\"vertical-align: middle;\">*</span> </div></td>"); tableRow.append("<td class=\"competitiveRepoData\"><div style=\"white-space: nowrap;\"><input id=\"f_compProduct\" value='" + temp + "' type=\"text\" class=\"styledInput product\" /><span id='Span_Prod_" + index + "' class=\"required-indicator\" style=\"vertical-align: middle;\">*</span> </div></td> "); temp = value.invoicePrice !=null ? value.invoicePrice : '' tableRow.append("<td class=\"competitiveRepoData\"><div style=\"white-space: nowrap;\"><span class=\"cellHeader\">$</span><input id=\"f_invoice\" value='" + temp + "' type=\"text\" class=\"styledInput invoice\" /> <span id='Span_Inv_" + index + "' class=\"required-indicator\" style=\"vertical-align: middle;\">*</span> </div></td> "); temp = value.discountPercent !=null ? value.discountPercent : '' tableRow.append("<td class=\"competitiveRepoData\" ><div style=\"white-space: nowrap;\"><input id=\"f_discount\" value='" + temp + "' type=\"text\" class=\"styledInput discount\" /> <span id='Span_Disc_" + index + "' class=\"required-indicator\" style=\"vertical-align: middle;\">*</span> </div></td> "); temp = value.deleteLine !=null ? value.deleteLine : "false" // SN 403714 tableRow.append("<td class=\"competitiveRepoData\" ><div style=\"white-space: nowrap;\"vertical-align: middle;\"><input id=\"f_delete\" value=" + temp + " type=\"checkbox\" /></div></td> "); // SN 403714 tableBody.append(tableRow); j$("#comp_"+index).val(value.competitiveBrand); if(index != 0){ j$("#Span_Comp_"+index).removeClass('required-indicator'); j$("#Span_Comp_"+index).html(''); j$("#Span_Inv_"+index).removeClass('required-indicator'); j$("#Span_Inv_"+index).html(''); j$("#Span_Prod_"+index).removeClass('required-indicator'); j$("#Span_Prod_"+index).html(''); j$("#Span_Disc_"+index).removeClass('required-indicator'); j$("#Span_Disc_"+index).html(''); } }); var initVar; for ( initVar = listSize; initVar < 6; initVar++) { tableRow = j$("<tr class=\"competitionReportInfo\"></tr>"); tableRow.append("<td class=\"competitiveRepoData\"><div style=\"white-space: nowrap;\"><select id=\"f_compBrand\" class=\"competBrand\">" + competitiveBrandlist + "</select><span id='Span_Comp_N" + initVar + "' class=\"required-indicator\" style=\"vertical-align: middle;\">*</span></div></td>"); tableRow.append("<td class=\"competitiveRepoData\"><div style=\"white-space: nowrap;\"><input id=\"f_compProduct\" type=\"text\" class=\"styledInput product\" /><span id='Span_Prod_N" + initVar + "' class=\"required-indicator\" style=\"vertical-align: middle;\">*</span></div></td>"); tableRow.append("<td class=\"competitiveRepoData\"><div style=\"white-space: nowrap;\"><span class=\"cellHeader\">$</span><input id=\"f_invoice\" type=\"text\" class=\"styledInput invoice\" /><span id='Span_Inv_N" + initVar + "' class=\"required-indicator\" style=\"vertical-align: middle;\">*</span></div></td>"); tableRow.append("<td class=\"competitiveRepoData\" ><div style=\"white-space: nowrap;\"><input id=\"f_discount\" type=\"text\" class=\"styledInput discount\" /><span id='Span_Disc_N" + initVar + "' class=\"required-indicator\" style=\"vertical-align: middle;\">*</span></div></td>"); tableBody.append(tableRow); if(initVar != 0){ j$("#Span_Comp_N"+initVar).removeClass('required-indicator'); j$("#Span_Comp_N"+initVar).html(''); j$("#Span_Inv_N"+initVar).removeClass('required-indicator'); j$("#Span_Inv_N"+initVar).html(''); j$("#Span_Prod_N"+initVar).removeClass('required-indicator'); j$("#Span_Prod_N"+initVar).html(''); j$("#Span_Disc_N"+initVar).removeClass('required-indicator'); j$("#Span_Disc_N"+initVar).html(''); } } } VSD_Inc_New_CompetitiveReport.getIncentiveProdList = function(){ //TODO : retrieve updated incentive products } VSD_Inc_New_CompetitiveReport.isPageValid = 'true'; VSD_Inc_New_CompetitiveReport.validatePage = function( CompetitionReportDataList ) { var recordCounter = 0 ; j$.each(CompetitionReportDataList, function(index, value) { //VSD_Inc_New_CompetitiveReport.isPageValid = 'false'; if(recordCounter < 1){ ++recordCounter; if(value.competitiveBrand == 'Select a Brand'){ alert('Please fill all required fields'); VSD_Inc_New_CompetitiveReport.isPageValid = 'false'; return false; }else{ VSD_Inc_New_CompetitiveReport.isPageValid = 'true'; } if(value.competitiveProduct == ''){ alert('Please fill all required fields'); VSD_Inc_New_CompetitiveReport.isPageValid = 'false'; return false; }else{ VSD_Inc_New_CompetitiveReport.isPageValid = 'true'; } if(value.invoicePrice == '' && value.discountPercent == ''){ alert('Please fill all required fields'); VSD_Inc_New_CompetitiveReport.isPageValid = 'false'; return false; } else{ VSD_Inc_New_CompetitiveReport.isPageValid = 'true'; } }else{ //return true; } }); } VSD_Inc_New_CompetitiveReport.validateCurrentIncentive = function(_currentIncentive){ if(_currentIncentive.providedBy == '' || _currentIncentive.receivedDate == ''){ alert('Please fill all required fields'); VSD_Inc_New_CompetitiveReport.isPageValid = 'false'; }else{ VSD_Inc_New_CompetitiveReport.isPageValid = 'true' } } VSD_Inc_New_CompetitiveReport.setIncentives = function() { var incentiveProductString = {}; var currentIncentiveInfo = {}; VSD_Inc_New_CompetitiveReport.CompetitionReportDataList = []; VSD_Inc_New_CompetitiveReport.currentIncentive = {}; VSD_Inc_New_CompetitiveReport.currentIncentive.receivedBy = j$("#f_receivedBy").val(); VSD_Inc_New_CompetitiveReport.currentIncentive.providedBy = j$("#f_progvidedBy").val(); VSD_Inc_New_CompetitiveReport.currentIncentive.receivedDate = VSD_Inc_Store.getPickerDate(j$("#rec_date").val()); this.validateCurrentIncentive(VSD_Inc_New_CompetitiveReport.currentIncentive); if(VSD_Inc_New_CompetitiveReport.isPageValid == 'false') return false; var recordCounter = 0; j$( "tr.competitionReportInfo" ).each(function(index,value){ var isValidRow = true; var CompetitionReportData = {}; CompetitionReportData.competitiveBrand = j$(this).find("select.competBrand").val(); CompetitionReportData.competitiveProduct = j$(this).find("input.styledInput.product").val(); CompetitionReportData.invoicePrice = j$(this).find("input.styledInput.invoice").val(); CompetitionReportData.deleteLine = j$(this).find("input.delete").val(); // SN 403714 if (CompetitionReportData.invoicePrice!=null){ CompetitionReportData.invoicePrice = cleanCurrencyValue(CompetitionReportData.invoicePrice); } CompetitionReportData.discountPercent = j$(this).find("input.styledInput.discount").val(); CompetitionReportData.id = j$(this).find("input.styledInput.hiddenId").val(); if(CompetitionReportData.competitiveProduct == ''){ isValidRow = false; } if(CompetitionReportData.invoicePrice == '' && CompetitionReportData.discountPercent == ''){ isValidRow = false; } if(CompetitionReportData.competitiveBrand == 'Select a Brand'){ isValidRow = false; } if(isValidRow){ VSD_Inc_New_CompetitiveReport.CompetitionReportDataList.push(CompetitionReportData); } }); if( this.CompetitionReportDataList.length < 1 ){ VSD_Inc_New_CompetitiveReport.isPageValid = 'false'; alert('Please fill all required fields'); }else{ VSD_Inc_New_CompetitiveReport.validatePage( this.CompetitionReportDataList ); } currentIncentiveInfo = JSON.stringify(VSD_Inc_New_CompetitiveReport.currentIncentive); incentiveProductString = JSON.stringify(VSD_Inc_New_CompetitiveReport.CompetitionReportDataList); if(VSD_Inc_New_CompetitiveReport.isPageValid != 'false'){ Visualforce.remoting.Manager.invokeAction( '{!$RemoteAction.VSD_Inc_New_CompetitionReportController.setIncentiveProducts}', incentiveProductString, VSD_Inc_Store.currentIncentive, currentIncentiveInfo, function(result, event) { if (event.status) { loadView(VSD_Inc_Store.CONSTANTS.ROUTER.NEW_INCENTIVE_SET_INCENTIVE); //TODO: Redirect to Set Incentives Screen } else { VSD_Inc_Store.showRemoteActionError(event); } VSD_Inc_Store.hideLoader(); }, { escape: false } ); } } j$(function() { j$('#startCancelRequestDialog').dialog({ autoOpen: false, width: "auto", height: "auto", modal: true }); }); j$("#_CancelCompetitive_Btn").click(function() { VSD_Inc_Store.cancelAction(); }); </script> </apex:component>
and here is the controller:
/* * Controller for VF Component : VSD_Inc_New_CompetitionReportView * - store remote actions to provide data for the interface. * * @author Deepak */ // // SN 403714 Steve Arnold 12/19/2016 // - Allow deletion of competitive data // - Fix pre-fill of Received By Field // public with sharing class VSD_Inc_New_CompetitionReportController { //Get a JSON of list of incentive data wrapper // //@return // String : JSON of structure Incentive Product @RemoteAction public static String fetchCompetitiveInfo(String incentiveId) { CompetitionReportInfo competitiveinfo = new CompetitionReportInfo(); // get incentive products to display in Competitive info section /* String queryString = ' SELECT Competitive_Brand__c,Competitive_Discount_Percent__c,Competitive_Invoice_Price__c,Competitive_Product__c,Id,Incentive__c,Name '+ ' FROM Incentive_Product__c WHERE Id = :currentIncentiveId '; for(Incentive_Product__c incetiveprod : Database.query(queryString)){ CompetitionReportData competitiveData = new CompetitionReportData(); if(competitiveinfo.competitiveInfo == null) competitiveinfo.competitiveInfo = new List<CompetitionReportData>(); competitiveData.product = incetiveprod.Name; competitiveinfo.competitiveInfo.add(competitiveData); } */ // get received by default value | Current User's -> 'FirstName' + 'LastName' User usr = [SELECT FirstName, LastName FROM User WHERE Id = :UserInfo.getUserId()]; competitiveinfo.receivedBy = (usr.FirstName != null ? usr.FirstName : '')+' '+(usr.LastName != null ? usr.LastName : '') ; Incentive__c incentive; if(incentiveId != null){ incentive = [SELECT Competitive_Info_Received_By__c, Competitive_Info_Provided_By__c, Competitive_Info_Date_Received__c FROM Incentive__c WHERE Id = :incentiveId]; } competitiveinfo.providedBy = incentive.Competitive_Info_Provided_By__c; competitiveinfo.receivedBy = incentive.Competitive_Info_Received_By__c; // SN 403714 if( incentive.Competitive_Info_Date_Received__c != null){ competitiveinfo.receivedDate = String.valueOf(incentive.Competitive_Info_Date_Received__c); }else{ competitiveinfo.receivedDate = String.valueOf(date.today()); } // fetch list of competitive brand values from Competitive_Brand__c Object for(Competitive_Brand__c compbrand : [SELECT Id, Name FROM Competitive_Brand__c WHERE VSD_Process__c includes ('Incentive') ]){ if(competitiveinfo.competitiveBrandPicklist == null) competitiveinfo.competitiveBrandPicklist = new List<Competitive_Brand__c>(); competitiveinfo.competitiveBrandPicklist.add(compbrand); } // fetch list of Incentive Competitive Info values from Incentive_Competitive_Info__c Object CompetitionReportData reportData; for(Incentive_Competitive_Info__c incCompInfo : [SELECT Id, Name, Incentive__c, Competitive_Brand__c, Competitive_Product__c, Competitive_Discount_Percent__c, Competitive_Invoice_Price__c ,DeleteLine__c // SN 403714 FROM Incentive_Competitive_Info__c WHERE Incentive__c = :incentiveId]){ if(competitiveinfo.competitiveInfo == null) competitiveinfo.competitiveInfo = new List<CompetitionReportData>(); //Competitive_Brand__c brand = [SELECT Name FROM Competitive_Brand__c WHERE Id =: incCompInfo.Competitive_Brand__c ]; reportData = new CompetitionReportData(incCompInfo); //reportData.competitiveBrand = brand.Name; competitiveinfo.competitiveInfo.add(reportData); } return JSON.serialize(competitiveinfo); } // Creates set of Incentive Competitive Info records // //@param // String : JSON of structure Incentives competitive report @RemoteAction public static void setIncentiveProducts(String competitiveInfoJsonString, String incentiveId, String currentIncentiveData){ Incentive__c incentive; if(incentiveId != null){ incentive = [SELECT Competitive_Info_Received_By__c, Competitive_Info_Provided_By__c, Competitive_Info_Date_Received__c FROM Incentive__c WHERE Id = :incentiveId]; } List<Incentive_Competitive_Info__c> competitiveInfo = new List<Incentive_Competitive_Info__c>(); List<Incentive_Competitive_Info__c> DelCompetitiveInfo = new List<Incentive_Competitive_Info__c>(); // SN 403714 List<VSD_Inc_New_CompetitionReportController.CompetitionReportData> compReportDataList = (List<VSD_Inc_New_CompetitionReportController.CompetitionReportData>)JSON.deserializeStrict(competitiveInfoJsonString, List<VSD_Inc_New_CompetitionReportController.CompetitionReportData>.class); VSD_Inc_New_CompetitionReportController.CompetitionReportInfo incentiveData = (VSD_Inc_New_CompetitionReportController.CompetitionReportInfo)JSON.deserializeStrict(currentIncentiveData, VSD_Inc_New_CompetitionReportController.CompetitionReportInfo.class); incentive.Competitive_Info_Received_By__c = incentiveData.receivedBy; incentive.Competitive_Info_Provided_By__c = incentiveData.providedBy; if(String.isNotBlank(incentiveData.receivedDate)) incentive.Competitive_Info_Date_Received__c = Date.valueOf(incentiveData.receivedDate + ' ' + '00:00:00'); for(VSD_Inc_New_CompetitionReportController.CompetitionReportData compData : compReportDataList){ Incentive_Competitive_Info__c incentiveInfo = new Incentive_Competitive_Info__c(); incentiveInfo.Incentive__c = String.valueOf(incentiveId); incentiveInfo.Competitive_Brand__c = compData.competitiveBrand; incentiveInfo.Competitive_Product__c = compData.competitiveProduct; if(String.isNotBlank(compData.invoicePrice)) incentiveInfo.Competitive_Invoice_Price__c = Decimal.valueOf(compData.invoicePrice); incentiveInfo.Competitive_Discount_Percent__c = compData.discountPercent; incentiveInfo.DeleteLine__c = compData.deleteLine; // SN 403714 incentiveInfo.Id = compData.id; system.debug('********************************************** compData.DeleteLine = ' + compData.DeleteLine); system.debug('********************************************** incentiveInfo.DeleteLine__c = ' + incentiveInfo.DeleteLine__c); if(IncentiveInfo.DeleteLine__c == true) // SN 403714 DelCompetitiveInfo.add(incentiveInfo); // SN 403714 else // SN 403714 CompetitiveInfo.add(incentiveInfo); } // SN 403714 //>>> system.debug('********************************************** DelCompetitiveInfo = ' + DelCompetitiveInfo); //>>> system.debug('********************************************** CompetitiveInfo = ' + CompetitiveInfo); try{ upsert competitiveInfo; delete DelCompetitiveInfo; // SN 403714 update incentive; }catch(Exception e){ System.debug('Caught DML exception on Incentive Competititve Info / Incentive object'); } } public class CompetitionReportInfo { public String receivedBy; public String providedBy; public String receivedDate; public List<Competitive_Brand__c> competitiveBrandPicklist; public List<CompetitionReportData> competitiveInfo; } public class CompetitionReportData { public CompetitionReportData(Incentive_Competitive_Info__c info){ competitiveBrand = info.Competitive_Brand__c; competitiveProduct = info.Competitive_Product__c; invoicePrice = String.valueOf(info.Competitive_Invoice_Price__c); discountPercent = info.Competitive_Discount_Percent__c; deleteLine = info.DeleteLine__c; // SN 403714 id = info.Id; } //public String product; public String id; public String competitiveBrand; public String competitiveProduct; public String invoicePrice; public String discountPercent; public Boolean deleteLine; // SN 403714 } }Can anybody help me?
Thanks,
Steve A.
But you can set the .change() function on a checkbox, this will trigger anytime you check or uncheck it. In the .change(), you could do your call to the remote function in your apex controller and pass this.checked as a parameter. This.checked inside the checkbox.change() function will be 'true' or 'false'.
Thanks for the quick response. Can you show an example of how to do this? I'm kinda new at this so I don't really understand what you're saying to do.
Steve