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.

Important
  • 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

  1. Create a new content page or display page template. Alternatively, begin editing ( Edit Button ) an existing one.

    Note

    You can also create a collection page using the collection provider. See Collections and Collection Pages for more information.

  2. Drag and drop the Collection Display fragment into the page or template from the Fragments and Widgets (Fragments and Widgets) sidebar.

  3. Select the Collection Display Fragment to access its configuration options and click Select Collection in the General tab.

    Select the fragment and click Select Collection.

  4. In the modal window, select a collection or click the Collection Providers tab and select the object’s provider.

    In the Collection Providers tab, select the object's provider.

    Note

    Liferay 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.

  5. (Optional) Filter the displayed object entries. You can filter by any picklist or Boolean fields in the object:

    Click Collection Options (Collection Options Button) and select Filter Collection.

    Click the Collection Options button and select Filter Collection.

    Then select the desired filters and click Apply.

    Select the Filters to 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.

Map fragment sub-elements in Collection Display fragments to object fields.

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.

You can display related objects in collections.

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,

  1. Use the object’s collection provider with a collection display fragment.

  2. Embed another collection display fragment within the initial collection display, as its collection item.

    Tip

    Using the Browser tab in the page edit menu can help you position the fragment more precisely within the page hierarchy.

    Use the Browser tab to help properly embed the Collection Display fragment.

  3. Click Select Collection in the new collection display fragment’s configuration options.

  4. Click the Related Items Collection Providers tab.

  5. 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:

    Select the relationship that you created with between the displayed object and another object type.

Now you can embed fragments in the new collection display and map them to fields in the related object.

Map fragment sub-elements to fields in parent objects.

Capabilities

Product

Contact Us

Connect

Powered by Liferay
© 2024 Liferay Inc. All Rights Reserved • Privacy Policy