cancel
Showing results for 
Search instead for 
Did you mean: 

problem with ftl template.

need
Champ in-the-making
Champ in-the-making
Hi all,

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.
13 REPLIES 13

need
Champ in-the-making
Champ in-the-making
ok thanks and sorry,

I tried the solution suggested by you and in your template gave me modelli.status not definied (I understand why), however, to go forward I removed the if block (the template) and in dashlet displays data correctly.

But now I have another problem that I can not fix, every time I add a new aspect to me is this error:

Error Message: 09100001 Failed to execute script 'classpath*:alfresco/web-extension/site-webscripts/org/alfresco/components/dashlets/getmodel.get.js': 09100000 SyntaxError: missing ] after element list (file:/C:/Alfresco/tomcat/shared/classes/alfresco/web-extension/site-webscripts/org/alfresco/components/dashlets/getmodel.get.js#3(eval)#5)

and this exception

Exception: org.mozilla.javascript.EcmaError - SyntaxError: missing ] after element list (file:/C:/Alfresco/tomcat/shared/classes/alfresco/web-extension/site-webscripts/org/alfresco/components/dashlets/getmodel.get.js#3(eval)#5)

and this is my js controller file


var connector = remote.connect("alfresco");
var data = connector.get("/let/modelli");
var result = eval('(' + data + ')');
model.result = result;

If i refresh the page http://127.0.0.1:8080/alfresco/service/let/modelli see correctly
{"modelli" : [
        {"name" : "consulente.xls",
         "link" : "\/alfresco\/d\/d\/workspace\/SpacesStore\/b632375f-e6a1-40e2-a2ee-dd858a4f8dc2\/consulente.xls",
        }
        {"name" : "doc1.doc",
         "link" : "\/alfresco\/d\/d\/workspace\/SpacesStore\/1019756f-4624-4ee7-8095-c78f57209560\/doc1.doc",
        }
]
}

Thanks all.

scouil
Star Contributor
Star Contributor
I actually never used the remote API so I don't really know how to use it.
Removing the "if" block works as long as the "remote.call" returns the expected result but you should find a way to retrieve and handle the errors.

Your current error is due to an error in your JSON syntax.
First:
You only got comas as long as the attribute isn't the last one in the object. e.g.
{"first":1,  //here is a coma
"last":2    //no coma
}
so none of your "link" attributes shouldn't end with a coma since these are the last attributes of the object.

Second:
In an array, the objects should, once again, be separated by comas. e.g.
{"myArray": ["first":1,
                   "last":2} , //here is a coma
                  {"first":1,
                    "last":2}  //no coma (last object of the array)
                   ]

Considering these rules, your json output should be:

{"modelli" : [
        {"name" : "consulente.xls",
         "link" : "\/alfresco\/d\/d\/workspace\/SpacesStore\/b632375f-e6a1-40e2-a2ee-dd858a4f8dc2\/consulente.xls"
        },
        {"name" : "doc1.doc",
         "link" : "\/alfresco\/d\/d\/workspace\/SpacesStore\/1019756f-4624-4ee7-8095-c78f57209560\/doc1.doc"
        }
]
}

need
Champ in-the-making
Champ in-the-making
Thank you for your immense availability,

use alfresco recently, I find it a powerful, yet extremely complex at the beginning to start to understand its mechanisms for the development and customization, this is because around documentation very scattered and not always updated.

Even with this discussion I'm learning a lot and is very useful for me to understand certain mechanisms.

Now I ask you an opinion, you think to do what I'm doing (view in a dashlets all docs who have a particular aspect), it is conceptually wrong to use the method I'm using? Is there any other method more effective to do this? I use this method because the documentation I found online seemed the only valid for my problem.

scouil
Star Contributor
Star Contributor
I'm usually more of an online-doc guy but for Alfresco, starting with books was an awesome plus.
I particularly liked Alfresco Developer guide by Jeff Potts (who's now the head of Alfresco community).

About what you're doing, I don't know all your needs so I can't really tell you but my advice would be to stick with alfresco's default UI.
If you start developing your own UI, your users will keep on asking for new features until your dashlet is no longer maintainable.
Alfresco Share's default interface is nice and powerful.
So before trying to develop your own alfresco share through an ecosystem of dashlets, have a look at what Alfresco can do out of the box.

Good luck,