function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
RustyboyRustyboy 

Pass value to visualforce component

Hi,

I am trying to pass parameters to a VF component, and build UI details when the controller is initialised. In my research I see that you cannot access component attributes in the constructor, and I have tried lots of ways to get around this. Currently trying to make actionSupport work but it is not firing.

I don't really care what method I use as long as it works

Here is my component
<apex:component controller="NamedVotesController">

    <!-- Attribute Definitions -->
    <apex:attribute name="meetId"
    				assignTo="{!meetingId}"
    				description="This is the meeting item ID"
                    type="Id" 
                    required="true"/>
    <apex:attribute name="meetItemId"
    				assignTo="{!meetingItemId}"
    				description="This is the meeting item ID"
                    type="Id" 
                    required="true"/> 

    <!-- Component Definition -->

	<apex:actionFunction name="buildDetails" action="{!buildVoterDetails}"/>    
   
	<apex:dataTable value="{!voters}" var="voter" id="voterTable"
		styleClass="tableClass">
		
		<apex:column >
			<apex:facet name="header">
				<apex:outputText value="{!$ObjectType.Meeting_Item_Vote__c.fields.Voter_Name__c.label}" />
			</apex:facet>
			<apex:outputField value="{!voter.Attendee__c}" />
		</apex:column>

		<apex:column >
			<apex:facet name="header">
				<apex:outputText value="{!$ObjectType.Meeting_Item_Vote__c.fields.Voter_Name__c.label}" />
			</apex:facet>
			<apex:outputField value="{!voter.Voter_Name__c}" />
		</apex:column>
		
		<apex:column >
			<apex:facet name="header">
				<apex:outputText value="{!$ObjectType.Meeting_Item_Vote__c.fields.Proposed__c.label}" />
			</apex:facet>
			<apex:inputField value="{!voter.Proposed__c}" />
		</apex:column>	
			
	</apex:dataTable>


</apex:component>

And here is the controller
public with sharing class NamedVotesController {

	// IDs - passed into controller using Attribute in NamedVotes component
	public ID meetingId;
	public ID meetingItemId {get; set;}

	private id meetId;

     public NamedVotesController()
    {
          DO SOMETHING
   	
    }


    public pageRreference buildVoterDetails()
    {

system.debug('----------- In buildVoterDetails, MeetingID: ' + meetingId);
system.debug('----------- In buildVoterDetails, theID: ' + theID);

		meetID = meetingId;
		

    	return null;
    }


    
}

Any assistance greatly appreciated
Best Answer chosen by Rustyboy
bob_buzzardbob_buzzard
The way I'd usually handle this is to provide setMeetItemid and setMeetId methods. These will be invoked when your attributes are set after the constructor completes.  After these have set their values, they hand off to another method, initialise or similar. This method checks that (a) the two ids are both defined and (b) initialisation hasn't already taken place.  Assuming these conditions are satisfied, I then execute the buildVoterDetails method. 

Essentially run a one-time initialisation after all of the attributes are populated.