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

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;
}
| improve this answer | |
  • sorry for late reply, thanks for suggestion, i created method to read components from the page :) . – Neetesh Narvaria Mar 17 '16 at 8:07
  • Cool. Happy that you got solution. – Vikas Kumar Mar 29 '16 at 20:52

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.