6

I am not able to read field of component from page-template using dd4t,

I want to read component --> metadata --> embedded schema --> embedded field

<c:forEach var="componentPresentations" items="${pageModel.componentPresentations}" varStatus="status">
  <c:if test="${componentPresentations.componentTemplate.title == 'Component Template [4 Column]'}">
    <c:out value ="${componentPresentations.component.metadata[1].value.embeddedValues[0].content[0].key['key']}" />
  </c:if>
</c:forEach>

I am just able to access component from line 3 given

<c:out value ="${componentPresentations.component}"/>

How do i access field of component from page?

Page --> component --> metadata --> embedded schema --> embedded field

1 Answer 1

1

I guess you need to target your component itself. as you are getting the component using 3rd line. try to check the tracings in IDE.

Also, when you loop through all the component presentation, try to get component from component presentation then convert to model. Do something like this:

public static <MethodName> findByPage(GenericPage page) throws ModelException {
    for (ComponentPresentation componentPresentation :   page.getComponentPresentations()) {
        GenericComponent component = componentPresentation.getComponent();
        if ("<rootElementName>".equals(component.getSchema().getRootElement())) {
            return (<PageName>) ModelFactory.createInstance(component);
        }
    }

    return null;
}
2
  • sorry for late reply, thanks for suggestion, i created method to read components from the page :) . Commented Mar 17, 2016 at 8:07
  • Cool. Happy that you got solution. Commented Mar 29, 2016 at 20:52

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.