cancel
Showing results for 
Search instead for 
Did you mean: 

Access Custom Java Spring Bean from Javascript

twizzel
Champ in-the-making
Champ in-the-making
Hey,

This is a bit of a weird question, so please bear with me.

Ok, I have a custom Java class (Spring Bean) that contains some code to do some stuff. What I am trying to do is add this Spring Bean to Alfresco and allow other developers to access methods this Spring Bean contains using Javasrcipt.

My question is how do I do this? I'm told it is possible using Alfresco config files but documentation seems to be lacking in this particular area.

What I have done so far is pretty much follow the steps in this little guide : http://wiki.alfresco.com/wiki/Overriding_Spring_Configuration

I have packaged my code into a lovely little Jar file and placed it in the following folder in Alfresco : Alfresco\tomcat\webapps\alfresco\WEB-INF\lib

I then added the following file to Alfresco : Alfresco\tomcat\shared\classes\alfresco\extension\dev-context.xml

It's contents are as follows :

<?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="myServiceBean" class="com.company.service.MyService"></bean>

</beans>
Finally I restarted the Alfresco server.

Is this all I need do to make my Spring Bean acessable via Javascript?


T
5 REPLIES 5

lotharmärkle
Champ in-the-making
Champ in-the-making

twizzel
Champ in-the-making
Champ in-the-making
Hey Lothar,

Thanks for the reply. Ok I had a look at those posts and I think all my configuration is set up fine.

However when I try to run things from Javascript I get problems.

My bean definition looks like this :

<beans>
    <bean id="myServiceBean" class="com.company.service.MyService">
        <property name="extensionName">
            <value>myService</value>
        </property>
    </bean>
</beans>

Then on the java script side of things I do the following :

var result = myService.doSomething();
alert(result);

But when I do this I get an error message saying : myService is undefined


Am I missing a step, do to have to import some reference to the service bean I created on the javascript side, or initialise it or something?

Any help would be greatly appreciated.


T

mitpatoliya
Star Collaborator
Star Collaborator
It seems like your myService is not registered properly.
Where you have done that entry?
also that bean should contain the API called doSomething().

lotharmärkle
Champ in-the-making
Champ in-the-making
I think what mitpatoliya meant was, that you need to define your bean with a parent:

<bean id="myServiceBean" class="com.company.service.MyService" parent="baseJavaScriptExtension">
        <property name="extensionName">
            <value>myService</value>
        </property>
</bean>

monicargrp
Champ in-the-making
Champ in-the-making
Hi, Twizzel!

Did you solve this problem? I have exactly the same one. Could you please help me?

Thanks.