1

I have an VisualForce page set up like this:

<apex:actionPoller interval="5" reRender="panel" action="{!getPanelRecords}"/>

<apex:outputPanel id="panel">
    <button onClick = "btnClick(this,'blue');" value="Change me blue"/>
    <button onClick = "btnClick(this,'red');" value="Change me red"/>
</apex:outputPanel>

<script>
    function btnClick(element, color) {
        this.attr('color', color);
    }
</script>

When I click the button, it will change color, But due to the panel getting rerendered, it will not persist between refreshes.

I was thinking of using the actionPoller onComplete event to get a list of id's and set the colors accordingly, but I'm not sure if there's an easier/better way to achieve this.

1
  • 1
    Maybe have a property in controller which binds with the buttons. – Raul Oct 26 '16 at 11:35
0

To solve this I used the actionPoller's onSubmit and onComplete attributes.

In the onSubmit I stored each buttons state and a Id into a global array (outside the scope of the output panel getting reRendered).

In the onComplete I read the Id's, found the buttons in the reRendered panel that matched the Id, and then set their state to the previous state.

The only problem with this approach is there is a tiny flicker just after refresh, and it's probably not the most efficient.

If anybody has any ideas on how to call a function after an ajax complete event and before load, I'd appreciate your thoughts.

1
  • hey did you ever work around the undesired flicker? – Peter Noges Mar 7 '19 at 2:17

Your Answer

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