cancel
Showing results for 
Search instead for 
Did you mean: 

Consuming webscripts

thomasg
Champ in-the-making
Champ in-the-making
Hi,

I'm (considering) using spring surf and it would be great to understand how I can consume webscript executed on alfresco instance from a surf controller.
i.e.
- I create a template on a surf instance to display a form available from http://127.0.0.1:1234/page/form
- I want to populate this form with content delivered by a webscript available at http://127.0.0.1:8080/alfresco/s/form?id=69

How do I achieve that?
Would it be a better option to use Spring MVC without surf? If not what is the benefit of surf is?

Thanks!
Thomas
1 REPLY 1

thomasg
Champ in-the-making
Champ in-the-making
I found the answer in share.
to consume a webscript:

in the page definition (under /site-data/pages)

<page>
    <id>mypage</id>
    <template-instance>mypage</template-instance>
    <authentication>user</authentication>
    <components>
        <component>
            <region-id>form</region-id>
            <uri>/com/component/form-component</uri>
        </component>
    </components>
</page>

under template-instances

<?xml version='1.0' encoding='UTF-8'?>
<template-instance>
  <template-type>mypage</template-type>
    <components>
        <component>
            <region-id>form</region-id>
            <uri>/com/component/form-component</uri>
        </component>
    </components>

</template-instance>

under site-webscripts/com/component/
I can create my component

form-component.get.desc.xml
form-component.get.js

for desc.xml, see other example in the code
form-component.get.js will have something like:

    var nodeRef = page.url.args.nodeRef,
        metadata = [],
        connector = remote.connect("alfresco"),
        result = connector.get("/customwebscript/" + nodeRef);

    if (result.status == 200) {
        metadata = JSON.parse(result);
    }

    model.metadata = metadata;

in the template
form-component.get.html.ftl
use response from webscript with freemarkers:
${metadata.value1}