JavaScript & Java classes

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2012 08:49 AM
Hi there
I have some code that parses an Excel spreadsheet. There is a parse() method on my service that takes a NodeRef (which would point to the uploaded spreadsheet). It returns an object graph of POJOs. The method signature looks like this:
MyConfiguration parse(NodeRef workbook) throws MyException;
I wrapped this code in an Action and this works fine. I would now like to expose this same functionality via server side JS. I extended BaseProcessorExtension and registered the extension via Spring.
I have the following JS code:
This works. I see a bunch of debug logging in the logfile that confirms that the spreadsheet has been parsed and the values transposed into a MyConfiguration object.
Now if I try this..
..this fails. The variable cfg is reported as being null even though I can see that the spreadsheet was parsed OK via logging.
Are there any restrictions re exposing custom Java objects in JS that I should be aware of?
Thanks
Mark
I have some code that parses an Excel spreadsheet. There is a parse() method on my service that takes a NodeRef (which would point to the uploaded spreadsheet). It returns an object graph of POJOs. The method signature looks like this:
MyConfiguration parse(NodeRef workbook) throws MyException;
I wrapped this code in an Action and this works fine. I would now like to expose this same functionality via server side JS. I extended BaseProcessorExtension and registered the extension via Spring.
I have the following JS code:
myextn.parse(document);
This works. I see a bunch of debug logging in the logfile that confirms that the spreadsheet has been parsed and the values transposed into a MyConfiguration object.
Now if I try this..
var cfg = myextn.parse(document);// should execute the method MyService.getSomeProperty()logger.log(cfg.someProperty);
..this fails. The variable cfg is reported as being null even though I can see that the spreadsheet was parsed OK via logging.
Are there any restrictions re exposing custom Java objects in JS that I should be aware of?
Thanks
Mark
Labels:
- Labels:
-
Archive
2 REPLIES 2
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2012 09:09 AM
Yes there are some fairly stringent limitations.
The first is how "MyConfiguration" will be exposed to JavaScript. From memory, some very basic collections will be mapped, otherwise it will require some custom mapping.
When I'm witing a java script extension, I tend to add a "script" object that converts from a Java object to a script object. It can also hide any bits that can't work with script or add helper methods if required.
The first is how "MyConfiguration" will be exposed to JavaScript. From memory, some very basic collections will be mapped, otherwise it will require some custom mapping.
When I'm witing a java script extension, I tend to add a "script" object that converts from a Java object to a script object. It can also hide any bits that can't work with script or add helper methods if required.

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2012 06:24 AM
Thanks for that. I ended up adding a new Script object (implementing Scopeable) and as I was doing this found a silly bug in my JS extension that was the cause for the NPE. It's always the obvious error.. 🙂
