+ Start a Discussion
JamesSSJamesSS 

Nested Components issue in VF page



I have used Multiple components in VF page.

M4 Component code have overlapped in M1 component.

I have passed one variable to M4 component.

But this passed variable is showing in Page. But this value always showing as "null" in M4 Component controller constructor.
Please help to get this passed value in M4 Component controller.

My Main page code :

<apex:page sidebar="false" showHeader="false">
    <c:M1 ></c:M1>
</apex:page>


M1 Component Code:
_________________

<apex:component controller="retriveSetCon" >
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"></meta>

    <c:M2 ></c:M2>                       
                                             
    <body  style="margin-top: 1%;background-color:white" >
        <div class = "modal1">  
            <p style="position: fixed; padding-top: 25%;font-weight: bold;color: black;padding-left: 46%;font-size: 19px;" id="msgBlock"><b> Processing...</b></p>
        </div>                
        <div class="container-fluid">         
                
                    <div class="tab-content">
                    
                            <div>
                                <!-- some code -->
                                <c:M4 myValue1="AccountObject"></c:M4>
                           </div>
                       
                    </div>
        </div>

        <div>
            <c:M5 ></c:M5>
        </div>

    </body>
 
</apex:component>



M4 Component Code :
_______________________

<apex:component controller="TestComponentController">

  <apex:attribute name="myValue1" description="This is the value for the component." required = "true" type="String"  assignTo="{!myValue}"/>
  <div class="container">

  <apex:outputText value="{!myValue}" style="color:red" />
  
  <apex:dataTable value="{!taskList}" var="t">
 
    <apex:column >

        <apex:facet name="header">Name</apex:facet>

            <apex:outputText value="{!t.Name}"/>

        </apex:column>
  </apex:dataTable>
 
</div>
</apex:component>

global without sharing class TestComponentController{
    
    public String myValue{get;set;}


    public TestComponentController(){
     System.debug('myValue:::::::'+myValue);
       
    }
}


SForceBeWithYouSForceBeWithYou
In a VF component, the "setters" that make a variable passed in actually save (or assignTo) doesn't happen until AFTER the constructor has ran.
 
global without sharing class TestComponentController{
    
    public String myValue{
      get;
      set{
          System.debug('value:::::::'+value); // Passed in value
          this.myValue = value; // Make sure to actually set it!
          System.debug('myValue:::::::'+myValue); // Should be value here
      }
    }

    public TestComponentController(){
        System.debug('myValue:::::::'+myValue); // No value here
       
    }
}

Not sure what the implications of this are for your code, but this got me a lot further once I understood this.  Maybe using JavaScript or jQuery to do some actionFunction on document load might help out.