cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Josh2007 <josh070...@gmail.com>
Subject Re: How to access cocoon object from javascript scriptAction?
Date Wed, 10 Oct 2007 17:51:07 GMT

Sorry, everything is fine.
I use request.getSession() instead of objectModel.session and replace
objectModel.session.setAttribute("stream", stream) with
session.setAttribute("stream", stream) and it works.

Thanks again,

Josh



Josh2007 wrote:
> 
> Thanks Joerg, I'm almost done.
> 
> Not familiar with Java, I still need to get access to the session to store
> my xml.
> Using session =
> manager.lookup(Packages.org.apache.cocoon.environmentSession.ROLE); I get
> an error "no public instance called "ROLE".
> Furthermore I use objectModel to get sitemap instance and do
> objectModel.session.setAttribute(...) but I'm not sure about it's the good
> way.
> 
> Here's my scriptAction, if you have time to take a look.
> Thanks,
> 
> Josh
> 
> 
> // streamToSession
> /*
> get xforms post from stream and store the result 
> in session attribute "stream".
> */
> 
> // Step 1 — Retrieve helper "beans" from the BSF framework
> request = bsf.lookupBean( "request" )
> logger = bsf.lookupBean( "logger" )
> actionMap = bsf.lookupBean( "actionMap" )
> 
> objectModel = bsf.lookupBean( "objectModel" )
> manager = bsf.lookupBean( "manager" )
> 
> // Step 2 — Perform the action
> logger.debug( "START streamToSession.js" )
> 
> // 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 =
> manager.lookup(Packages.org.apache.excalibur.xml.dom.DOMParser.ROLE);
> resolver =
> manager.lookup(Packages.org.apache.cocoon.environment.SourceResolver.ROLE);
> source = resolver.resolveURI(uri);
> var is = new Packages.org.xml.sax.InputSource(source.getInputStream());
> is.setSystemId(source.getURI());
> return parser.parseDocument(is);
> } finally {
> if (source != null) resolver.release(source);
> }
> }
> 
> // ------------------------- getStreamToSession
> -----------------------------------------------------------------------------------------------------------------------------
> 
> // retrieve the XML
> var stream = loadDocument("cocoon:/stream");
> 
> // save stream in session
> var session = objectModel.session;
> objectModel.session.setAttribute("stream", stream);
> 
> //
> ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> 
> // Hello action always succeeds, and returns message
> actionMap.put( "scriptaction-continue", "" )
> actionMap.put( "message", "success!" )
> logger.debug( "END streamToSession.js" )
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-access-cocoon-object-from-javascript-scriptAction--tf4596915.html#a13140932
Sent from the Cocoon - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message