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
Sviatlana AndryianchykSviatlana Andryianchyk 

Controller method is not called second time

Hi, I am calling controller function on command button click.

This is button:
<apex:commandButton value="Add" onClick="addItemToCard('{!$Component.bVAL}', '{!item.Id}'); return false;"/>
 
<apex:actionFunction name="addToCardFunction" action="{!addToCard}" reRender="items"> 
    <apex:param name="count" value="" assignTo="{!itemCount}"/> 
    <apex:param name="id" value="" assignTo="{!itemId}"/> 
</apex:actionFunction>

I call controller function in js:
function addItemToCard(itemCountId, id) { 
    addToCardFunction(document.getElementById(itemCountId).value, id); 
}

I don't know why, but my addToCard() controller method is called only in the first time . When I click button second time, nothing happens. Page is just reloaded :(
 
Lokesh KumarLokesh Kumar
Hi,

Make sure Your Controller method should be like below pseudo code.
 
public PageReference methodOne() {
        return null;
    }

Thanks
Lokesh
Sviatlana AndryianchykSviatlana Andryianchyk
Yes. It looks like this:
public PageReference addToCard(){
        System.debug('addToCard');
        return null;
    }

 
Vivian Charlie 1208Vivian Charlie 1208

Hi Sviatlana,

 

Can you try few things

1. Remove the return false; element from the onClick event

2. In case your apex:form / outer apex:outputpanel has an id try rerendering it in the actionfunction

<apex:actionFunction name="addToCardFunction" action="{!addToCard}" reRender="items,formID OR PanelId">

 

Thanks

Vivian