Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Salesforce by (11.9k points)

This is an extension of a question I asked on the Salesforce developer boards that didn't get much play:

I have a VisualForce page that requires frequent changes to load new information from the controller and embed that information into a Javascript array for further use.

Curent solution: rI've had success using VisualForce 'Browser Technologies' as described here (in the Wiki): http://wiki.developerforce.com/index.php/Using_Browser_Technologies_in_Visualforce_-_Part_1

I surround the Javascript array.push with the recommended tags:

<apex:repeat value="{!Object}" var="objects">       

    d.push( {

               element1: "{!objects.id}"            

    })

</apex:repeat>

Issue: The array is correctly populated when an entire page refresh populates, and when I use my 'dropdown' to modify the filter on the object (in the controller), the DOM Is updated (I Can see new information being placed on the page),

Ultimately, however, the Javascript array doesn't change it's values unless I call a refresh on the entire page, which sort of defeats the Partial Refresh and is kind of shock to the system for users.

This 'necessary post' issue wasn't a problem before, and even when I directly call the Javascript function that contains this array population after the DOM has been updated the Javascript array doesn't change (So I'm assuming that it's loaded once based on what's at the DOM when the page initially posts back and can't be changed.

Thoughts?

1 Answer

0 votes
by (32.1k points)

If you need to control when your array gets refreshed, you can go ahead and wrap it in an output panel and put its ID in the attribute of whatever causes the data the need to update it. 

<apex:commandButton action="{!something}" rerender="scriptPanel"/>

<apex:outputPanel id="scriptPanel>

  <script>

     d = new Array();

     <apex:repeat value="{!objects}" var="object">

       d.push({

           element1: "{!objects.id}"            

       });

     </apex:repeat>

  </script>

</apex:outputPanel>

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...