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

Javascript does not execute after rerender

I have a javascript function (using Protovis) that draws a dynamic pie chart in my Visualforce page. The pie chart is contained within an outputPanel, and a button at the top of the page rerenders that outputPanel. The javascript works perfectly the first time the page is loaded. However, after the button is pressed and the section rerenders, the javascript never executes a second time -- the pie chart disappears and the alert on line 16 does not fire. How can I make sure my function executes after the rerender event?



<apex:page controller="devTracking" > <script type="text/javascript" src="{!URLFOR($Resource.Protovis, 'protovis-r3.1.js')}"></script> <apex:form > <apex:commandButton id="goButton" value="Go" action="{!start}" rerender="container"></apex:commandButton> </apex:form> <apex:outputPanel id="container"> <apex:pageBlock title="Sample Protovis Graph"> <script type="text/javascript+protovis"> function renderMe() { alert('debug #1'); var data = pv.range(10).map(Math.random).sort(pv.reverseOrder), w = 400, h = 400, r = w / 2, a = pv.Scale.linear(0, pv.sum(data)).range(0, 2 * Math.PI); var vis = new pv.Panel() .width(w) .height(h); vis.add(pv.Wedge) .data(data) .bottom(w / 2) .left(w / 2) .outerRadius(r) .angle(a) .title(function(d) d) .add(pv.Wedge) // invisible wedge to offset label .visible(function(d) d > .15) .innerRadius(2 * r / 3) .outerRadius(r) .fillStyle(null) .anchor("center").add(pv.Label) .textAngle(0) .text(function(d) d.toFixed(2)); vis.render(); } renderMe(); </script> </apex:pageBlock> </apex:outputPanel> </apex:page>





I'd use an actionStatus to execute the Javascript once the rerendering is complete.





<apex:actionStatus id="renderMeStatus" onstop="renderMe()"/> <apex:commandButton id="goButton" value="Go" action="{!start}" rerender="container" status="renderMeStatus">




Gino BassoGino Basso

Might this have something to do with the javascript parsing that occurs when you add +protovis to the type attribute?


I believe this parsing only occurs onload. In other words, when you rerender, you might be getting the original, unparsed javascript.


This is just a guess though.