7

We are using DXA for Java.

We are trying to map a field that in Tridion is a Component Link field. Debugging the code, we see that is trying to resolve the component Link like a URL using ComponentLinkFieldConverter Class. But we want to map all the field in the linked component as data for use in the jsp of th entity.

We found this article: http://blog.trivident.com/2013/12/improving-link-resolving-in-dd4t/ But is talking about DD4T and I don't know if a similar option exists in DXA.

We checked the page json and it has all the information of the component and all the information of the linked Component.

How can we change the treatment for the ComponentLink?

18:19:17,956 ERROR [com.sdl.webapp.common.impl.mapping.SemanticMapperImpl] (http-localhost/127.0.0.1:8080-1) Exception while getting field data for: private com.tms.tms4web.baseline.common.model.entity.text.TextTitleSubDescrip com.tms.tms4web.baseline.common.model.entity.FeaturedContainer.featuredContainerText: com.sdl.webapp.dd4t.fieldconverters.UnsupportedTargetTypeException: Unsupported target class: com.tms.tms4web.baseline.common.model.entity.text.TextTitleSubDescrip
    at com.sdl.webapp.dd4t.fieldconverters.ComponentLinkFieldConverter.createComponentLink(ComponentLinkFieldConverter.java:56) [webapp-dd4t-1.0.0.jar:1.0.0]
    at com.sdl.webapp.dd4t.fieldconverters.ComponentLinkFieldConverter.getFieldValues(ComponentLinkFieldConverter.java:35) [webapp-dd4t-1.0.0.jar:1.0.0]
    at com.sdl.webapp.dd4t.fieldconverters.AbstractFieldConverter.getFieldValue(AbstractFieldConverter.java:15) [webapp-dd4t-1.0.0.jar:1.0.0]
    at com.sdl.webapp.dd4t.DD4TSemanticFieldDataProvider.getFieldData(DD4TSemanticFieldDataProvider.java:83) [webapp-dd4t-1.0.0.jar:1.0.0]
    at com.sdl.webapp.common.impl.mapping.SemanticMapperImpl$1.doWith(SemanticMapperImpl.java:68) [webapp-common-impl-1.0.0.jar:1.0.0]
    at org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:577) [spring-core-3.2.8.RELEASE.jar:3.2.8.RELEASE]
    at org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:554) [spring-core-3.2.8.RELEASE.jar:3.2.8.RELEASE]
    at com.sdl.webapp.common.impl.mapping.SemanticMapperImpl.createEntity(SemanticMapperImpl.java:47) [webapp-common-impl-1.0.0.jar:1.0.0]
    at com.sdl.webapp.dd4t.EntityBuilder.createEntity(EntityBuilder.java:80) [webapp-dd4t-1.0.0.jar:1.0.0]
    at com.sdl.webapp.dd4t.PageBuilder.createPage(PageBuilder.java:101) [webapp-dd4t-1.0.0.jar:1.0.0]
2

The DD4T templates used by the DXA do publish linked component data (by default 3 levels of linking), so the data is there on the front end.

It sounds like you are asking for functionality similar to what is described here for the .NET version.

From a product capability point of view this feature should also be present in the Java version (as they should be equivalent). However, as the Java version is not yet officially released, I would recommend that you ask Bart if this feature is developed yet, and if not perhaps even provide him some code to integrate.

  • Hi Will, do you know if it's possible to change this 3 levels configuration? In case of yes, where? Thank u! – tfinez Apr 17 '15 at 17:41
  • Yes its a standard DD4T TBB parameter value. I forget the exact name of the container TBB where it is specified, something like Publish/Render Component Data (this TBB will be in every Component Template)? – Will Price Apr 17 '15 at 21:10
2

It seems the Java version is not as equivalent as it should be at this point, since as you found right now a Component link is only mapped to a String & Link. Take a look at the createComponentLink methods in the com.sdl.webapp.dd4t.fieldconverters.ComponentLinkFieldConverter Class:

if (targetClass.isAssignableFrom(String.class)) {
    return url;
} else if (targetClass.isAssignableFrom(Link.class)) {
    final Link link = new Link();
    link.setUrl(url);
    return link;
} else {
     throw new UnsupportedTargetTypeException(targetClass);
}

It should however be quite straight-forward to implement support for linking to model classes, I suggest you take a look at how we solved it in the .NET version (see the DD4TModelBuilder class, lines 502-504).

(please note the answer Will Price gave, as the current released .NET version is missing the private methods GetCompLinks and GetCompLink in the DD4TModelBuilder.cs, the missing code is available in his answer here)

The createComponentLink method is called from the getFieldValues method in the same class inside a for loop, this is how the Java side handles the multi value options, so looks like you only need a GetCompLink method there.

Also note that a similar construct is found in the Class com.sdl.webapp.dd4t.DD4TSemanticFieldDataProvider, method getSelfFieldData. That looks to be specifically for Media items, but worth knowing its there.

  • 1
    Thank you, Bart. But we cannot find the equivalent class in java. It's quite different and we don't find the recursive method to process the componentLink. Could you help us? – Guskermitt Apr 15 '15 at 21:53
  • Even I have same issue....How to model a component link in Java+DXA – Huston Lopes Aug 25 '15 at 13:27

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.