You need to sign in to do that
Don't have an account?

How to send a checkbox value from a table to a controller to delete the record?
Hi,
I have a Text Box, where I enter Date and as soon as I click on Add it gets added to the list and displays below. Now when I am trying to remove the date from the list I am unable to do it. I have used a wrapper class to set the value of the checkbox.
Here is the code - Term_Dates__c is my custom Object having a lookup relationship with Contract_Term__c and I have created a wrapper for Term_Dates__c custom object. As soon as I click on Add, I create a new Term_Dates__c and it gets added to the list but when I am tring to remove it, it is not happening. It is working in my develoiper org but not in sandbox.
I have only pasted a part of the code that is applicable -
Please help...
I have a Text Box, where I enter Date and as soon as I click on Add it gets added to the list and displays below. Now when I am trying to remove the date from the list I am unable to do it. I have used a wrapper class to set the value of the checkbox.
Here is the code - Term_Dates__c is my custom Object having a lookup relationship with Contract_Term__c and I have created a wrapper for Term_Dates__c custom object. As soon as I click on Add, I create a new Term_Dates__c and it gets added to the list but when I am tring to remove it, it is not happening. It is working in my develoiper org but not in sandbox.
I have only pasted a part of the code that is applicable -
Code:
Code: <apex:pageBlock title="Section 4" rendered="{!showFourthSection}"> <p>Select Payment Frequency: <span style="padding:2px;"/> <apex:inputText id="payFreq"/></p> <p>Total # of Payments: <span style="padding:2px;"/><apex:inputText ></apex:inputText> </p> <p>Payment Dates: <span style="padding:2px;"/> <apex:inputField id="term" value="{!termDates.Date__c}"/> <span style="padding:10px;"/><apex:CommandButton action="{!addTermDates}" value="Add"></apex:CommandButton></p> <apex:pageBlockTable value="{!allTermDates}" var="a" id="rows" title="Details of Effective Date" > <apex:column ><apex:inputCheckbox value="{!a.sendToExternalService}"></apex:inputCheckbox></apex:column> <apex:column ><apex:inputField value="{!a.TermDates.Date__c}"/></apex:column> </apex:pageBlockTable> <apex:commandLink action="{!removeTermDates}" value="Remove" rendered="{!listSize}"></apex:commandLink> <p><span style="padding:20px;"/>Are the Hi ROC rate thresholds and/or reduction/increases adjustable— </p> <p><span style="padding:30px;"/><apex:commandButton action="{!showSection5}" value="Yes, Continue" styleClass="btn"></apex:commandButton> <span style="padding:2px;"/><apex:commandButton action="{!nextPage}" value="No, Continue" styleClass="btn"></apex:commandButton></p> </apex:pageBlock> public class Wizard_Step6_Controller { CONTRACT_TERMS__c contract_terms; Term_Dates__c termDate = null; List<TermDatesWrapper> listOfTermDatesWrapper; List<TermDatesWrapper> selectedTermDatesWrapper = new List<TermDatesWrapper>(); public Term_Dates__c getTermDates() { termDate = new Term_Dates__c(); return termDate; } public PageReference addTermDates() { termDate.TERM_ID__c = getContractTerms().Id; termDate.Date_Type__c = 'Payment'; insert termDate; System.currentPageReference().getParameters().put('term', ''); return null; } public Boolean getListSize() { Boolean termSize= false; if(getAllTermDates().size()>0) { termSize = true; } return termSize; } public List<TermDatesWrapper> getAllTermDates() { listOfTermDatesWrapper = new List<TermDatesWrapper>(); Term_Dates__c[] allTermDates = [select id, Date__c from Term_Dates__c where TERM_ID__c =:contract_terms.Id]; for(Term_Dates__c l : allTermDates) { TermDatesWrapper wrapper= new TermDatesWrapper(l); listOfTermDatesWrapper.add(wrapper); } return listOfTermDatesWrapper; } public List<TermDatesWrapper> getAllSelectedTermDatesWrappers() { return selectedTermDatesWrapper; } public PageReference removeTermDates() { for(TermDatesWrapper lw : listOfTermDatesWrapper) { if(lw.getSendToExternalService()) { selectedTermDatesWrapper.add(lw); delete lw.getTermDates(); } } return null; } } public class TermDatesWrapper { private final Term_Dates__c delegate; private boolean sendToExternalService = false; public TermDatesWrapper (Term_Dates__c delegate) { this.delegate = delegate; } public Term_Dates__c getTermDates() { return delegate; } public void setSendToExternalService(boolean sendToExternalService) { this.sendToExternalService = sendToExternalService; } public boolean getSendToExternalService() { return sendToExternalService; } }
I had experienced this problem before, your getAlltermDates() method should return an Array , rather a list,
should work :)
Message Edited by Feng on 06-02-2008 01:57 PM