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
Jina ChetiaJina Chetia 

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 -
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;
      }
   
   
    }
Please help...
Ron HessRon Hess
when the behavior is different in sandbox and developer org, is the difference in the data, or is it in the visualforce page re-render that is not happening?
FengFeng

I had experienced this problem before, your getAlltermDates() method should return an Array , rather a list,

should work :) 

Jina ChetiaJina Chetia
Shall I just change the List to Array? Actually the problem is with setting the checkbox value not with rerendering. The sendToExternalService attribute in the Wrapper class is not getting set in the sandbox but working in developer. I sit something to do with usage of page:BlockTable as in developer org I using page:BlockList and sandbox says apex:BlockList is deprecated.
Jina ChetiaJina Chetia
Changing to Array doesn't work. Here is the piece of controller with Array and nothing gets added to the array

Code:
public class Wizard_Step4c_Controller 
{
    CONTRACT_TERMS__c contract_terms= null;
   
     Term_Dates__c termDate = null;
      TermDatesWrapper[] listOfTermDatesWrapper;
       TermDatesWrapper[]  selectedTermDatesWrapper = new TermDatesWrapper[10];
 
    public CONTRACT_TERMS__c getContractTerms()
    {
        Id contractTermsId= System.currentPageReference().getParameters().get('contractTermsId');
        if(contractTermsId != null)
        {
            contract_terms = [select id,ADJ_RT_CRITERIA__c from CONTRACT_TERMS__c where id=:contractTermsId];
        }
        return contract_terms;
    }
    
    public pageReference addDates()
    {
        String newDate = System.currentPageReference().getParameters().get('effectDates');
        setShowTable(true);
        dates.add(newDate);
        return null;
    
    }
      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 TermDatesWrapper[] getAllTermDates()
        {
            Contract_Terms__c contTerm = getContractTerms();
            listOfTermDatesWrapper = new TermDatesWrapper[10];
            Term_Dates__c[] allTermDates = [select id, Date__c from Term_Dates__c where TERM_ID__c =:contTerm .Id and Date_Type__c = 'Payment'];
            for(Term_Dates__c l : allTermDates)
            {
                TermDatesWrapper wrapper= new TermDatesWrapper(l);
                listOfTermDatesWrapper.add(wrapper);
            }
            return listOfTermDatesWrapper;
        }
        
      
        
        public TermDatesWrapper[] getAllSelectedTermDatesWrappers()
        
        {
            return selectedTermDatesWrapper;
        }
        
         
        public PageReference removeTermDates()
        {
            for(TermDatesWrapper lw : getAllTermDates())
            {
               if(lw!= null)
               {
                if(lw.getSendToExternalService())
                {
                    selectedTermDatesWrapper.add(lw);
                    delete lw.getTermDates();
                }
                }
            }
        
            return null;
        }
 }

 

Jina ChetiaJina Chetia
In removeTermDates() method, when I call getAllTermDates() it returns me null. Even if use the listOfTermDatesWrapper attribute, it gives me null. Why is it not returning any value from teh Array whereas the same Array is used for the display of the dates and it is working. I am really confused with the behaviour.What can be the issue?
FengFeng
Cheers


Message Edited by Feng on 06-02-2008 01:57 PM