You need to sign in to do that
Don't have an account?
Pat McQueen
Using a component w/ a custom controller in a VF page
Hello,
I am using a component in a VF page and trying to pass information to the custom controller of the component and not having any luck. I think I am missing something basic ... But can't seem to figure it out. There are three parts - The VF page, Component and Controller. When I run the VF page the Apex Debug log confirms that the TargetUserID: is not passed to the custom controller. I thought that the apex:attribute tag with the assign to would call the setter for Target User ID. Any assistance would be appreciated.
The code does run. It just evaluates the TargetUserID as null and returns all the "null" booth shifts - I would like the target users' shifts.
pat
I am using a component in a VF page and trying to pass information to the custom controller of the component and not having any luck. I think I am missing something basic ... But can't seem to figure it out. There are three parts - The VF page, Component and Controller. When I run the VF page the Apex Debug log confirms that the TargetUserID: is not passed to the custom controller. I thought that the apex:attribute tag with the assign to would call the setter for Target User ID. Any assistance would be appreciated.
The code does run. It just evaluates the TargetUserID as null and returns all the "null" booth shifts - I would like the target users' shifts.
pat
VF Page Code:
<apex:page > <h1>Start</h1> <c:BoothShiftList TargetUserID="00580000001UipR" /> </apex:page>
Custom Component <BoothShiftList> Code:
<apex:component controller="ScheduleEmailController"> <apex:attribute name="TargetUserID" description="User id of the person getting this page" type="string" required="true" assignTo="{!TargetUserID}"/> <apex:pageBlock title="My Dreamforce Shifts"> <apex:pageBlockTable id="shifttable" value="{!bs}" var="currentBooth"> <apex:column headerValue="Shift Time"> <a href="/{!currentBooth.Id}">{!currentBooth.Shift__r.name}</a> </apex:column> <apex:column headerValue="Booth Name"> <a href="/{!currentBooth.Booth__r.Id}">{!currentBooth.Booth__r.Booth__c}</a> </apex:column> <apex:column headerValue="Add to Calendar"> <a href="/{!currentBooth.Id}">{!currentBooth.Assigned__c} - {!currentBooth.Is_this_Staffed__c}</a> </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:component>
Custom Controller Code:
Public class ScheduleEmailController { public string TargetUserID { get; set; } public Booth_Shift__c[] bs { get; set; } public ScheduleEmailController() { bs = [Select assigned__r.Id, b.Shift__r.Date__c, b.Shift__r.name, b.Shift__r.Shift_Time__c, b.Shift__c, b.Booth__r.Booth_Type__c, b.Booth__r.Booth__c, b.Booth__c, b.Is_this_Staffed__c from Booth_Shift__c b where assigned__r.Id = :TargetUserID order by b.Shift__r.start__c LIMIT 10]; System.debug('Current User: ' + UserInfo.getUserName()); System.debug('TargetUserID: ' + TargetUserID); } }
to something like this and you should be good to go:
Message Edited by dchasman on 10-21-2008 08:03 AM
Thanks Doug! I actually had two problems. The second problem was a timing problem. The solution was here: http://forums.sforce.com/sforce/board/message?board.id=Visualforce&message.id=5832
Basically, the assignment to targetUser happens AFTER the controller is initialized. This was an easy fix in the controller - just use a get method instead of defining our booth shift array in the controller.
Everything Works now!!