Tools
Sign in
Login
Forum
Find a component from its Component Path
Forum
>
Scripting
>
Find a component from its Component Path
Dali Li
posted
on August 26, 2014
at 12:22 AM
Dali Li
posted
on August 26, 2014
at 12:22 AM
Given a component path, for example, SCREENSTATE().getErrorComponentPaths(). Is there any way to find out which component it really is?
Stephan
replied
on September 25, 2014
at 10:06 AM
Stephan
replied
on September 25, 2014
at 10:06 AM
No, there is unfortunately no simple and perfect way.
Component paths are generated at runtime. The default strategy is that every component appends its internal id to the component path of the parent component.
Parent component path: root/0/2/8/12
Component id: 23
Component path: root/0/2/8/12/23
So in theory you could take the last element of the component path and then search for a component with this id in the current screen.
But there are some exceptions to the default strategy. Some components append extra information to the component path. The Portal Work List component for example appends the workitem id before it starts to render/process the components in a workitem row. Loop components like For, ForEach and While append either a loop index (1, 2, 3, ...) or a loop iteration id (calculated from an expression). All this would not invalidate the statement above about taking the last path element and treat it as id. But if a screen contains an Include or Template component, you don't know in which screen you have to look for the given id. Component ids are unique only within one screen. So it may be the case (and is in fact very likely) that the main screen, an included screen and a template screen all have a component with id 1 for example. You could try to identify the screen by traveling through the component tree and "replaying" the construction of the component path. Whenever you reach a Include or Template component, you have to analyze which screen it is referring to and continue to travel through the component tree of this screen. Unfortunately there is another hurdle. If the id of the included screen is evaluated at runtime using an expression, you have to reevaluate this expression to find the screen. And to do this, you have to reinitialize a scope with the exact same variables and values as at the time the included screen has been rendered.
But even if you would master all of this, I doubt if you would be happy with what you get. Lets assume that you finally know that the component path belongs to a Text Field component. The component has a binding like "$party.address[$type].street". What do you take out of this? You have no clue which party or which type of address this text field has been rendered for. Maybe the screen contains a ForEach component to loop over a list of parties and a nested ForEach component to loop over addresses (by type) for every party. The rendered screen may show multiple text fields (with different component paths), but the screen business object (the model) only contains one Text Field component. Extracting relevant business information from the screen component model is probably even more complex than analyzing the component path.
Finally, component paths are something very internal to Appway. Relying on a certain layout or structure of a component path may make your solution break if we ever decide to make changes to this.
Sorry for not having better news :-(
- Stephan
Please
sign in
to add a reply
About this site
|
Terms of use
|
Privacy statement
|
Contact us
© 2025 Appway AG. All Rights Reserved.