Displaying Object Entries with Collection Providers
Liferay 7.4 U77+/GA77+
When you publish an object definition, Liferay creates a collection provider for it. You can use this provider with the Collection Display fragment and collection pages to display its entries. Objects support all collection display features, including filtering, styling, and display options.
Using an Object’s Collection Provider
-
Create a new content page or display page template. Alternatively, begin editing ( ) an existing one.
noteYou can also create a collection page using the collection provider. See Collections and Collection Pages for more information.
-
Drag and drop the Collection Display fragment into the page or template from the Fragments and Widgets () sidebar.
-
Select the Collection Display Fragment to access its configuration options and click Select Collection in the General tab.
-
In the modal window, click the Collection Providers tab and select the object’s provider.
-
(Optional) Filter the displayed object entries. You can filter by any picklist or boolean fields in the object:
Click Collection Options () and select Filter Collection.
Then select the desired filters and click Apply.
After selecting the desired provider, use additional fragment options to determine how Object entries appear, including List Style and Pagination.
Mapping Fragments to Object Fields
When you select an object for a Collection Display fragment, the object is set as its mapping source. Now you can add fragments to it and map their sub-elements to object fields to create flexible page displays for individual object entries. This is true for collection pages as well.
For example, you can embed a button in a Collection Display fragment mapped to an object and then configure the button’s link to display the name of each item in the collection.
Mapping Fragments to Related Object Fields
Mapping fragment elements to related object fields is behind a release feature flag. Read Release Feature Flags for more information.
If the mapped object is on the child side of a one-to-many relationship, you can map fragment elements to fields in the parent object. The embedded Collection Display fragment uses a unique related items collection provider to form the new collection.
For example, if a City
object (child) is related to a Country
object (parent), you can map fragments to fields in the Country
object.
To map fragments to a related object’s fields,
-
Use the Object’s collection provider with a Collection Display fragment.
-
Embed another Collection Display fragment within the initial Collection Display.
tipUsing the Browser tab in the page edit menu can help you position the fragment more precisely within the page hierarchy.
-
Click Select Collection in the new Collection Display fragment’s configuration options.
-
Click the Related Items Collection Providers tab.
-
Select the collection provider with the name of the object’s relationship. The associated object type appears under the relationship’s name. In this example, the relationship is called
cities in country
:
Now you can embed fragments in the new Collection Display and map them to fields in the related object.