You need to sign in to do that
Don't have an account?
Apex controller property not being passed properly into a custom compont's componentBody
I have a custom component that sits within a repeater.
the custom component's attribute is set via the repeater.
the custom component's attribute uses assignTo to set a property on its controller.
if (and only if) I use that attribute in the body of another custom component (inside the first custom component), then the attribute only sets the first time the repeater creates the component, never thereafter. I can access the visualforce attribute as expected... but the property on the controller is never set again.
I have a simple code example to illustrate the problem.
Note that the two case IDs ({!case.id} and {!myCase.id}) should be the same.
Any idea what is wrong?
*EDIT*
looking into it more...
the controller is being set properly, but the wrong value is being passed into the component body for some reason.
Its like {!myCase} only gets resolved once and gets reused for every repetition.
TestPage
<apex:page standardController="Contact"> <apex:repeat value="{!Contact.Cases}" var="c"> <div><c:TestComponent case="{!c}" /></div> </apex:repeat> </apex:page>
TestComponent
<apex:component controller="TestComponentController"> <apex:attribute name="case" type="Case" description="TODO" assignTo="{!myCase}"/> <c:TestComponent2>these should be the same: {!case.id}, {!myCase.id} </c:TestComponent2> </apex:component>
TestComponentController
public class TestComponentController { public Case myCase {get;set;} }
TestComponent2
<apex:component> <apex:componentbody/> </apex:component>
Found a workaround.
Load the controller property into an apex:variable and reference that from within the component body.
In the example I gave, modify the TestComponent like this:
I raised a bug, but its just a P3 so it'll probably never get looked at. There was a similar bug from 2009 which was likewise still open.
This workaround seems to do the trick, though