Access Custom Java Spring Bean from Javascript

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2012 02:46 AM
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 :
Is this all I need do to make my Spring Bean acessable via Javascript?
T
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
Labels:
- Labels:
-
Archive
5 REPLIES 5
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2012 04:35 AM
Use this http://wiki.alfresco.com/wiki/4.0_JavaScript_API#Adding_Custom_Script_APIs
or that http://wiki.alfresco.com/wiki/4.0_JavaScript_API#Native_Java_API_Access to make your Java API available in scripts.
hth,
lothar
or that http://wiki.alfresco.com/wiki/4.0_JavaScript_API#Native_Java_API_Access to make your Java API available in scripts.
hth,
lothar

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2012 11:51 PM
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 :
Then on the java script side of things I do the following :
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
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
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2012 01:26 AM
It seems like your myService is not registered properly.
Where you have done that entry?
also that bean should contain the API called doSomething().
Where you have done that entry?
also that bean should contain the API called doSomething().
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2012 03:21 AM
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>

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2012 07:52 AM
Hi, Twizzel!
Did you solve this problem? I have exactly the same one. Could you please help me?
Thanks.
Did you solve this problem? I have exactly the same one. Could you please help me?
Thanks.
