3

We are facing issue with accessing custom Embedded fields in Java DXA 1.4 solution. Default DXA Linklist component is working fine, but when we create custom schema like "CeairLinkList" Then it is not rendering the fields and always throw Null for URL and text fields values. Same custom embedded field is working fine with DXA 1.4 .Net solution.

Code Block:

@SemanticEntity(entityName = "CeairLinkList", vocabulary = > "http://schema.org", prefix = "e", public_ = true)
public class CeairLinkList  extends AbstractEntityModel
{

     @JsonProperty("Headline")
        private String headline;

        @JsonProperty("Links")
        private List<CeairLink> links;


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

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

        /**
         * <p>Getter for the field <code>links</code>.</p>
         *
         * @return a {@link java.util.List} object.
         */
        public List<CeairLink> getLinks() {
            return links;
        }

        /**
         * <p>Setter for the field <code>links</code>.</p>
         *
         * @param links a {@link java.util.List} object.
         */
        public void setLinks(List<CeairLink> links) {
            this.links = links;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public String toString() {
            return "CeairLinkList{" +
                    "headline='" + headline + '\'' +
                    ", links=" + links +
                    '}';
        }


@ComponentScan(basePackages = {"com.ceair.dxa"})
public class CeairModuleInitializer {

    @RegisteredViewModels({

            //added Pages
            @RegisteredViewModel(viewName = "TwoColumnLayoutWithLeftIndentation", modelClass = PageModelImpl.class),
            @RegisteredViewModel(viewName = "OneColumnLayout", modelClass = PageModelImpl.class),

            //added Regions
            @RegisteredViewModel(viewName = "Main", modelClass = RegionModelImpl.class),
            @RegisteredViewModel(viewName = "Top",  modelClass = RegionModelImpl.class),

            //added Models
            @RegisteredViewModel(viewName = "HeroBanner", modelClass = CeairHeroBanner.class),
            @RegisteredViewModel(viewName = "ExpandableBox", modelClass = CeairGenericContent.class),
            @RegisteredViewModel(viewName = "ArticleDetail",  modelClass =  CeairGenericContent.class),
            @RegisteredViewModel(viewName = "LeftNavigation",  modelClass =  NavigationLinks.class),
            @RegisteredViewModel(viewName = "RelatedContent", modelClass = CeairLinkList.class),
            @RegisteredViewModel(viewName = "HeroBannerHeadingLeft", modelClass = CeairHeroBanner.class),
            @RegisteredViewModel(viewName = "NewsList", modelClass = CeairContentList.class),
            @RegisteredViewModel(viewName = "NewsList2", modelClass = ContentList.class)

    })

    @Component
    @ModuleInfo(name = "Ceair module", areaName = "Ceair", description = "Ceair DXA module which contains basic views")
    public static class CeairViewInitializer extends AbstractInitializer {
        @Override
        protected String getAreaName() {
            return "Ceair";
        }


    }


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

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

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

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

/**
 * <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 "CeairLink{" +
         "url='" + url + '\'' +
         ", linkText='" + linkText + '\'' +
         ", alternateText='" + alternateText + '\'' +
         '}';
}
}
3
  • is your CeairLink class works in other scenarios?
    – Raj Kumar
    Commented Jul 19, 2016 at 13:00
  • 1
    what are the Schema details of your CeairLinkList Schema? I see you are trying to map it using schema.org (is it mapped on the CM side to this too), but CeairLinkList is not a Schema on schema.org, so that public mapping does not make any sense. Commented Jul 19, 2016 at 13:30
  • When you add code, please make sure you format it correctly so it shows up readable in your question. Read the FAQ section of this site for tips on how to format. The getters and setters code you posted arn't really useful, what we still don't know is the details of your actual Schema in the CMS, like what is its Rootelement name, and have you actually supplied a semantic mapping to it? I suggest you edit the question yourself and remove all the information that is not adding anything (like the getter and setter code) and provide a few more details around your Schema in the CMS? Commented Jul 20, 2016 at 5:36

1 Answer 1

2

The problem may be that you did not register your CeairLink Entity Model. See: https://docs.sdl.com/LiveContent/content/en-US/SDL%20DXA-v5/GUID-FEDC295C-1D87-485E-B904-AE5596A4A802

As mentioned in that doc topic, DXA 1.5 Java provides an easy way to register such "embedded" Entity Models. On earlier DXA version, you can't register a View Model without an associated View, so you will have to hack your way around using a bogus View.

Hope this is sufficient incentive to upgrade to DXA 1.5. :-)

2
  • Thank Rick..registered with bogus View with CeairLink works fine. Commented Jul 20, 2016 at 6:48
  • Good to hear. Will you mark this Answer as the solution, then? Commented Jul 20, 2016 at 16:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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