Skip to main content

How can I get a Component in Structure Group metadata?

UPDATED

We haven't found a solution, and we think every step is right. What are we missing??

Core Initializer: @RegisteredViewModel(viewName = "myPage",modelClass = CustomPageModelImpl.class)

CustomPageModelImpl: @SemanticEntity(entityName = "myPage", vocabulary = SDL_CORE, prefix = "m") public class CustomPageModelImpl extends PageModelImpl {}

myPage.jspx

JAVA ERROR: PageModelImpl cannot be cast to CustomPageModelImpl


I need to get a component included in Structure Group metadata. To have this information in the page I include the template "Add inherited metadata to page" in the page template and I can see in the JSON the value of that metadata:

MetadataFields":{"promotion":{"Name":"promotion","Values":["tcm:47-129384"],"NumericValues":[],"DateTimeValues":[],"LinkedComponentValues":...

The problem that I have is when I try to get that information in the view:

${pageModel.meta["promotion"]}

I am using dxa 1.5 with Java.

I tried to extend the PageModelImpl as an Entity to get the Metadata creating a "CustomPageModelImpl":

@SemanticEntity(entityName = "MyPage", vocabulary = SDL_CORE, prefix = "m") public class CustomPageModelImpl extends PageModelImpl { [...] }

And using this entity as a Bean in the Page view:

jsp:useBean id="pageModel" type="com.dxa.api.model.entity.CustomPageModelImpl" scope="request"

It returns an error when the page load:

ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/web].[jsp]] (http-localhost/127.0.0.1:8080-1) JBWEB000236: Servlet.service() for servlet jsp threw exception: java.lang.ClassCastException: com.sdl.webapp.common.api.model.page.PageModelImpl cannot be cast to com.dxa.api.model.entity.CustomPageModelImpl

How can I get the TCM of the component included in SG metadata? or how can I get the information of that component?


Edited: I think that my issue can be here:

@SemanticEntity(entityName = "MyPage", vocabulary = SDL_CORE, prefix = "m")

I am not sure what I have to write in the "entityName" param.