8

I am trying to get some information from Dynamic Component Presentation through a Java program.

I have published Dynamic Component called ABCD from Tridion 2011 SP1.

Do we have any tutorials online to learn from?

6

I am not sure you'll find something close to a tutorial, most of the active bloggers/participants in the Tridion Community learned how to do this before there was an active online community.

Things to take into consideration:

  • Make sure you have a working developer environment with Tridion loaded. Given you're using Java, I'd like to point you to this page where I explain how to get Tridion to run inside Eclipse.
  • Try to understand the difference between ComponentPresentationFactory and ComponentPresentationAssembler. If your DCP has any dynamic code in it (like dynamic linking) then you should use ComponentPresentationAssembler.
  • Check the official Documentation - I just did a quick search on LiveContent for ComponentPresentationAssembler on the 2013 doc and got 8 pages with examples.
  • It's a lot easier to load a DCP if you know its ID. If you don't know the ID, and all you know is - for instance - the title, then you'll have to play around with the Criteria classes to run a query.

And, of course, don't forget to ask here whatever else you find that gets you stuck.

5

Quick References on Dynamic Component Presentations:

Use either ComponentPresentationAssembler or ComponentPresentationFactory depends on your usage.

ComponentPresentationAssembler:

Use the ComponentPresentationAssembler class to execute any code in the Component Presentation, then add the result to the Web page.

The ComponentPresentationAssembler class assembles Dynamic Component Presentations on a Page. You can use the Component Presentation Assembler to dynamically add content of Dynamic Component Presentations to the content of your Page. The Component Presentation Assembler invokes handlers for JSP, ASP and XML/XSLT content.

Example:

<%@ page import="com.tridion.web.jsp.JSPPage, com.tridion.web.jsp.ComponentPresentationAssembler" %>
<%
  JSPPage dcdPage = new JSPPage(pageContext, "tcm:28-834-64");
  ComponentPresentationAssembler cpAssembler = new ComponentPresentationAssembler(dcdPage);
  out.println(cpAssembler.getContent("tcm:28-780","tcm:28-821-32"));
%>

ComponentPresentationFactory:

Use the ComponentPresentationFactory class to add Component Presentation content 'as is' to a Web page.

To retrieve raw Component Presentation content, first create a Component Presentation Factory:

ComponentPresentationFactory factory = new ComponentPresentationFactory();

Example:

<%@ page import="com.tridion.dynamiccontent" %>
<% 
  ComponentPresentationFactory cpf = new ComponentPresentationFactory("tcm:0-1-1"); // Publication URI
  // Component URI and Component Template URI
  ComponentPresentation componentPresentation = cpf.getComponentPresentation("tcm:1-234", "tcm:1-345:32");
  out.println(componentPresentation.getContent());
%>

*Content is taken from SDLLiveContent

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.