3

In order to avoid translating pages we've added a linked component in our page metadata.

enter image description here

I've created a custom page model:

@Data
@SemanticEntity(entityName = "MyPageModel", vocabulary = SDL_CORE, public_ = true)
@EqualsAndHashCode(callSuper = true)
public class MyPageModel extends DefaultPageModel {

    @JsonProperty("MyLinkedPageMetaData")
    @SemanticProperty("myLinkedPageMetaData")
    public MyLinkedPageMetaData myLinkedPageMetaData;

}

I've registered this in my initializer:

@RegisteredViewModel(viewName = "MyPageTemplate", modelClass = MyPageModel.class)

I've create the model for the linked component schema:

@SemanticEntity(entityName = "MyLinkedPageMetaData", vocabulary = SDL_CORE, public_ = true)
@Data
@EqualsAndHashCode(callSuper = true)
public class MyLinkedPageMetaData extends AbstractEntityModel{  
    @JsonProperty("PageTitle")
    @SemanticProperty("pageTitle")
    public String pageTitle;
}

I'm trying to access this in my view via:

<jsp:useBean id="pageModel" type="com.client.dxawebapp.model.page.MyPageModel" scope="request" />

${pageModel.myLinkedPageMetaData.pageTitle}

However the value is never written out, it's just blank.

When I write out ${pageModel.meta} I see "myLinkedPageMetaData=''".

Previewing the page I see:

"Metadata": {
  "nonTranslatedTitle": "Test title",
  "myLinkedPageMetaData": {
    "$type": "EntityModelData",
    "Id": "20953",
    "ComponentTemplate": {
      "Id": "10581",
      "RevisionDate": "0001-01-01T00:00:00"
    },
    "Folder": {
      "Id": "1058",
      "Title": "Page Metadata Components"
    },
    "Content": {
      "pageTitle": "Page title in linked component",
    },
    "SchemaId": "20952"
  }
}

My question is: how can I obtain the values in my linked component in DXA 2.0 Java?

Note: The same approach works fine in DXA 2.0 .Net.

  • What is the root element name of your linked Component? The semantic entity name of MyLinkedPageMetadata should match the root element name. – Rick Pannekoek Oct 8 at 19:25
  • Furthermore, the MyLinkedPageMetadata View Model should also be registered. – Rick Pannekoek Oct 8 at 19:28
  • Thanks Rick. The root element name is indeed "myLinkedPageMetaData" (same as the semantic entity name). Do you have an example of how the MyLinkedPageMetadata model should be registered please? I tried this @RegisteredViewModel(modelClass = MyLinkedPageMetadata.class) – Jonathan Primmer Oct 8 at 19:30
  • The semantic entity name is “MyLinkedPageMetaData” (initial capital) is that exactly the same as the root element name? Note that if the semantic entity name is exactly the same as the class name, the @SemanticEntity annotation is redundant. – Rick Pannekoek Oct 8 at 19:34
  • Your way to register the View Model looks fine to me. – Rick Pannekoek Oct 8 at 19:37

Your Answer

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

Browse other questions tagged or ask your own question.