You need to sign in to do that
Don't have an account?

Pass value from Component to Controller
I want to pass the ID of the Contact from my VisualForce Email Template up to the Controller, via the Custom Component, so that the Controller can query Events for just this Contact. However, I seem to be getting stuck at Component to Controller.
Per the VF Developer's Guide, under "Custom Component Controllers", step 3 says, "In the <apex:attribute> tag in your component definition, use the assignTo attribute to bind the attribute to the class variable you just defined." However, I am finding this never sets the value in the Controller - just within the Component. Is the Guide wrong or do I have an error?
Here is a snippet of the Component code:
<apex:component controller="EmailApptController" access="global"> <apex:attribute name="ToID" type="ID" description="the account ID" assignTo="{!contactID}"/> <apex:attribute name="Something" type="String" description="something to assign" assignTo="{!something}"/>
And the relevant Controller:
public class EmailApptController { public List<Event> appts {get; set;} public String message {get; set;} public ID contactID {get; set;} public String something {get; set;} public EmailApptController() { datetime yaynow = datetime.now(); appts = [SELECT WhoId, WhatId, OwnerId, Subject, StartDateTime, Result__c, Confirmation_Status__c, Location_Map_URL__c, Location__c, Location_Address__c, Location_City_State_Zip__c, Location_Directions__c, Location_Directions_2__c FROM Event WHERE WhoId = :contactID AND StartDateTime >= :yaynow AND Result__c != 'Cancelled' AND Result__c != 'Rescheduled']; if (appts.isEmpty()){ message = 'There are no pending appointments for this client: ' + contactID + ' and something is: '+ something; } } }
contactID and 'something' always return null from the controller, but when I access them in the Component they are fine.
I have found this post in the wiki re Controller Component Communication, but it's way over my head and seems overkill if all I want to do is grab this one ID. Any thoughts?
Finally figured it out. Solution for anyone who searches this out later:
EmailApptController() was being called BEFORE the values for ContactID were set. (see, 1st line of Component sets controller="EmailApptController" -> THEN lines 2 and 3 were called, to set the values)
I adjusted the code so that the EmailApptController() is called AFTER the ContactID was set (it's called explicitly from inside SetContactID, instead of being implicitly called from the first line of the Component).
Component:
and the Controller:
Note: it seems to take the ID type just fine. Did not have to change that to a String.
All Answers
change the type from id to String.
The assingTo cant take Id type value.
-Dharmesh(http://sfdc-development.blogspot.com/)
My String 'something' (which I added to test that exact issue before I posted) doesn't work either - it does not pass through to the Controller at all...
Finally figured it out. Solution for anyone who searches this out later:
EmailApptController() was being called BEFORE the values for ContactID were set. (see, 1st line of Component sets controller="EmailApptController" -> THEN lines 2 and 3 were called, to set the values)
I adjusted the code so that the EmailApptController() is called AFTER the ContactID was set (it's called explicitly from inside SetContactID, instead of being implicitly called from the first line of the Component).
Component:
and the Controller:
Note: it seems to take the ID type just fine. Did not have to change that to a String.
I have same problem... Just solved with your solution Thanks.
We can use assignto with <apex: attribute to pass from component to controller instead.
Thanks a lot dude, that works just great!
In the page controller:
system.currentPageReference().getParameters().put('aid', 'someID);
then in the component controller:
system.currentPageReference().getParameters().get('aid');