Bean writer generates wrong code for multiable Resources

Bean writer generates the following code for multiable Resources:

@HippoEssentialsGenerated(internalName = “portal:uploadFiles”)
public List<HippoResourceBean> getUploadFiles() {
return getBeans(“portal:uploadFiles”, HippoResourceBean.class);
}

But the method “getBeans” is never defined in the hierarchy, and shoule it be “getLinkedBeans” instead?

I’m using ver. 12.4.0.

For a resource I think it should be getChildBeans, but getBeans indeed does not seem to exist.

Thanks a lot for your reply. Furthermore, may I know how to get the link of the uploaded resources in freemarker?
I tried:

<#list document.uploadFiles as file>
<@hst.link var=“fileURL” hippobean=file/>
</#list>

but can not get the correct url of the reources…

I’ve created an issue in Essentials for the method.

https://issues.onehippo.com/browse/ESSENTIALS-1232

I think your ftl code should work as is. What are you seeing?

I got the url like “/site/binaries/content/documents/portal/department/it/it/portal%3AuploadFiles”, but acturally it is a pdf file named “test.pdf”. I don’t know how to make a donwload link of the document in freemarker…

Actually, I think the correct method here might be org.hippoecm.hst.content.beans.standard.HippoItem#getChildBeansByName(java.lang.String, java.lang.Class) rather than getChildBeans. The first method allows you to give child node name, which is proabbly what you want here. Otherwise you may get more beans than you want (if there are other resource nodes in a different compound).

I’ve tried your ftl code and it works correctly for me.

I created an archetype project, added Simple Content via essentials, added a resource compound via document type editor, made it multiple. Adjusted a document to have resources. Used BeanWriter and adjusted the code to work with getChildBeansByName. Added your ftl to the template (contentpage-main.ftl), wihtout the var so it just prints. The correct urls are generated.

Could you try that in an archetype? It should work.

The “getChildBeansByName” really worked, but there’s still the problem for freemarker template.

Could you please try the following code, and check whether the html link works or not?
<#list document.uploadFiles as file>
<@hst.link var=“fileURL” hippobean=file/>
<a href="${fileURL}">

${file.filename}
</a>
</#list>

I think the code is just the same as the one of getting linked images, but for resources, I cannot get the documents (pdf files in my case).

My code is:

<#list document.hippo_resource as file>
  <@hst.link  var="link" hippobean=file/>
  <a href="${link}">
    ${file.filename}
  </a>
</#list>

java side

@HippoEssentialsGenerated(internalName = "myhippoproject:hippo_resource")
public List<HippoResourceBean> getHippo_resource_() {
    return getChildBeansByName("myhippoproject:hippo_resource",
            HippoResourceBean.class);
}

And this gives me links to the resources with the correct name.

But the url losts filename info. When right clicking the link and then saving the file, the name of the saved file is without any extension (.pdf. jpg and so on). The user may not know what the document is.

The problem is that links are generally generated as paths. In the assets folder the filename is part of the path, but in document the path is “myproject:resource”. You should be able to influence this with custom binary link generation.

I got it. Thanks a lot for your kind info., and I’ll try it later.

I found I can add some configurations in web.xml instead of creating customized ResourceContainer.

https://www.onehippo.org/library/concepts/images-and-assets/content-disposition.html

1 Like

Good find! Sorry, I don’t always have all the details at hand.