Hi, I'm trying to pass a string (buttonText) that is stored inside a template to its parent (template repeater) by storing it in a custom property called selectedButton. It is only allowed to pass it if active == True (active is a property of the template). The mouseClicked event triggers it.
component = event.source
parentComponent = component.parent
if component.getPropertyValue('active'):
parentComponent.selectedButton = component.getPropertyValue('buttonText')
The shown code results in the following error: object has no attribute 'selectedButton'.
Would be appreciated if somebody could help me out, many thanks!
Kevin
The direct parent of a template instance won't be the containing component - there's more intermediaries than that, for boring technical reasons. Try printing the type of each parent reference you get as you add more successive .parent
calls until you get the repeater.
Historically, it has been .parent.parent
to get to a simple template holder from its template root, and .parent.parent.parent
to get to either a repeater or canvas from that template root.
That's very interesting and insightful to know. I wasn't aware of the amount of component layers inside the template canvas. My issue has been resolved thanks to your help, PGriffith and pturmel!
I haven't used the .parent.parent.parent.parent...
approach in a long time. I prefer to use either system.gui.getParentWindow(event)...
or SwingUtilities.getAncestorOfClass...
.