2

We have implemented DD4T 1.31 using Java with the example website.

As per the dispatcher servlet the controller uses is:

<bean id="ContentController" class="org.dd4t.springmvc.controller.DynamicPageContentController" >
    <property name="componentViewManager"><ref bean="componentViewManager" /></property>                
</bean>

So when I check the code in DynamicPageContentController, the handleRequestInternal method is doing nothing but returning null. How does this work?

Additionally, I can see one more controller called DynamicPageController which does have code for handleRequestInternal but my question is if this controller is not mapped in dispatcher-servlet.xml then how it is getting executed?

Can some explain the the full request life cycle for the basic example page in the DD4T 1.31 Java example web site?

1 Answer 1

4

There is a file "urlmapping.xml" in WEB-INF. In the file, there is following code.

<bean id="dd4t" class="org.dd4t.springmvc.controller.DynamicPageController" parent="parent_controller">
        <property name="publication" value="25" />      
        <property name="subcontext" value="/dd4t" />                    
</bean>

The property "publication" is Tridion publication's ID, and "subcontext" should be the publication's "Publication URL".

There is also following code. Modify value "/dd4t/**/*" to your DD4T Web site's url, then DynamicPageController will be called.

<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    <property name="mappings">
        <value>
            /app/newslist.html=newslist
            /dd4t/**/*=dd4t
        </value>
    </property>
</bean>

Also, there is a bean element named "LinkResolver". It's "contextpath" property is added to URL generated by dynamic linking, so modify it to adjust to your environment.

DynamicPageContentController is used for rendering component template, and its "buildComponentViews" method is called from DynamicPageController's handleRequestInternal method, around line 132.

ComponentViews contentModel =
        contentController.buildComponentViews(pageModel, request,
                response);

Create a JSP in "/components/jsp" directory, and set the JSP's file name without extension on component template's metadata "view", then the JSP will be called if the component template is used on a page. An instance of "org.dd4t.contentmodel.ComponentPresentation" is generated automatically, and passed to the JSP by request's attribute. The attribute's key is defined in org.dd4t.springmvc.constants.Constants.COMPONENT_PRESENTATION_KEY. ("GenericComponent" might be passed to JSP instead of "ComponentPresentation" on version 1.31)

You can get all contents of a component from the instance's property, and output them by using scriptlet or EL. Following code is an example of component template's JSP.

ComponentPresentation cp = (ComponentPresentation)request.getAttribute(Constants.COMPONENT_PRESENTATION_KEY);%>
<h1 id="h-1"><%=cp.getComponent().getContent().get("heading").getValues().get(0) %></h1>

When creating page template, create JSP in "/pages/jsp" and set its file name on page template's metadata.

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.