cancel
Showing results for 
Search instead for 
Did you mean: 

Alfresco 4.x Share custom page with Java backed script load

m_scapoli
Champ in-the-making
Champ in-the-making
Hi there!

I'm trying, and partially done, to extend Alfresco 4.0c with an action that load a new page (in the style of alfresco's pages) and load a certain webscript that I have written but when I try to load the webscript I run into Web Script Status 500 - Internal Error

I was inspired by the DocumentGeographicDetails and with some "reverse engineering" I could create a new action and link that to a new page declaration, then I unsuccessful try to recall a Java backed Script (that it works when I call it separately) in a certain region <region-id>doclib-custom</region-id> at the end of  template-instances.xml

[img]http://desmond.imageshack.us/Himg801/scaled.php?server=801&filename=docdiffaction.png&res=medium[/img]

[img]http://desmond.imageshack.us/Himg99/scaled.php?server=99&filename=docdiffpage.png&res=medium[/img]

[img]http://desmond.imageshack.us/Himg338/scaled.php?server=338&filename=jsonresponse.png&res=medium[/img]

I've tryed to load the script in the <region-id>doclib-custom</region-id> at the end of  template-instances.xml
alfresco/web-extension/template-instances/document-diff.xml

<?xml version='1.0' encoding='UTF-8'?>
<template-instance>
   <template-type>org/alfresco/document-details</template-type>
   <properties>
      <pageFamily>documentlibrary</pageFamily>
      <container>documentLibrary</container>
   </properties>
   <components>

      <!– Title –>
      <component>
         <region-id>title</region-id>
         <sub-components>
            <sub-component id="default">
                               …
                               …
                               …

      <!– Custom Component –>
      <component>
         <region-id>doclib-custom</region-id>
         <url>/components/diffhook</url>
         <!–<url>/components/documentlibrary/doclib-custom</url>–>
      </component>

   </components>
</template-instance>

alfresco/web-extension/site-webscripts/ext/documentdiff/components/diffhook.get.desc.xml

<webscript>
   <shortname>Document Diff Hook</shortname>
   <description>document-diff hook for declarative.json</description>
   <family>family_docdiff_hook</family>
   <url>/components/diffhook</url>
</webscript>
alfresco/web-extension/site-webscripts/ext/documentdiff/components/diffhook.get.html.ftl
<div>${diffhook.msg}</div>
the .msg try to hook at the repo-extension project that is simply the Simple Declarative Web Script Project from the Java backed Wiki page…
alfresco/web-extension/site-webscripts/ext/documentdiff/components/diffhook.get.js

var connector = remote.connect("alfresco/service");
var data = connector.get("/documentdiff/declarative.json");

// create json object from data
var result = eval('(' + data + ')');
model.diffhook = result["declarative"];

I also tryed to work adding additional region with the <@region> directive as it is written in the David Draper's - Customizing Alfresco Share FreeMarker Templates but without results. I tryed to recall the same "Hello World" script code in my custom page above under the node-header region with this code but don't work

alfresco/web-extension/site-data/extensions/docdiff-extension.xml

<module>
    <id>Blog Module (Add Region)</id>
    <customizations>
        <customization>
            <targetPackageRoot>org.alfresco</targetPackageRoot>
            <sourcePackageRoot>blog.demo.customization</sourcePackageRoot>
        </customization>
    </customizations>
</module>
alfresco/templates/blog/demo/customization/document-details.ftl

<@region id="additional-content" target="node-header" action="after" scope="global" />
alfresco/web-extension/site-data/components/global.additional-content.xml

<component>
    <region-id>additional-content</region-id>
    <source-id>global</source-id>
    <scope>global</scope>
    <uri>/blog/demo/new-content</uri>
</component>

certainly is my fault but the poor documentation and the wiki are of little help, thanks in advance to anyone responding to the question

Regards
4 REPLIES 4

erikwinlof
Confirmed Champ
Confirmed Champ
Hi,

Rather than referring to "the poor documentation and the wiki are of little help" please consider either come with a distinct list of requirements with what you miss in the documentation OR create and contribute it yourself after you have learned it. We are doing the best we can.

It is very hard to help you without knowing what the actual error is, you mind sending over the actual error you get in as much detail as possible?

However if I should guess what the error might be my vote would be that the following line:
var connector = remote.connect("alfresco/service");
should be:
var connector = remote.connect("alfresco");

Cheers, Erik

