0

I am trying to update an Apex:repeat section with new values returned from the controller.

I have a JS remote call connected to a to refine my search qry This works and returns fine.

However i cannot Rerender or update the list to pass new values down to the component.

The JS Remote gets values from other parts of the page Via Jquery

Any help would be welcome

VF

     <div class="refine_search-btn">
      <button type="button" class="btn btn-refine" onclick="refineSearch()" ><i><img src="{!URLFOR($Resource.WebImages,'search.png')}"/></i>Refine search</button>
    </div>

    <apex:form id="form">

        <div class="adv_dealslist svr_model" id="theDealRepeater">
        <apex:actionFunction name="reRenderDeals" rerender="theRepeat" />

          <apex:repeat value="{!AllDer}" var="deal" id="theRepeat">
                <div class="replaceTarget">
                    <c:dealListCmp DealObject="{!deal}" />
                </div>
          </apex:repeat>
        </div>
    </apex:form>


function refineSearch(){

            console.log('Firing');

            var selectedBodyTypes = new Array();

            // Get BodyType
            $("input:checkbox[type=checkbox]:checked").each(function(){
                selectedBodyTypes.push($(this).attr('title'));
            });

            console.log(selectedBodyTypes[0]);
            // Get Trim Level Selected
            var trimSelected = $("#trimLevel option:selected").text();
            //get GearBox Selected
            var gearBoxSelected = $("#gearBox option:selected").text();

            //get FuelSelected
            var FuelSelected = $("#FuelType option:selected").text();

            // Remote action call to controller
            Visualforce.remoting.Manager.invokeAction(
                '{!$RemoteAction.searchModelController.testRemoteCall}',
                selectedBodyTypes,trimSelected,gearBoxSelected,FuelSelected,
                function(result, event){
                    if(event.status){
                        //alert(result);

                    console.log(result);

                    $("#NumberOfDeals").text(result.length + " Deals Found");


                    reRenderDeals();



                    } else if(event.type ==='exception'){
                        alert("We had a boo boo " + event.message);
                    } else {
                        alert("something odd happened " + event.message); 
                    }
                },
                {escape:true}
            );

Controller

public List<public_tblderivative_base__x> AllDer = new List<public_tblderivative_base__x>();



    @RemoteAction
    public static List<public_tblderivative_base__x> testRemoteCall(List<String> bodytypes, String Trim, String gearBox, String Fuel){
        System.debug('Value 1 ' + bodytypes);
        System.debug('Value 2 ' + Trim);
        System.debug('Value 3 ' + gearBox);
        System.debug('Value 4 ' + Fuel);


        List<public_tblderivative_base__x> theResult = getAllModels(manufactorCode, rangeCode, bodytypes, Trim, gearBox, Fuel);
        new searchModelController().setAllDer(theResult);
        return theResult;
    }

public List<public_tblderivative_base__x> getAllDer(){
        // Limit this to 10 for now.

        List<public_tblderivative_base__x> theReturn = new List<public_tblderivative_base__x>();
        Integer count = 5;
        //System.debug('Getting Deals ' + getAllDer());

        if(AllDer.size() < 5){
            count = AllDer.size();
        }
        for(Integer i = 0; i < count; i++) {
            System.debug('In for loop');
            theReturn.add(AllDer[i]);
        }

        return theReturn;
    }
0

Found the Answer:

VisualForce needed changing so that the actionFunction took params, As well as a action call to a new method within the controller

<apex:actionFunction action="{!actionCallToResetList}" name="reRenderDeals" reRender="reRenderThis">
        <apex:param id="Trim" name="Trim" value="" />
    </apex:actionFunction>

Also the Repeat needed a wrapper of a outputPanel.

This then aloud the JS call to take a param taken from the Jquery call earler.

reRenderDeals(trimSelected);

In the controller the new method then needed to get the param from the current page and reset the List that will be returned.

public void actionCallToResetList(){
Apexpages.currentPage().getParameters().get('bodytypes');
        string Trim = Apexpages.currentPage().getParameters().get('Trim');
        System.debug('*Value 2 ' + Trim); 

         AllDer = getAllModels(manufactorCode, rangeCode, null, Trim, null, null);
    }

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.