mandatory lists areas templates definitions Developer Jahia 8 Jahia 8.1 Jahia 8.2

How to force an editor to contribute at least one element in an jnt:area ?

Question

Sometimes you want to make sure that editors do not leave an area (which is stored as a jnt:contentList) completely empty. For example, a homepage might require at least one teaser, or a blog section might require at least one article. A common question is therefore: Can Jahia force editors to contribute at least one element inside an area?

The short answer is: No, Jahia does not provide a native way to enforce this constraint.
However, you can guide editors by displaying a clear message in Edit mode when a list is empty, so they understand that content is expected.

Answer

By design, Jahia does not prevent saving or publishing empty lists.
If a jnt:contentList (or any area) has no sub-nodes, the system considers it valid.

The solution is to implement a UX-friendly helper:

  •  Create a custom list type (a subtype of jnt:contentList),
  • Use it in your templates where you want to avoid empty lists,
  • Provide a footer view that displays a message only when the list is empty in Edit mode.

This way, editors are gently reminded to add content, without blocking their work.

Example implementation

  1. Declare a mixin subtype
    [jmix:nonEmptyList] > jnt:contentList
  2. Use it in a template
    When you declare an <template:area> in a template, you can specify an areaType.
        •    By default, if no areaType is provided, the area is created as a jnt:contentList, which is Jahia’s built-in node type for storing lists of child nodes.
        •    The areaType parameter allows you to override this default and tell Jahia to use a different node type for the underlying list.
    <template:area path="teaser"
                   areaAsSubNode="true"
                   areaType="jmix:nonEmptyList"/>

    Here, instead of creating a plain jnt:contentList, the area is created as a jmix:nonEmptyList (which itself extends jnt:contentList).

  3. Create a footer override
    For your custom list type, you only need to provide the hidden.footer view — all other views are automatically inherited from jnt:contentList.
    This means you don’t need to duplicate or redefine standard views like list.jsp, only the one that contains your extra logic.
    Create the file src/main/resources/jmix_nonEmptyList/html/nonEmptyList.hidden.footer.jsp

    <c:if test="${renderContext.editMode
                 and currentNode.isNodeType('jmix:nonEmptyList')
                 and empty moduleMap.currentList}">
        <div class="alert alert-info" role="status">
            This list can’t be empty — please add at least one item to continue!
        </div>
    </c:if>

    Because jmix:nonEmptyList extends jnt:contentList, all default rendering (like list display in Live or Preview) is preserved — only the footer in Edit mode is customized.
     

Result

  • In Edit mode, editors see the message when the list is empty.
  • In Live/Preview, nothing is displayed.
  • This is guidance only, not a blocking validation.