In an older post from 2012, Albert Romkes explained ways to render Component Presentations with DD4T for .NET , namely with HTML helpers. For example:

  • @Html.RenderComponentPresentations()
  • @Html.RenderComponentPresentationsBySchema("ArticleSchema")
  • @Html.RenderComponentPresentationsByView("Article")
  • @Html.RenderComponentPresentationsByView(new[] {"Article", "FullArticle" })

Does DD4T for Java have similar functionality?

Background: I'm updating a content model which renders all Component Presentations in the "main content area" of the page. But I now have webpage metadata (seo fields) and other content to place in specific parts of the page (like partitioning CPs, but with Java DD4T).

1 Answer 1


Yes, but its different. In the dd4t-example-site, the connection between pageviews and componentviews isn't direct as in dotnet, but looped through the controller and the componentviews model. In dotnet, the pageview would use these helpers to render componentviews. In java, the controller pre-renders the componentviews (check the contentcontroller and the jspcomponenentviewhandler - they implement the rendering calls) and then passes on the bunch of rendered component html snippets to the page view.

If you want to do the "dotnet style" way, all you have to do is write an accessor class where the page view can call the jspcomponentviewhandler.

  • So this accessor class could include parameters for the Schemas and/or Component Templates similar to the dotnet style? The devs would then call this class to get the component views (e.g. functionally only CPs with Schema Banner go here). Jul 17, 2015 at 16:26
  • 1
    Yes exactly. The component presentations you're looking for are already available in the request, they're inside of the pagemodel. All you need to do is define how you'd like to render them (by schema, region, view, etc) and code the selection from the list. Once selected, you pass the component(presentation) to the componentviewhandler to render it into html and return it as a string. Jul 19, 2015 at 8:20
  • Okay, in the dd4t-example-site, I found the ContentController and JSPComponentViewHandler. @Rogier, is there an example accessor I can show the team (or what would its signature look like)? We're a little stuck on "you know, get me the CPs by this template." :-) Jul 24, 2015 at 14:42
  • Update: the team found <dd4t:componentpresentations view="view_name"/> which renders only Component Presentations that match a given view. There are also attributes for region, rootElement, and schema. We might have been on an earlier DD4T build and/or someone added this functionality. Jul 25, 2015 at 14:51
  • Sorry, don't have any real example code because i prefer to use the pre-rendered method (using the content controller to build the componentviews model, and then having the page view use the componentviews). There may be usable code for you in dd4t-2 though, which is probably where your team found that. Jul 27, 2015 at 8:55

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.