cancel
Showing results for 
Search instead for 
Did you mean: 

How to write a java backed dashlet in alfresco3.4.c

rasharma
Champ in-the-making
Champ in-the-making
Hello

I had downloaded alfresco 3.4.c and successfully added few custom dashlets helloworld and weather dashlet.
I need to write a java backed dashlet. I am trying from last 2 days without success.
Can not figure out where to place the class file of SimpleWebScript in share/webinf/classes or alfresco/webinf/classes.

Sample code of java backed dashlet will help.

Can anybody plz share sample code……

I was tring to add following sample:

package org.alfresco.module.demoscripts;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.extensions.webscripts.AbstractWebScript;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
import org.springframework.extensions.webscripts.WebScriptResponse;

public class SimpleWebScript extends AbstractWebScript {
   public void execute(WebScriptRequest req, WebScriptResponse res)
         throws IOException {
      try {
         // build a json object
         JSONObject obj = new JSONObject();

         System.err
               .println("*************************************************");
         System.err.println("Rahul is here");
         System.err
               .println("*************************************************");
         // put some data on it
         obj.put("field1", "data1");

         File f = new File("C:\\Users\\rasharma\\Desktop\\test.txt");
         FileOutputStream fop = new FileOutputStream(f);

         if (f.exists()) {
            String str = "This data is written through the program";
            fop.write(str.getBytes());

            fop.flush();
            fop.close();
            System.out.println("The data has been written");
         }

         else
            System.out.println("This file is not exist");

         // build a JSON string and send it back
         String jsonString = obj.toString();
         res.getWriter().write(jsonString);
      } catch (JSONException e) {
         throw new WebScriptException("Unable to serialize JSON");
      }
   }
}



<webscript>
  <shortname>The World's Simplest Webscript</shortname>
  <description>Hands back a little bit of JSON</description>
  <url>/components/dashlets/simple</url>
  <authentication>none</authentication>
  <family>dashlet</family>
</webscript>



Thanks.
Rahul
6 REPLIES 6

rasharma
Champ in-the-making
Champ in-the-making
I am sorry but I am still not able to figure out how to do this?

Can anybody help?


Thanks…

mrogers
Star Contributor
Star Contributor
One option is to put your classes into shared/classes.
(so shared/classes/org/alfresco/module/demoscripts)

Another is to Jar all your extensions up and put the jar into shared/lib.
Or you can Deploy them as an AMPs.

tommahy001
Champ in-the-making
Champ in-the-making
Hi,

i have been looking for hours on how to do this.

I have used webscripts before. I have built java backed webscripts on spring surf before. This all worked fine.
But a simple java-backed dashlet web script does not work.

Here is what i have done.

ive got a class. simple.Active


public class Active extends DeclarativeWebScript{
   
    Map<String, Object> model = new HashMap<String, Object>();

    public Map<String, Object> executeImpl(WebScriptRequest req, WebScriptResponse res) throws IOException {
       
        model.put("content", "value");
        return model;

    }
}

under webapps/share/WEB-INF/classes/org/springframework/extensions/webscripts/
i have a file web-scripts-application-context.xml


<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>

<beans>

    <bean id="webscript.site-webscripts.org.alfresco.components.dashlets.simple.active.active.get"
            class="simple.Active" parent="webscript">
    </bean>
   
</beans>

and i have the ftl and declaration under : webapps/share/WEB-INF/classes/alfresco/site-webscripts/org/alfresco/components/dashlets/simple/active/

two files:
active.get.desc.xml


<webscript>
    <shortname>active-dashlet</shortname>
    <description>active dashlet</description>
    <family>user-dashlet</family>
    <url>/active</url>
</webscript>

and active.get.html.ftl

RESULT !!! <#if content?exists>${content}</#if>

Dashlet appears in share just fine. Just it never gets into the java code.
I have tried jpda debugging, but no use since it doesnt get this far.

The class file is build and put into a jar under share/WEB-INF/lib/
Its there and doubled checked that the file is correct inside. I can see no problems.

any help would be appreciated.

Thank you

michaelc
Champ on-the-rise
Champ on-the-rise
I am no expert but 
  I call most of my back end processes as a service, looks like the method that is used in most areas of share.

  So from a page I may call my servlett that returns a JSON object. from the back end I can have a javascript module that will call the servlett as a restful service and receive back JSON.

tommahy001
Champ in-the-making
Champ in-the-making
Hi,

I see where you are coming from, but we want to minimize all contact to the backend.

I just dont see why it wouldnt work here and fine on a spring surf platform.
I thought share was build on spring surf.

dejal33t
Champ in-the-making
Champ in-the-making
Has anyone found a solution for this problem?
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.