3

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.

1 Answer 1

1

The thing you are observing with PageModel.meta is a Known Issue. See https://github.com/sdl/dxa-web-application-java/issues/21

However, if you want to use Page Metadata, you can better define your own Page Model and use semantic mapping for the metadata fields. Basically, what you also tried to do.

The missing step is that you should register your custom Page Model (using the @RegisteredViewModel annotation) and associate it with the Page View you are using.

2
  • I tried to do it in this way in the coreInitialicer: > @RegisteredViewModel(viewName = "MyViewName", modelClass = CustomPageModelImpl.class) But I continue with the same error. Do you know what is wrong? Commented Sep 20, 2016 at 8:07
  • I don't see anything obviously wrong. Try debugging; the code to instantiate custom Page Model Types based on View Model Registration is in method createPageModel in github.com/sdl/dxa-web-application-java/blob/release/1.5/… Commented Oct 11, 2016 at 17:38

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.