Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading component in fragment with usage: "Uncaught Error: The name of the component is undefined." #2181

Closed
sukramAxians opened this issue Aug 29, 2018 · 4 comments
Assignees

Comments

@sukramAxians
Copy link

Hi,
not sure if it's a bug or a feature...
Loading of components in fragments by configured usage, works only if enclosed by component.runAsOwner.
See exaple provided below.

App.contoller.js function handlePressWorks Works as expected.
App.contoller.js function handlePressBroken Well, is broken...

OpenUI5 version: 1.52.19

Browser/version (+device/version): All

Any other tested browsers/devices(OK/FAIL):

URL (minimal example if possible):
https://plnkr.co/edit/32jCltN2VErODLszAGOQ?p=preview

Steps to reproduce the problem:

  1. Open console (F12)
  2. Press "Brocken!" Button
  3. See @log for "Component-dbg.js:2022 Uncaught Error: The name of the component is undefined."

What is the expected result?
Dialog schould oupen like pressed "Works!" Button

What happens instead?
"Component-dbg.js:2022 Uncaught Error: The name of the component is undefined."

Any other information? (attach screenshot if possible)

Kind Regards
Markus

@stephania87 stephania87 self-assigned this Oct 3, 2018
@stephania87
Copy link

In general, I see the same behavior with older versions
The question is forwarded to the dev team for clarification on the required settings for loading other component into the current component, via #1880578895

@matz3
Copy link
Member

matz3 commented Oct 8, 2018

Hey @sukramAxians,

thanks for reporting this.

The working example seems to be the only way to get this working right now.

Without calling this.getOwnerComponent().runAsOwner within the controller, the owner component is not propagated and therefore, the ComponentContainer fails to create the "usage" component defined.
It seems that the ComponentContainer is not prepared for being instantiated with a "usage" property but without having an owner component defined, that's why the error message is confusing and not really helpful.

So we have two things that should be improved:

  1. Better error message in ComponentContainer for this scenario
  2. Check for a better solution to create fragments (or controls in general) from a controller method by ensuring to propagate the owner component. This should also be documented somewhere in the Developer Guide.

@flovogt flovogt assigned flovogt and unassigned stephania87 Mar 23, 2022
@Thodd
Copy link
Contributor

Thodd commented Mar 24, 2022

Hi,

pretty old issue...

Anyway, in the meantime the proposals of @matz3 have been implemented for quite some time already.
So if you are still interested there is an asynchronous loadFragment() function on the sap.ui.core.mvc.Controller class that takes care of the Owner component setting internally.
Adding the Fragment content to the dependents aggregation of the view is also implicitly done, but you can opt out if needed:
https://ui5.sap.com/#/api/sap.ui.core.mvc.Controller%23methods/loadFragment

I fixed the broken path in this plunkr:
https://plnkr.co/edit/JFXYVbotyFfnlij2

BR,
T

@Thodd
Copy link
Contributor

Thodd commented Mar 24, 2022

PS: forgot to tag @sukramAxians, so you get a notification :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants