cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joerg Heinicke <>
Subject Re: How to get same function as java loadDocument(cocoon:/your.pipeline) in javascript flow?
Date Sun, 07 Oct 2007 15:49:46 GMT
On 07.10.2007 11:15 Uhr, wrote:

> I am uncertain about scope in JavaScript.  I would never declare a
> variable inside a block and expect the variable to be available
> outside the block, but that rule is a LCD from using many programming
> languages.  If JS had an issue, this code should error about accessing
> a missing property "nodeValue" from a null object.

This is the actual reason. Even if it works at all (as you explain why 
it should not) the variable is declared only inside the loop and not 
available outside of it. Cocoon once had a feature to put non-declared 
variables into a global scope, but I thought this was somehow protected 
during method execution. Anyway, this means that you have a local 
variable inside the loop - and a different global one, conincidentally 
with the same name, which never gets set. But in that case you really 
should get an exception since you access the nodeValue property of null.

The code has to change at least (besides possible DOM changes) to:

   var captchaUserEntries = root.getElementsByTagName("captcha");

   var captchaUserEntry;
   // get captcha node
   for (var i = 0; i < captchaUserEntries.getLength(); i++) {
       captchaUserEntry = captchaUserEntries.item(i);

   // get required content
   var captchaUserContent = captchaUserEntry.nodeValue;

Or to avoid the meaningless looping do:

   var captchaUserEntries = root.getElementsByTagName("captcha");

   var captchaUserEntry =
     captchaUserEntries.item(captchaUserEntries.getLength() - 1);

   // get required content
   var captchaUserContent = captchaUserEntry.nodeValue;

(Both examples should have a check for the case there is no captcha 

Hope this helps,


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

View raw message