cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Josh2007 <>
Subject Re: How to access cocoon object from javascript scriptAction?
Date Wed, 10 Oct 2007 11:44:05 GMT

Thanks for the information,

I took a look at ScriptAction's source code.
I have a better understanding of how it works but it seems I need to import
in my scriptAction other components and functions (DOMParser,

Actually I'm trying to adapt my flowscript code to a scriptAction as I need
to stay in the same sitemap after the execution of the javascript.

Here's the flowscript I'm trying to adapt.

// loadDocument() reads in an XML file and returns a DOM Document. 
function loadDocument(uri) {
var parser = null;
var source = null;
var resolver = null;
try {
parser =
resolver =
source = resolver.resolveURI(uri);
var is = new;
return parser.parseDocument(is);
} finally {
if (source != null) resolver.release(source);
if (parser != null) cocoon.releaseComponent(parser);
if (resolver != null) cocoon.releaseComponent(resolver);

// ------------------------- getStreamToSession

// retrieve the XML
var stream = loadDocument("cocoon:/stream");

// save stream in session
var session = cocoon.session;
session.setAttribute("stream", stream);


Of course, getComponent to load java components is undefined as I don't have
access to the class, the same with the parser.

I noticed that getComponent is part of org.apache.components.flow and
therefore not accessible from scriptAction.

I should be able to import java comonents with BSF. 

Do you have any idea how to do it?



Joerg Heinicke wrote:
> On 09.10.2007 17:13 Uhr, Josh2007 wrote:
>> I need to access cocoon object from a javascript scriptAction to make use
>> of
>> session, request... functions.
> The ScriptAction works more like a usual Cocoon Java component than like 
> flowscript. Therefore you have the ObjectModel available which is 
> actually only a Map. To access the stuff you need you use the 
> ObjectModelHelper and call the corresponding static methods like 
> getRequest() or getSession() [1]. If you have a look into ScriptAction's 
> source code (which is simple) you will see the other objects it 
> registers for usage in the JavaScript:
> mgr.registerBean("resolver", resolver);
> mgr.registerBean("objectModel", objectModel);
> mgr.registerBean("parameters", par);
> // ScriptAction housekeeping
> mgr.registerBean("actionMap", actionMap);
> // helpers
> mgr.registerBean("logger", getLogger());
> mgr.registerBean("request", ObjectModelHelper.getRequest(objectModel) );
> mgr.registerBean("scriptaction", this );
> mgr.registerBean("manager", this.manager );
>> It seems the only way to access cocoon object is to create a flowscript.
>> Is there another solution as I don't want to redirect to another pipeline
>> after the script is performed unlike flowscript does?
> The cocoon object is only a simplified version to access all the stuff 
> in the ObjectModel. It's indeed only available in flow script.
> Joerg
> [1] 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

View this message in context:
Sent from the Cocoon - Users mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message