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
fredkafredka 

Using updated value from SelectList

I have a select list where the user selects a number from 1 to 10:
<apex:outputText >New Laser Count?  </apex:outputText>
                                                    <apex:selectList label="new Count?" value="{!newLaserCount}" size="1" >
                                                    <apex:selectOptions value="{!newLaserCounts}" />
                                                    </apex:selectList>

I then want to loop through, using that number to create the same number of new records for the user to popualate.  Here is the part of the code where I am using the 'newLaserCount':

    Integer LaserCount = integer.valueOf(newLaserCount);  

         for (Integer i = 0; i < LaserCount; i++) {
            SLLNewList.add(new Laser__c());
        } 

If I hardcode the LaserCount field it gives me the correct number.. however, this does not work.  The default value of teh seleclist is 1.. it always creates one record recardless of the value populated in the selectlist.

I've done this before without issue but for some reason, this is just not getting updated.  Any help would be greatly appreciated!!!

​Fred
Apoorv Saxena 4Apoorv Saxena 4
Hi Fred,

Could you please post your controller code, so that I may be able to help you to resolve this issue.

Thanks,
Apoorv
fredkafredka
Thanks Apoorv! The entire controller is pretty big but here are hte pieces that apply.

the button calls this function:
public PageReference NewSLL() {
    UpdateSLLSList(); 
    Integer LaserCount = integer.valueOf(newLaserCount);
        newSLL = true;      
        return null;
    }

There is a pageblocktable that has the following: <apex:pageBlockTable width="100%" value="{!SLLNewList}" var="laser" rowClasses="">

There is a method called  to update the list..  The problem is that the varialble newLaserCount) is not getting updated when it is changed on the page.

public void UpdateSLLSList() {
            // Create a list of the related Stop Loss Laser Summaries 
            // to show onthe SL Lasers tab.
        SLLSList = new List<SLLSCheckbox>();
        SLLSPickListSelect = new List<SelectOption>();
        SLLSPickListSelect.add(new SelectOption('', '-- No Value Selected --'));
       
        newSLLS = false;
        newSLL = false;
       
        for (Laser_Summary__c ls : [
            select ID, Name, Account__c, Lasers_Apply_To__c,
                Start_Date__c, End_Date__c, Laser_Summary_Name_Copy__c,
                (select Id, First_Name__c, Last_Name__c, Gender__c,
                    DOB__c, SSN__c, Relationship_Code__c, Attachment_Point_Amount__c, Laser_Type__c
                 from Lasers__r)
            from Laser_Summary__c
                where Account__c = : a.id
                and Start_Date__c >= : startRenewalDate
                and Start_Date__c < : activeGroup.masterUwi.End_Date__c
                and End_date__c >= :startRenewalDate              
            order by Start_Date__c]) {
            SLLSList.add(new SLLSCheckbox(ls));
            SLLSPickListSelect.add(new SelectOption(ls.Id, ls.Name));
        }
       
        if (SLLSList.size() == 0) {
            SLLSList = null;
            SLLSPickListSelect = new List<SelectOption>();
            SLLSPickListSelect.add(new SelectOption('', '-- No Lasered Summary Records Exist --'));
        }
        else {
            selectedSLLS = SLLSList[0].laserSummary.id;
        }
       
            // Refresh the list of new laser records
        SLLNewList = new List<Laser__c>();
       
            // Set the number of cloned records to create
            // for each original record that is cloned
        Integer LaserCount = integer.valueOf(newLaserCount);
         for (Integer i = 0; i < LaserCount; i++) {
            SLLNewList.add(new Laser__c());
        }
        
      
    }   
 
Apoorv Saxena 4Apoorv Saxena 4
Ok, so is 'newLaserCount' a {get;set;} property?
Have you tried debugging its value on button click?
fredkafredka
Hi.. you are correct.. When I created the values for the list I also default the value to a 1.. the value never changes from 1.  Only one record gets created. Also, I am not sure how to debug it.. thanks!!!
Apoorv Saxena 4Apoorv Saxena 4
Ok, first make sure you have declared 'newLaserCount' as an autoproperty ie. you should declare it as :

public String newLaserCount{get;set;}

Now setup your debug logs from Setup.

Next, you can add debug statement in you method that gets called on button click, like this:
 
public PageReference NewSLL() {
    system.debug('@@@---'+newLaserCount);
    UpdateSLLSList();  
    Integer LaserCount = integer.valueOf(newLaserCount);
        newSLL = true;       
        return null;
    }


And then check your debug log that what value you are getting for 'newLaserCount' in controller when your method is called.

Hope this helps!
fredkafredka
I was able to debug the variable and the value is 1 as expected.  So I'm at the same place.. I have no idea how to get that select list to show the correct value when it is changed?  thanks!
Apoorv Saxena 4Apoorv Saxena 4
Hmm, there must be something that you're missing. It would be really great if you could post your controller code, so that I might be able to help you out.