# Bean writer generates wrong code for multiable Resources

**URL:** <https://community.bloomreach.com/t/bean-writer-generates-wrong-code-for-multiable-resources/475>\
**Category:** Experience Manager (PaaS/OnPrem)\
**Created:** [October 8, 2018, 7:15am UTC](https://community.bloomreach.com/t/bean-writer-generates-wrong-code-for-multiable-resources/475 "2018-10-08T07:15:18Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![tonny](https://avatars.discourse-cdn.com/v4/letter/t/a88e4f/32.png) [@tonny](https://community.bloomreach.com/u/tonny)\
**Post date:** [October 8, 2018, 7:15am UTC](https://community.bloomreach.com/t/bean-writer-generates-wrong-code-for-multiable-resources/475/1 "2018-10-08T07:15:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jasper.floor](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/jasper.floor/32/28_2.png) [@jasper.floor](https://community.bloomreach.com/u/jasper.floor)\
**Post date:** [October 8, 2018, 1:12pm UTC](https://community.bloomreach.com/t/bean-writer-generates-wrong-code-for-multiable-resources/475/2 "2018-10-08T13:12:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tonny](https://avatars.discourse-cdn.com/v4/letter/t/a88e4f/32.png) [@tonny](https://community.bloomreach.com/u/tonny)\
**Post date:** [October 8, 2018, 1:19pm UTC](https://community.bloomreach.com/t/bean-writer-generates-wrong-code-for-multiable-resources/475/3 "2018-10-08T13:19:46Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![jasper.floor](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/jasper.floor/32/28_2.png) [@jasper.floor](https://community.bloomreach.com/u/jasper.floor)\
**Post date:** [October 8, 2018, 1:25pm UTC](https://community.bloomreach.com/t/bean-writer-generates-wrong-code-for-multiable-resources/475/4 "2018-10-08T13:25:55Z")

</div>

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

[https://issues.onehippo.com/browse/ESSENTIALS-1232](https://issues.onehippo.com/browse/ESSENTIALS-1232)

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

---

<div class="post-metadata">

**Author:** ![tonny](https://avatars.discourse-cdn.com/v4/letter/t/a88e4f/32.png) [@tonny](https://community.bloomreach.com/u/tonny)\
**Post date:** [October 8, 2018, 1:31pm UTC](https://community.bloomreach.com/t/bean-writer-generates-wrong-code-for-multiable-resources/475/5 "2018-10-08T13:31:37Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![jasper.floor](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/jasper.floor/32/28_2.png) [@jasper.floor](https://community.bloomreach.com/u/jasper.floor)\
**Post date:** [October 8, 2018, 1:47pm UTC](https://community.bloomreach.com/t/bean-writer-generates-wrong-code-for-multiable-resources/475/6 "2018-10-08T13:47:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jasper.floor](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/jasper.floor/32/28_2.png) [@jasper.floor](https://community.bloomreach.com/u/jasper.floor)\
**Post date:** [October 8, 2018, 1:50pm UTC](https://community.bloomreach.com/t/bean-writer-generates-wrong-code-for-multiable-resources/475/7 "2018-10-08T13:50:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tonny](https://avatars.discourse-cdn.com/v4/letter/t/a88e4f/32.png) [@tonny](https://community.bloomreach.com/u/tonny)\
**Post date:** [October 8, 2018, 2:01pm UTC](https://community.bloomreach.com/t/bean-writer-generates-wrong-code-for-multiable-resources/475/8 "2018-10-08T14:01:10Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![jasper.floor](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/jasper.floor/32/28_2.png) [@jasper.floor](https://community.bloomreach.com/u/jasper.floor)\
**Post date:** [October 8, 2018, 3:12pm UTC](https://community.bloomreach.com/t/bean-writer-generates-wrong-code-for-multiable-resources/475/9 "2018-10-08T15:12:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tonny](https://avatars.discourse-cdn.com/v4/letter/t/a88e4f/32.png) [@tonny](https://community.bloomreach.com/u/tonny)\
**Post date:** [October 8, 2018, 11:26pm UTC](https://community.bloomreach.com/t/bean-writer-generates-wrong-code-for-multiable-resources/475/10 "2018-10-08T23:26:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jasper.floor](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/jasper.floor/32/28_2.png) [@jasper.floor](https://community.bloomreach.com/u/jasper.floor)\
**Post date:** [October 9, 2018, 8:11am UTC](https://community.bloomreach.com/t/bean-writer-generates-wrong-code-for-multiable-resources/475/11 "2018-10-09T08:11:41Z")

</div>

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.

> **[Custom Binary Link Generation - Enterprise Java Content management system -...](https://www.onehippo.org/library/concepts/images-and-assets/custom-binary-link-generation.html)**
>
> Hippo Open Source Enterprise Content Management

---

<div class="post-metadata">

**Author:** ![tonny](https://avatars.discourse-cdn.com/v4/letter/t/a88e4f/32.png) [@tonny](https://community.bloomreach.com/u/tonny)\
**Post date:** [October 9, 2018, 12:46pm UTC](https://community.bloomreach.com/t/bean-writer-generates-wrong-code-for-multiable-resources/475/12 "2018-10-09T12:46:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tonny](https://avatars.discourse-cdn.com/v4/letter/t/a88e4f/32.png) [@tonny](https://community.bloomreach.com/u/tonny)\
**Post date:** [October 9, 2018, 2:08pm UTC](https://community.bloomreach.com/t/bean-writer-generates-wrong-code-for-multiable-resources/475/13 "2018-10-09T14:08:36Z")

</div>

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](https://www.onehippo.org/library/concepts/images-and-assets/content-disposition.html)

---

<div class="post-metadata">

**Author:** ![jasper.floor](https://yyz1.discourse-cdn.com/flex027/user_avatar/community.bloomreach.com/jasper.floor/32/28_2.png) [@jasper.floor](https://community.bloomreach.com/u/jasper.floor)\
**Post date:** [October 9, 2018, 2:59pm UTC](https://community.bloomreach.com/t/bean-writer-generates-wrong-code-for-multiable-resources/475/14 "2018-10-09T14:59:15Z")

</div>

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