0

I have a below apex function call

<apex:actionFunction name="searchContinueAvailableSlotJS" action="{!searchnextSevenSlots}" status="searchOpenSlots" onComplete="Appointment.onContinuationComplete()" rerender="confirmMsgPanel,nextSevenDaysId"/>

On Above call I rerender the components with id nextsevendays. Now this component has a apex:repeat which has a Map in it and that map gets updated on every apex function call. and I recurrsively calling the apex function 4 times like below from a javascript function

function1 () {
if(counter < 4){
searchContinueAvailableSlotJS();
}
}

Now this creates duplicate values on the UI as below. After first call say Map has value1 After second call map has value1 , value 2 so on UI it displays duplicate values Value 1 Value 1 Value 2 Value 1 Value 2 Value 3 ..... and so on. Can someone suggest a way to overcome this problem.Thanks

1

I think for each counter you are adding values in the map. Here I am thinking it is not simple as Value 1, Value 2....kind of simple values, rather it may have list of values.

So, let's say you are passing values in lstString, for each iteration it may be specific set of values (e.g. Value 1 on first iteration, Value 2 in 2nd iteration.

//first call
List<String> lstString = new List<String>();
lstString.add('Value 1');

//hold value values in the map
Map<String, List<String>> myMap = new Map<String, List<String>>();

//loop through list of values before putting into map, let's say you want to put 'Value 1' in the map
for(String outerStr:lstString)
{
    for(String str:myMap.keySet())  //compare with the key
    {
        List<String> lstInternalString = myMap.get(str); //get list of values already exist in the map
        String str2 = String.join(lstInternalString,','); //create a string with comma delimited way.
        if(!str2.contains(outerStr))                    //check 'Value 1' exists in the map.
        {
            //add value to the map
            myMap.put(str, lstInternalString.add(outerStr));
        }
    }
}
  • I am putting unique values and map has unique values I checked it. But since apex action function is re rendering the section it duplicates the values while displaying. – user5129806 Jul 17 '17 at 16:00
  • I have given a direction how to handle it, since you didn't share your full code, thats why I have assumed and written this code. – Santanu Boral Jul 17 '17 at 16:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.