Compound types

114 views
Skip to first unread message

Hetvi Kotak

unread,
Jul 8, 2016, 6:53:36 AM7/8/16
to Hippo Community
Hi,
I am beginner to Hippo. I am using Hippo CMS 10.2.0 Community Edition. I have created new compound type in CMS. i.e. Custom Compound Type. I have used it in one existing document. Now I want to know that how should I render it the template of the existing document, in which i have used this compound type. I have written bean class for this compound type, but don't know how to render this compound type. 

I am posting code for compound type bean here. I have created Profile Compound type which includes image, Title(String), Designation(String), Description(text) fields in it.
***Starts here***
package org.example.beans;

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


@HippoEssentialsGenerated(internalName = "gogreen:gogreen_profile")
@Node(jcrType = "gogreen:Profile")
public class Profile extends HippoCompound  {
    @HippoEssentialsGenerated(internalName = "gogreen:string")
    public String getString() {
        return getProperty("gogreen:string");
    }
    
    @HippoEssentialsGenerated(internalName = "gogreen:string_")
    public String getString_() {
        return getProperty("gogreen:string_");
    }
    
    @HippoEssentialsGenerated(internalName = "gogreen:text")
    public String getText() {
        return getProperty("gogreen:text");
    }
    
    @HippoEssentialsGenerated(internalName = "gogreen:image")
    public Imageset getImage() {
        return getLinkedBean("gogreen:image", Imageset.class);
    }
}
***Ends Here***

can anyone suggest me whether this bean class is correct?,where should I place this bean class?, how should I use this methods in the template of the document in order to render this compound type fields.

Any help is appreciated.
Thanks in advance.

Jasper Floor

unread,
Jul 11, 2016, 4:07:45 AM7/11/16
to Hippo Community
HI,

The bean and the template need to be tied together. There is a third component which is the java Component class which needs to load the document on to the request. Though, if extending an existing document it probably is already put on the request. Then you can use the bean in your template like any other java bean.

Some of out tutorials may help. They start here[1].

mvg,
Jasper


--
Hippo Community Group: The place for all discussions and announcements about Hippo CMS (and HST, repository etc. etc.)
 
To post to this group, send email to hippo-c...@googlegroups.com
RSS: https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
---
You received this message because you are subscribed to the Google Groups "Hippo Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hippo-communi...@googlegroups.com.
Visit this group at https://groups.google.com/group/hippo-community.
For more options, visit https://groups.google.com/d/optout.

Jasper Floor

unread,
Jul 11, 2016, 4:47:10 AM7/11/16
to Hippo Community
Ah, I should've read more carefully.

So you shouldn't create a bean for a compound but for a document. This bean already exists for the document types in the project. If you are using essentials you can use the Bean Writer tool. Otherwise you will need to create the bean for the whole document. This still needs to be put on the request by a component of course. The class itself should be in your site war. It will be found as long as it is on the class path.

mvg,
Jasper

Hetvi Kotak

unread,
Jul 11, 2016, 6:58:51 AM7/11/16
to Hippo Community
Thanks Jasper for reply. I am able to do this configuration. Next thing is that bean Method returns single bean, but what if I want bean Method to return multiple beans, since there can be multiple instances of that compound type in the same document. What should be return type of the bean Method, and how  to iterate through multiple beans in the template in order to render it on the site.

 I am posting my Bean method which returns single bean, but I want it to return multiple beans.

 @HippoEssentialsGenerated(internalName = "gogreen:profile")
    public Profile getProfile() {
        return getBean("gogreen:profile");
    }

Please suggest me the return type for this bean Method and how to iterate it in the template for rendering on site.
Thanks in advance.

Jasper Floor

unread,
Jul 11, 2016, 8:34:50 AM7/11/16
to Hippo Community
Hi,
You can use:
public <T extends HippoBean> List<T> getChildBeansByName(String childNodeName, Class<T> beanMappingClass)

this is in the HippoDocument base class. So like your method but instead of getBean you get all beans matching that name and class.

How you loop through it in jsp with:

<c:forEach items="${document.profiles}" var="profile" >

Assuming your method is getProfiles and it returns a collection. Within the loop the specific profile will be in the variable named by "var", in this case profile.

mvg,
Jasper


--

Hetvi Kotak

unread,
Jul 12, 2016, 4:58:51 AM7/12/16
to Hippo Community
Thank you Jasper. I got your point. I tried and it is working.
Thanks again.

Regards,
Hetvi

Jasper Floor

unread,
Jul 12, 2016, 5:42:15 AM7/12/16
to Hippo Community
Glad to hear it works, thanks for letting us know.

mvg,
Jasper
Reply all
Reply to author
Forward
0 new messages