+ Start a Discussion
Luke Vang 52Luke Vang 52 

Controller loading after javascript is called in reRender of apex component.


Here's the situation, I am trying to dynamically show some custom apex components. I have an parent outputpanel with some nested outputpanel children. The outputpanel gets reRendered from an action function the the nested outpanels get rendered depending on some value. Everything looks good and is working, but each apex component has a visualforce remoting function which is supposed to be called when the component loads. When the component loads, the js remoting function tries to fire but it says the controller can't be found. It looks like the remoting function is trying to fire before the actual controller loads. If I look in the debug logs, the constructor for the controller is being called.

Apex Page:
<apex:form >
    	<apex:actionFunction name="setName" action="{!onChangeName}" reRender="containerPanel">
    		<apex:param name="name" assignTo="{!name}" value="" />

<apex:outputPanel id="containerPanel" >
                             <apex:outputPanel rendered="{!name == 'Bob'}">
                             <c:Component1 a_name="{!chartName}"  />
                              <apex:outputPanel rendered="{!name == 'Barb}">
                              	  <c:Component2 name="{!name}"/>
        const j$ = jQuery.noConflict();
        j$(document).ready(function() {
//call action function

<apex:component controller="Controller">

<apex:attribute name="name" type="String" description="name" assignTo="{!name}" />

<div id="{!name}" class="container"></div>


var name = {!name}
//call remoting function when component is loaded
                                                  function(result, event) {
                                                      if (event.status) {
//do something


Controller not found for: 
Unable to invoke action .....  no controller and/or function found
Luke Vang 52Luke Vang 52
Sorry I always wanted to add.... adding a javascript timer function before the remoting function is called makes the remoting function work. So there looks to be some sort of delay of when the remote function fires and the controller being loaded in the component.