What is apex:commandButton with apex:actionSupport?

233    Asked by ClareMatthews in Salesforce , Asked on Jun 5, 2023

So I'm currently working off the example for apex:actionSupport given in the VF dev docs. All is fine with the example. I am now looking to have a button click initiate the refresh of the counter variable. I changed the VF page to the following:

         
When I hit the command button I'm seeing that the counter variable increments and displays for a couple ms but then gets reverted back. I believe this might have something to do with order of getters/setters interacting with the AJAX refresh? I could be wrong, but I'm looking for an explanation of why this behaviour occurs ( as I'm assuming this is working as designed).

Answered by Diane Carr

When using it actually submits the page. You could see the HTML button actually type is submit.

Refer documentation

A button that is rendered as an HTML input element with the type attribute set to submit, reset, or image, depending on the tag's specified values. The button executes an action defined by a controller, and then either refreshes the current page, or navigates to a different page based on the PageReference variable that is returned by the action.

That's the reason, it is submitting the page and re-initiating the counter
Workable code will be (without actionSupport):
Here with the use of action you can submit the page and increment the counter and use the rerender attribute to refresh the counter.

Otherwise putting action="{!incrementCounter}" in commandbutton will keep the incrementCounter but it makes no sense to use actionSupport with the commandButton in this scenario.


Your Answer

Interviews

Parent Categories