Skip to Content

SAPUI5: Reuse fragments and JS files in multiple apps

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    Mar 10, 2017 at 05:24 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Mar 10, 2017 at 05:17 PM

    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.

    Add comment
    10|10000 characters needed characters exceeded

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

    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);
    
    Add comment
    10|10000 characters needed characters exceeded

    • 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)
      
  • Mar 17, 2017 at 08:58 AM

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

    Add comment
    10|10000 characters needed characters exceeded