0
votes

I've searched google and stack but can't seem to find a definitive answer. What I would like to do, is something like this:

Say I have custom control A, within which, is a radio button, when I click it, I want it to grab a custom property that is set on custom control B, lets say compositeData.Name as an example. Can I do this?

If I give custom control B an ID, lets say ccB, can the radio button in custom control A do something like, getComponent("ccB").getValue().compositeData.Name so I can get the value of the property I passed into custom control B using the custom property 'Name'?

If its a straight no, at least I know to stop playing around with the idea! Thanks

1
Your question is based on whether it could be done or not. But what you should be more concerned about is the why. What your are trying to accomplish is an anti-pattern. You’re trying to overextended the component responsibility to control and read data, data that it wasn’t given to it. A custom control on the page should know nothing about the existence of another custom control in the view tree. Flow should always be top-down and in case something needs to trigger a particular behavior to bubble up and be caught by a higher controller in the hierarchy. What are you trying to do exactly?shillem
Extract the property to a bean. And use this bean in the compositeData properties. Put the bean in the viewscope or use some viewscope variables for that.umeli
@shillem My top level CC drives lower level stuff, showing / hiding of certain questions for example. If question 1, drives question 2 and 3, and the user answers question 2 and 3, but then changes their mind on question 1 meaning items in question 2 or 3 are now not needed, I want to wipe some of their values and do some other bits. I've created a custom property on Q1 which contains an array of questions to wipe if certain conditions are met which works fine, however some field names for example are computed dynamically based on the custom property values, so I want to get a handle on themChris Richards
By custom property in Q1 you mean that each question is a custom control embedded by your top level CC? Does the top level have any bearing as to whether these question CC are present on the page? Are these questions hardcoded in the xsp or generated dynamically (say by an xp:repeat loop)?shillem
@shillem to keep it simple, lets say I have 1 custom control (the question and fields) and around 50 of them on the page. Each has the same custom properties, i.e question text and review team but obviously the custom property has a different value passed into each cc. But the custom control containing question 3 could be shown or hidden based on the answer selected from the custom control that contains question 1.Chris Richards

1 Answers

0
votes

Reaching from one control into the inside of another control would break component isolation. You might want to take a different approach:

Option a - client side: Your control emits a JavaScript event that bubbles up until it reaches a parent element that contains the control you want to change (presumably the parent Dom element). There you set the property of that element.

Option b - server side: As Urs suggested: bind both to a bean and handle the updates inside the bean