You need to sign in to do that
Don't have an account?
Luke@TWS
Accessing Component Attributes with AssignTo
I have a VF Page with a custom controller. It contains a string with get and set methods. This value is passed as a String to a component. The attribute has an assignTo referencing a public string with {get;set;) in the components controller. The value is not available (is null) when acessed in the components constructor but is available shortly after within a command button action. I need the value within the constructor. Any ideas?
@Doug, when can we get the 'action' attribute???!!! That would be a huge help for this issue. Everyone please vote up this idea if this an issue for you: https://sites.secure.force.com/ideaexchange/ideaView?c=09a30000000D9xt&id=08730000000H6PMAA0&mc=0
I've been able to work around this by hooking initialization into a setter method. Based on the documentation (http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_lifecycle_example.htm) for lifecycle I believe we can count on the setters for any assignTos to be evaluated prior to any getters being called.
In my example I needed to parse a sub query of an object to populate other objects. When this parsing took place in the constructor it failed as the assignTo hadn't been evaluated yet.
Ideally I would just call parseSubObjects from an action attribute on the component, but as that feature is not here yet I opted to use a setter side effect instead.
This has been working so far for me.
All Answers
This is a bug and should be fixed.
Also I do not seem to be getting any success with the "default" property of the component's attribute either.
Regardless of the Component state (Constructor, Postback event, Property get or set) the default value is not passed down to the Component Controller!
Another approach would be something like we already have in <apex:page> - the action attribute can be used to handle this very issue (among others). We have not exposed the same concept for <apex:component> yet and to date you are the first person to ask for it externally.
This is exactly the kind of thing that IdeaExchange is great for - why not post the idea and get some community support for it to help move it up in priority?
Message Edited by dchasman on 10-09-2008 02:31 PM
I believe what Salesforce is doing behind the scene with what developers require to develop business applications are two different things.
For a visualforce developer constructor of a controller is the only place to initialize values. Unless Salesforce would provide a full life-cycle of events like ASP.NET and free up programmers to develop full-scale apps.
Such events are:
constructor
onInit
onLoad
onPreRender
onRender
At least a "Load" event could be really nice.
As I mentioned in my previous post <apex:page action> is already in place at the page level for this type of server side onload event you can wire up to your apex code method of choice and what we are currently missing is <apex:component action>. This approach is more likely to show up earlier than component binding because it is a direct analog to an existing concept.
Message Edited by dchasman on 10-09-2008 08:16 PM
What about Component's interaction with its parent page? Any plans to address that?
This part is also very crucial and I wonder why it is absent. If I have a Component that has controller of its own then the Component can not return any values (through attributes) back to the page!
See this post:
http://community.salesforce.com/sforce/board/message?board.id=Visualforce&thread.id=5791
http://community.salesforce.com/sforce/board/message?board.id=Visualforce&thread.id=5791
Basically you can inject an object (apex object or sobject) from the page into a component and the component can most definitely change state, invoke methods, etc. This is extremely powerful and something we do all the time in our own components and pages.
Message Edited by dchasman on 10-10-2008 10:44 AM
I'm having another problem though. How do I get the value back to the main page?
I'm using the attribute value perfectly fine. It's been assigned to a variable in the component controller.. Every time I make a change to the data within the control I am updating the component controller variable but it doesn't seem to be making it back to the main page code.
Message Edited by Luke@TWS on 10-13-2008 07:07 AM
Ok, so here is an example of injecting the entire controller into a component via an attribute and then injecting that into the component's controller via assignTo.
NOTE: I am specifically not worrying about providing a clean separation of concerns in order to keep this example small. Normally when I do this I define and interface in apex code that I sue as the type of the attribute and then create a class that implements the interface in order to keep things loosely coupled. once you have this in place you can easily add additional capabilities to your injected object/interface.
Message Edited by dchasman on 10-16-2008 02:46 PM
Commenting on the opening line below:
The demoValue property in ExpressionPassingDemo appears to assume the value one enters.
Perhaps something changed in subsequent releases?
Hi Doug,
I have a question on a slight variant of what has been discussed here.
I am looking at the bit that deals with not having yet the <apex:component action>.
My component needs to display a list of checkboxes that is dynamic in the sense that its number and the label for each checkbox comes from the database. So in principle I would make the queries and intialize the list of checkboxes (I am using <apex:selectCheckboxes>) within the component controller. But we know this dos not work yet.
What would you suggest we use in this case ?. I mean, which combination of apex standard components and component controller methods combination ?.
Thanks very much in advance.
Regards,
Fernando
Wow, kidding me?
This is not an obvious work-around.
Is there anything being planned to fix this?
JPC
@Doug, when can we get the 'action' attribute???!!! That would be a huge help for this issue. Everyone please vote up this idea if this an issue for you: https://sites.secure.force.com/ideaexchange/ideaView?c=09a30000000D9xt&id=08730000000H6PMAA0&mc=0
I've been able to work around this by hooking initialization into a setter method. Based on the documentation (http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_lifecycle_example.htm) for lifecycle I believe we can count on the setters for any assignTos to be evaluated prior to any getters being called.
In my example I needed to parse a sub query of an object to populate other objects. When this parsing took place in the constructor it failed as the assignTo hadn't been evaluated yet.
Ideally I would just call parseSubObjects from an action attribute on the component, but as that feature is not here yet I opted to use a setter side effect instead.
This has been working so far for me.
Are parsePriorForecastSnapshots and parseSubObjects the same method?
EDIT: Nevermind. I see that this is just a typo and these should be the same method.