problem with ftl template.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2011 02:44 PM
I have a problem with a dashlet 3.4d with Alfresco Share. I have followed many tutorials but I can not solve my problem. Let me explain.
I created Alfresco webscripts makes me a search for all documents that have a certain aspect. and return a json and it works if I access the page http://localhost:8080/alfresco/service/let/modelli visualize the result in json format.
{"modelli" : [ {"name" : "consulente.xls", "link" : "\/alfresco\/d\/d\/workspace\/SpacesStore\/b632375f-e6a1-40e2-a2ee-dd858a4f8dc2\/consulente.xls", }]}
Now I have created a dashlet of Alfresco Share, which should see the list of documents that have a certain aspect.
Post the code for clarity:
- getmodel.get.desc.xml
<webscript> <shortname>Crea da modello</shortname> <description>Nuovo documento da modello esistente</description> <!– one of dashlet, site-dashlet or user-dashlet –> <family>dashlet</family> <url>/components/dashlets/getmodel</url></webscript>
- getmodel.get.html.ftl
<div class="dashlet"> <div class="title">Nuovo documento da modello esistente</div> <div class="body scrollableList"> <div class="detail-list-item first-item last-item"> <h5>Modelli di documento</h5> <table> <#list modelli as mod> <tr> <td><b>Name</b></td><td>${mod.name}</td> </tr> <tr> <td><b>Link</b></td><td><a href="${url.context}${mod.link}?guest=true">${url.context}${mod.link}</a></td> </tr> </#list> </table> </div> </div></div>
- getmodel.get.js
var connector = remote.connect("alfresco");var data = connector.call("let/modelli");if (data.status == 200) {var result = eval('(' + data + ')');model.modelli = result["modelli"];}else{ model.modelli="zzzz";}
And this is exception in tomcat log.
Exception: freemarker.template.TemplateException - Expected collection or sequence. modelli evaluated instead to freemarker.template.SimpleScalar on line 7, column 32 in org/alfresco/components/dashlets/getmodel.get.html.ftl.
I understand that the problem are in the ftl template file but I can not figure out how I can fix and what is wrong. Help me to understand?
Thank you all for the availability.
- Labels:
-
Archive
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2011 03:31 AM
Have you tried printing its value?
Cheers,
Jordi.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2011 03:48 AM
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2011 03:52 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2011 04:14 AM
In this case you enter in the "else" where model.modelli is assigned the string "zzzzzz" which converts into a freemarker.template.SimpleScalar.
I'm not sure what you're trying to do with this but, even in the "else", model.modelli should be an array or your html template will fail.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2011 04:18 AM
I have to change something in the connection string? (Let / modelli)?
Thank a lot.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2011 05:03 AM
var data = connector.get("/let/modelli");
It this doesn't work you can check what status code are you getting from your webscript.
Cheers,
Jordi.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2011 05:14 AM
So you should do
if (data.status.code == 200)
instead of if (data.status == 200)
But I would advise you to return the response in the modelli whatever the code is:
var connector = remote.connect("alfresco");var data = connector.call("let/modelli");var result = eval('(' + data + ')');model.modelli = result;
and handle the display in your html template<#if modelli.status.code == 200> <table> <#list modelli.response["modelli"] as mod> <tr> <td><b>Name</b></td><td>${mod.name}</td> </tr> <tr> <td><b>Link</b></td><td><a href="${url.context}${mod.link}?guest=true">${url.context}${mod.link}</a></td> </tr> </#list> </table><#else> Error ${modelli.status.code}: <br /> ${modelli.status.message}</#if>
I haven't tested it so it might be full of syntax errors but I hope you get the point.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2011 05:23 AM
But now I can print var data is returned: {"modelli" : [ {"name" : "consulente.xls", "link" : "\/alfresco\/d\/d\/workspace\/SpacesStore\/b632375f-e6a1-40e2-a2ee-dd858a4f8dc2\/consulente.xls", } ] }
Now how do I access from ftl template at variable name and link variable?
Thanks at all.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2011 05:33 AM
How about you give it a try on your own and come back posting here if you're actually stuck? I bet you'll get it to work with the first thing you'll try.
