Skip to content

Include Fragments

A fragment is a new type of file which allows for reuse of code from the projection and client files. The principle is simple, the code to share/reuse is created, and then this code is included as a fragment in other files.

There are some restrictions to what is possible to share. For example, it is not possible to put a page or assistant in a fragment, but it is possible to have selectors, groups, lists, dialogs, commands and so on. Projection parts are also there for reuse.

A fragment file is created like any projection or client file. In the file there are two sections, one for client fragments and one for projection fragments. Each section is defined by a starting comment. Those comments need to be there, so it is recommended to not remove them.

Example

This example shows a page that uses groups and entities, which are defined in a fragment.

Fragment file


fragment PubCustomerInfo;  
component NWENTP;  
layer Core;  

--------------- CLIENT FRAGMENTS ---------------  
group CustomerInfoHeaderGroup for CustomerInfo {  
   label = "Customer";  
   field CustomerId;  
   field Name;  
   field AssociationNo;  
}  

selector CustomerInfoSelector for CustomerInfo {  
   static CustomerId;  
   static Name;  
   static AssociationNo;  
}  

group GeneralGroup for CustomerInfo {  
   label = "General";  
   lov LanguageCodeRef with IsoLanguageSelector;  
   lov CountryCodeRef with IsoCountrySelector;  
   field CustomerCategory;  
   field CreationDate;  
   field CorporateForm;  
   field IdentifierReference;  
   field IdentifierRefValidation;  
}  

----------------- PROJECTION FRAGMENTS --------------------  
@Override  
entity CustomerInfo {  
   attribute CustomerId Text {  
      label = "Customer";  
   }  

   reference LanguageCodeRef(DefaultLanguage) to IsoLanguage(LanguageCode) {  
      label = "Default Language";  
   }  
   reference CountryCodeRef(Country) to IsoCountry(CountryCode) {  
      label = "Country";  
   }  
}  

Client file

This client file example shows a page with the label "Customer". Notice that the groups defined in the fragment file are reused. Also notice the include fragment-statement.


client NiweCustomer;  
component NWENT;  
layer Core;  
include fragment PubCustomerInfo;  

page CustomerPage using CustomerSet {  
   label = "Customer";  
   selector CustomerInfoSelector;  
   group HeaderGroup;  
   arrange {  
      group GeneralGroup;  
      list OurIdList(OurIds);  
   }  
}  

list OurIdList for CustomerInfoOurId {  
   label = "Our Id at Customer";  
   field CustomerId;  
   lov CompanyRef with CompanySelector;  
   field OurId;  
}  

selector CompanySelector for Company {  
   static Company;  
   static Name;  
}  

Projection file

Notice that the example code has an overridden CustomerInfo in both the fragment and the projection. It is also a requirement to add an include fragment-statement to make use of the fragment in the projection file.


projection NiweCustomer;  
component NWENT;  
layer Core;  
include fragment PubCustomerInfo;  
entityset CustomerSet for CustomerInfo;  

@Override  
entity CustomerInfo {  
   array OurIds(CustomerId) to CustomerInfoOurId(CustomerId);  
}  

@Override  
entity CustomerInfoOurId {  
   reference CompanyRef(Company) to Company(Company);  
}