6

I am trying to fetch fields inside of an embedded schema using JSP. My Root Elements inside the schemas are set to be equal to the Class names.

Displaying the field entity.title is no problem. Displaying entity.link.linkText renders nothing for me.

I have noticed Core Modules have no issues displaying embedded fields. For example Cookie Notification Bar outputs the embedded info. What steps do I need to undertake to make this work for my own classes?

InspirationalHeader JSP:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="dxa" uri="http://www.sdl.com/tridion-dxa" %>
<%@ taglib prefix="xpm" uri="http://www.sdl.com/tridion-xpm" %>

<jsp:useBean id="entity" type="be.toerismevlaamsbrabant.website.modules.Toerisme.Entity.BlockLink"
             scope="request"/>
<div class="content" ${markup.entity(entity)}>
    <h1 ${markup.property(entity, "title")}> ${entity.title}</h1>
    <c:if test="${not empty entity.link.linkText}">
        <p>
            ${entity.link.linkText}
        </p>
    </c:if>
</div>

BlockLink Class:

@SemanticEntity(entityName = "BlockLink", vocabulary = SDL_CORE, prefix = "bl")

public class BlockLink extends AbstractEntityModel {
    @JsonProperty("Title")
    @SemanticProperty("bl:title")
    private String title;

    @JsonProperty("Link")
    @SemanticProperty("bl:link")
    private Link link;

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public Link getLink() {
        return link;
    }

    public void setLink(Link link) {
        this.link = link;
    }
}

Link Class - mostly copied from SDL Core:

@SemanticEntity(entityName = "Link", vocabulary = SDL_CORE, prefix = "l")
public class Link extends AbstractEntityModel {

    @SemanticProperties({
            @SemanticProperty("internalLink"),
            @SemanticProperty("externalLink"),
            @SemanticProperty("l:internalLink"),
            @SemanticProperty("l:externalLink")
    })
    @JsonProperty("Url")
    private String url;

    @JsonProperty("LinkText")
    @SemanticProperty("l:linkText")
    private String linkText;

    @SemanticProperty("l:alternateText")
    @JsonProperty("AlternateText")
    private String alternateText;

    @Getter @Setter private String target;

    /**
     * <p>Getter for the field <code>url</code>.</p>
     *
     * @return a {@link java.lang.String} object.
     */
    public String getUrl() {
        return url;
    }

    /**
     * <p>Setter for the field <code>url</code>.</p>
     *
     * @param url a {@link java.lang.String} object.
     */
    public void setUrl(String url) {
        this.url = url;
    }

    /**
     * <p>Getter for the field <code>linkText</code>.</p>
     *
     * @return a {@link java.lang.String} object.
     */
    public String getLinkText() {
        return linkText;
    }

    /**
     * <p>Setter for the field <code>linkText</code>.</p>
     *
     * @param linkText a {@link java.lang.String} object.
     */
    public void setLinkText(String linkText) {
        this.linkText = linkText;
    }

    /**
     * <p>Getter for the field <code>alternateText</code>.</p>
     *
     * @return a {@link java.lang.String} object.
     */
    public String getAlternateText() {
        return alternateText;
    }

    /**
     * <p>Setter for the field <code>alternateText</code>.</p>
     *
     * @param alternateText a {@link java.lang.String} object.
     */
    public void setAlternateText(String alternateText) {
        this.alternateText = alternateText;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        return "Link{" +
                "url='" + url + '\'' +
                ", linkText='" + linkText + '\'' +
                ", alternateText='" + alternateText + '\'' +
                '}';
    }
}

I initialize the BlockLink view

@RegisteredViewModels({
                @RegisteredViewModel(viewName = "InspirationalHeader", modelClass = BlockLink.class)
        })
4

You have to ensure that your embedded View Models (class Link in this case) are also registered.

See http://docs.sdl.com/LiveContent/content/en-US/SDL%20DXA-v5/GUID-FEDC295C-1D87-485E-B904-AE5596A4A802

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.