PS. If you haven't seen it there is a thread that contains Share documentation at:
https://forums.alfresco.com/en/viewtopic.php?f=48&t=43694

m_scapoli
Champ in-the-making
Champ in-the-making
Ok with the work in the morning I was able to load a Json Web Script in my page following these tutorials:
-How to access Alfresco repository in Alfresco Share December 2009
-Accessing Alfresco repository in Share February 2010
are practically the same thing with a small variation… this is the result:

[img]http://desmond.imageshack.us/Himg341/scaled.php?server=341&filename=docdiffpagejson.png&res=medium[/img]

what I'm trying to do is to load another Json Webscript called "Declarative" that is explained here: SimpleDeclarativeWebScript.java from Piergiorgio Lucidi Alfresco Partner that write the wiki spurred by another request

It is very hard to help you without knowing what the actual error is, you mind sending over the actual error you get in as much detail as possible?

here the error:
[img]http://desmond.imageshack.us/Himg214/scaled.php?server=214&filename=surferror.png&res=medium[/img]
it seems that the error is in the eval('(' + data + ')'); section:
alfresco/web-extension/site-webscripts/ext/documentdiff/components/diffhook.get.js

var connector = remote.connect("alfresco");
var data = connector.get("/documentdiff/declarative.json");

// create json object from data
var result = eval('(' + data + ')');
model.diffhook = result["declarative"];
alfresco/web-extension/site-webscripts/ext/documentdiff/components/diffhook.get.desc.xml

<webscript>
   <shortname>Document Diff Hook</shortname>
   <description>document-diff hook for declarative.json</description>
   <family>family_docdiff_hook</family>
   <url>/components/diffhook</url>
</webscript>
alfresco/web-extension/site-webscripts/ext/documentdiff/components/diffhook.get.html.ftl
<div>${diffhook.msg}</div>
to clarify I report the declarative.get.json.ftl from the Simple Declarative Web Script that show how it handle the json response..
{   "msg" : "Hello ${person.properties.userName}: ${speak}"}
However if I should guess what the error might be my vote would be that the following line:
var connector = remote.connect("alfresco/service");
should be:
var connector = remote.connect("alfresco");

Cheers, Erik
yep this was a try that I've forgotten in the code when I posted it, had already been corrected, thanks anyway
PS. If you haven't seen it there is a thread that contains Share documentation at:
https://forums.alfresco.com/en/viewtopic.php?f=48&t=43694
yes I've also seen this, I already knew many of the links thanks
Rather than referring to "the poor documentation and the wiki are of little help" please consider either come with a distinct list of requirements with what you miss in the documentation OR create and contribute it yourself after you have learned it. We are doing the best we can.
I apologize if I was not very fair, mine was just an opinion but imho it's very difficult to understand the Alfresco mechanism and "conventions over configuration", above all the AMP packaging practice (that none of the developers have used in the examples on his blog, this would help, for example), the maven alfresco archetype is in an ambiguous state (the wiki is not accurate pointing on outdated resources and bugged pom.xml and the documentation in this way it's poor)..
It 's very difficult to understand how things work through very old posts and understand what things are good and which ones to discard..
I do not know if it is totally my fault, maybe it is, but a reorganization of the documentation would help a lot so external developer would know exactly and easly what Alfresco development environment provides because this informations are only in your possession..

however, this remains an opinion and it will be further emphasized, do not worry

Thanks to all

erikwinlof
Confirmed Champ
Confirmed Champ
I would recommend running Share's javascript debugger and print out the value of "data" in the console.
http://localhost:8081/share/page/api/javascript/debugger
(If you get problem setting a break point try refreshing your webscript)

My guess is that what you get as result in data is a bunch of html saying that the webscript can't be found, and that the "eval" is trying to parse it as xml. Hopefully you will find an error message in the html from the "data" variable. If not, take a closer look at your declarative.get.desc.xml file and see if you can spot the problem, i.e the url isn't matching "/documentdiff/declarative" (or possibly that you have set the "format" to "html" even thought I doubt it).

Cheers and good luck, Erik

PS. I will make sure your thoughts are picked up by our community officer and documentation team.

m_scapoli
Champ in-the-making
Champ in-the-making
PS. I will make sure your thoughts are picked up by our community officer and documentation team.
thanks a lot  Smiley Happy

Sorry I forgot to update

FIX UPDATE: it's
model.diffhook = result;
and not
model.diffhook = result["declarative"];
because isn't a list but only one json object.