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 retrieve an array List of String inside a dataTable and also its index?

Hi, I have a input text box and a button 'Add' beside the text box. As soon as I enter anything in the textbox and click on Add it should get displayed as a list below the textbox. First time I enter a value only 1 value will appear below the text box, second time I enter 2 values will appear and so on.

Logic: I have used an Array List of String and as soon as I click on 'Add' button, the add the value in the textbox to the arraylist and in my page I iterate through the List to display the values in the table. I also have a checkbox next to the value in the table. I am not being able to get any of the values. Neither the checkbox nor any entered value is visible in the table. Also how do I get to know which checkbox gets selected once I have them in the table. Here is the piece of code
Code:
<apex:page controller="Wizard_Step4c_Controller">
<apex:form >
    <apex:pageBlock title="Section 1">
        <p> Is the EDC Rate adjustable— </p>
        <p> <apex:commandButton action="{!showSection2}" value="Yes" styleClass="btn"></apex:commandButton>
        <apex:commandButton action="{!nextPage}" value="No" styleClass="btn"></apex:commandButton></p>
    </apex:pageBlock>
    <apex:pageBlock title="Section 2" rendered="{!showSecondSection}">
        <p>Enter criteria for EDC rate adjustment : </p>
        <p><apex:inputTextArea style="height:50px;width:200px;overflow-y:scroll" id="rateCriteria"></apex:inputTextArea> </p><br/>
        <p>Enter effective date(s) for EDC rate adjustment :
        <apex:inputText id="effectDates"></apex:inputText><span style="padding:10px;"/>
         <apex:commandButton action="{!addDates}" value="Add" styleClass="btn"></apex:commandButton></p> 
         <apex:dataTable value="{!dates}" var="effDate" width="50%" rows="5" rendered="true">
               <apex:column>
                  <apex:inputCheckbox id="checkb"></apex:inputCheckbox>
            </apex:column>
            <apex:column>
              {!effDate}
            </apex:column>
          </apex:dataTable>
        <p><apex:commandButton action="{!nextPage}" value="Continue" styleClass="btn"></apex:commandButton></p>
    </apex:pageBlock>
 </apex:form>
</apex:page>

public class Wizard_Step4c_Controller 
{
    Boolean secondSection = false;
    CONTRACT_TERMS__c contract_terms= null;
    Boolean showSection = false;
    List<String> dates = new List<String>();

    public Boolean getShowSecondSection() {
        return this.secondSection ;
    }
    
    public void setSecondSection(Boolean secondSection)
    {
            this.secondSection= secondSection;
    }


    public PageReference nextPage() 
    {
        if(getShowSecondSection() == true)
        {
            
                update contract_terms;
           
        }
        PageReference pr= Page.Wizard_Step4d;
        pr.getParameters().put('contractTermsId', System.currentPageReference().getParameters().get('contractTermsId'));
        pr.getParameters().put('contractId', System.currentPageReference().getParameters().get('contractId'));
        pr.getParameters().put('questNum', System.currentPageReference().getParameters().get('questNum'));
        pr.setredirect(true);
        return pr;
    }


    public PageReference showSection2() {
        setSecondSection(true);
        return null;
    }
    
    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 List<String> getDates()
    {
    
        return this.dates;
    }
    
    public void setShowTable(Boolean showSection)
    {
        this.showSection = showSection;
    }
    
     public Boolean getShowTable()
    {
        return this.showSection;
    }
}
 
Can anyone please help me resolve this issue?

Thanks, Jina
Ron HessRon Hess
For this line


i think you need value="{!effDates}" so:



then in your controller, provide a getter and setter for this getEffDates(), setEffDates()


for the checkbox, rather than return a list of string to iterate over, include the checkbox in a list, then iterate over that.

so:
List dates = new List();

would be
class dateandcheckbox { string date;boolean checkb;
//... getter and setter here...
}
list dates = new list();


you will have to construct and add to this list, but then you will have the checkbox value for each item in the list.
Jina ChetiaJina Chetia
Thanks Ron. I got a work around for this problem, it is working fine in developer org but when I am trying to do the same in sandbox I m getting a prolblem.

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:
 <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;
      }
   
   
    }

 

Ron HessRon Hess

Code:
<apex:commandLink action="{!removeTermDates}" value="Remove" rendered="{!listSize}" rerender="rows"></apex:commandLink>

 You may need the rerender specified



Message Edited by Ron Hess on 05-29-2008 12:42 PM