Displaying Object Entries with Collections
Liferay 7.4 U77+/GA77+
When you publish an object definition, Liferay creates a collection provider for it. For site-scoped objects, you can also create manual or dynamic collections for the object. You can use these collections with the Collection Display fragment and collection pages to display object entries. Objects support all collection display features, including filtering, styling, and display options.
- Instance-scoped objects cannot be used in manual or dynamic collections. With Liferay DXP you can use Search Blueprints and its collection provider to achieve most use cases. See Collections with Search Blueprints for more information.
- Draft entries cannot be displayed in collections. Object entries must first be published.
Using an Object Collection
-
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, select a collection or click the Collection Providers tab and select the object’s provider.
NoteLiferay DXP 2024.Q4+ You can access entries from registered system objects (e.g., Accounts, Commerce Order Items, Commerce Orders, Organizations, Users) using their respective Collection Providers.
-
(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 collection, use additional fragment options to determine how Object entries appear, including List Style and Pagination.
When you select an object for a Collection Display fragment, the object is set as its mapping source. When you add fragments to the collection display, you can 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 heading in a collection display fragment and configure it to display the name of each item in the collection. If working with an object on the child side of a one-to-many relationship, you can also map fragments to fields of the related parent object.
You can display related object entries from a relationship table with the relationship collection provider that’s generated for each relationship table.
Relationship Collection Providers
You can display related object entries from relationship tables with collection providers using nested collection display fragments. The top-level collection display uses the parent object’s collection provider, while the nested collection display uses a special relationship collection provider for relating each parent to its child objects.
The relationship collection provider is called a Related Items Collection Provider and is available for the parent object of one-to-many relationships and both objects in many-to-many relationships. This collection provider only appears in nested collection display fragments for objects with relationship tables.
For example, with a one-to-many relationship of Country to Cities, you can show countries with their child cities by mapping a fragment to the city name field in a nested collection display.
This is the general procedure for configuring nested collection display fragments:
- Configure the top level collection display to use the parent object’s collection provider.
- Configure the nested collection display to use the related item collection provider generated for the relationship table data.
- In both collection display fragments, choose the grid display style and add fragments mapped to their respective object fields.
To map fragments to a related object’s fields in the collection display,
-
Use the object’s collection provider with a collection display fragment.
-
Embed another collection display fragment within the initial collection display, as its collection item.
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.