0

I've created a compound document type called SampleCaps in a HippoCMS 7.9 site and set out to build a template for it. In the process, I added hst:sitemap nodes, a pair of nested hst:pages nodes, and an hst:templates node. I also added the appropriate type property to hippo:namespaces/barcom/SampleCaps.

Finally, I created a Component and a Bean to expose the document data to the template, adapting the steps presented in part 2 of the Hippo Video Trails.

To my frustration, while the Component loads properly the Bean is never loaded (or at least, its getter is never called.) My component and bean are as follows:

site/src/main/java/com/footech/barcom/components/SampleCapsComponent.java:

package com.footech.barcom.components;

import com.footech.barcom.beans.SampleCapsDocument;
import org.hippoecm.hst.content.beans.standard.HippoBean;
import org.hippoecm.hst.component.support.bean.BaseHstComponent;
import org.hippoecm.hst.core.component.HstComponentException;
import org.hippoecm.hst.core.component.HstRequest;
import org.hippoecm.hst.core.component.HstResponse;

public class SampleCapsComponent extends BaseHstComponent {
    @Override
    public void doBeforeRender(final HstRequest request, final HstResponse response) throws HstComponentException {
        SampleCapsDocument document = request.getRequestContext().getContentBean();
        request.setAttribute("document", document);
        System.out.println("Ping"); /* prints "Ping" to console */ 
    }
}

site/src/main/java/com/footech/barcom/beans/SampleCapsDocument.java:

package com.footech.barcom.beans;
import java.util.Calendar;

import org.hippoecm.hst.content.beans.Node;
import org.hippoecm.hst.content.beans.standard.HippoHtml;
import org.onehippo.cms7.essentials.dashboard.annotations.HippoEssentialsGenerated;

@HippoEssentialsGenerated(internalName = "barcom:SampleCapsdocument")
@Node(jcrType = "barcom:SampleCapsdocument")
public class SampleCapsDocument extends BaseDocument {

    @HippoEssentialsGenerated(internalName = "barcom:title")
    public String getTitle() {
        System.out.println("Pong"); /* This never triggers */
        return getProperty("barcom:title");
    }
}

To my understanding, the annotation @Node(jcrType = "barcom:SampleCapsdocument") in SampleCapsComponent.java should hint to the compiler that the content node should be wrapped with the SampleCapsDocument bean - this does not appear to be the case, as the debug console prints Ping but not Pong. What am I doing wrong?

Winfield Trail
  • 5,535
  • 2
  • 27
  • 43

1 Answers1

2

you'll need to call document.getTitle() because values are lazy loaded.

grunfy
  • 161
  • 1
  • 2
  • If this works I'm going to spontaneously zombify and eat my own brains. I tried that last night but this was before fixing an issue in my sitemap and I never thought to try again. – Winfield Trail Mar 24 '15 at 14:03
  • After a lot of playing with it I realized my `sitemapitem` node was missing its `hst:componentconfigurationid` value. After fixing this, I determined that no matter what attributes I set with `request.setAttribute()` they are not available in the JSP context... even passing string literals doesn't work. Inspection of the Request variable through the debugger seems to indicate the attributes aren't being saved. Any thoughts? – Winfield Trail Mar 25 '15 at 03:36
  • The problem I described in the second comment was an unrelated configuration problem (hst:componentclassname property was set in hst:pages/SampleCaps node, not hst:pages/SampleCaps/main as it should have been.) Marijan's answer is correct after all. – Winfield Trail Mar 26 '15 at 15:26