+ Start a Discussion
h8r41dh8r41d 

When are component attributes sent to the controller?

My Visualforce test page:

 

<apex:page sidebar="false" showHeader="false">
<c:ideas_email_digest email="{!$CurrentPage.parameters.email}" mode="Weekly"/>
</apex:page>

 

The Visualforce component:

 

<apex:component controller="ideas_digest_component_controller" access="global">
	<apex:attribute type="String" name="email" assignTo="{!context_user}" description="email address for context" /> 
	<apex:attribute type="String" name="mode" assignTo="{!digest_mode}" description="Digest type can be Weekly or Monthly"/>

{!context_user}   <-- Loads

{!mode} <-- Loads

//.... rest of page

</apex:component>

 

Component controller:

 

public class ideas_digest_component_controller {

	// stuff for the visualforce page
	public string context_user {get; set;}
	public  string digest_mode { get; set; }


// Constructor
public ideas_digest_component_controller() {
		
		if(context_user==null) {
			system.assert(false);  // <-- Always get here
		}
}

///... rest of code irrelevant

}

 

 

My question is, on the VF test page, the class properties are set and will display on the page. However, in the class constructor, the property values are still null.

 

At what point are these values populated? Why are they null in the controller? They are used to load dynamic data for the vforce page.

h8r41dh8r41d

Anybody know an answer to this one?

Thibault WeberThibault Weber

Hi,

 

Same problem, I'have seen other topics on this subject but I didn't found a solution...

h8r41dh8r41d

I just moved my code and avoided using the component parameters in the constructor.

 

Use them in your get functions, they'll be set by then.

Thibault WeberThibault Weber

Yes but it doesn't work for my use:

 

For example:

 

Page:

<apex:page>
	<c:TestComponent val="myValue"/>
</apex:page>

 

 

Component ( "TestComponent" ):

<apex:component controller="TestController">

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

	<apex:dynamicComponent componentValue="{!dynamicDatatable}"/>

</apex:component>

 

Component controller:

 

public with sharing class TestController {

	private String val;
	
	public String getVal(){
		system.debug('getter');
		system.debug(this.val);
		return this.val;
	}
	
	public void setVal(String val){
		this.val = val;
		system.debug('setter');
		system.debug(this.val);
	}
	
	public TestListComponentController(){
		system.debug('Component constructor');
		system.debug(this.val);
	}
		
	public Component.Apex.DataTable getDynamicDatatable(){
		
		system.debug('Dynamic Component');
		system.debug(this.val);
		
		//Create my dynamic component here
		//...
	}
}

 

And the result is:

 

  • DEBUG|Component constructor
  • DEBUG|null
  • DEBUG|Dynamic Component
  • DEBUG|null
  • DEBUG|setter
  • DEBUG|myValue

 

The problem is that I can't retrieve my value "val" into my dynamic component...

 

Any idea?

h8r41dh8r41d

Did you ever solve this?