Skip to Content
0

SAPUI5: Reuse fragments and JS files in multiple apps

Mar 10, 2017 at 07:18 AM

260

avatar image

Hello experts

I have a few fragments with JS files as their controllers that I would like to reuse in all my apps.

An example of one of these would be our custom "upload attachment" fragment along with it's JS file as controller for the events. I would then like to include this fragment and JS in all my apps that requires documents to be uploaded.

What would be the best way to make these files global and how would I reference/include them in my projects/apps?

Thanks :)

Antonette

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Best Answer
Ryan Crosby Mar 10, 2017 at 05:24 PM
1

Hi Antonette,

I have done something like this using the component container concept. You could refer to this also and see if this works for you: Component Container Help

Regards,

Ryan Crosby

Show 6 Share
10 |10000 characters needed characters left characters exceeded

Hello Ryan

Could you please elaborate? I'm not sure how this would work.

Thanks
Antonette

0

Hi Antonette,

What I did in my case was a I deployed the reusable fragment as a component - basically a page. Then, in any other application I was able to refer to that component and instantiate an instance of that component within the component container. In any application where I have done this I can then run that component like it exists within the application.

Regards,

Ryan Crosby

0

Hi Ryan

That is really cool. I've done a bit more reading and I think this might work.

Is it possible to pass data to and from the app in the component container?

Regards

Antonette

0

Hi Antonette,

I didn't have a requirement for what I was doing but I don't see why it would not be possible. Have some method in the controller to pass the model from the application and then bind some event to pass it back to application when the component onExit is triggered. Not 100% certain since I have not tried but you could look into it.

Regards,

Ryan Crosby

0

Thanks Ryan

I can see the component of my 1st app is initializing inside my 2nd app, but the view of app 1 is not displaying in the view of app 2 (xml, using component container). Am I doing something wrong?

Thanks

Antonette

0

Never mind, got it working, thanks so much Ryan! :)

1
Srikanth KV Mar 10, 2017 at 05:17 PM
0

Its like you are building a library to place commonly used customUI controls/fragments so that it can be accessed from any application where it is referenced.

I think this should be possible.

Refer to this blog by Philip, where custom controls are placed in a separate project lib 'dalrae/ui/controls'. This should provide some pointers on the approach to be used.

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Thanks Srikanth

I'll try this and get back to you.

Regards

Antonette

0
avatar image
Former Member Mar 15, 2017 at 06:16 AM
0

In my case, I created a reusable package as 'ZCOMMON'.

In every package that wants to access a fragments in ZCOMMON, I registered common package.

Check below code

jQuery.sap.registerModulePath("common", "../zcommon");
var oDialogController = sap.ui.controller("common.controller.Approve");
this._approveDialog = sap.ui.xmlfragment("common.frag.Approve", oDialogController);
Show 2 Share
10 |10000 characters needed characters left characters exceeded

Hello Seungchul

Is ZCOMMON your BSP name? example http://<gateway>:<port>/sap/bc/ui5_ui5/sap/zcommon/index.html

How did you make it reusable? Or can you just call it?

Where do you register it? In index or component?

Thanks

Antonette

0
Former Member

ZCOMMON is BSP(SAPUI5) application name.

If your application APP1 wants to access a ZCOMMON, just register a path like below code.

Check this link

 jQuery.sap.registerModulePath("common", "../zcommon");

Then call a fragments

this._approveDialog =sap.ui.xmlfragment("common.frag.Approve", oDialogController)
0
Noufal Farah Mar 17, 2017 at 08:58 AM
0

As I did, I created my own library which includes the shared fragment and then declare it in all my apps.

Share
10 |10000 characters needed characters left characters exceeded