You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Peter Bowman <Pe...@btopenworld.com> on 2004/01/09 19:17:58 UTC

JXTemplate forEach problem

Hi,

I have many pages in my application that use the JXTemplateGenerator to
iterate over collections of Javascript and Java objects passed from a Cocoon
flowscript.

However, after a reasonably short number of page impressions, instead of
iterating over the whole collection, only the first item in the list is
processed.

For example,

${collection}

<jx:forEach var="i" items="collection">
  ${i}
</jx:forEach>

Where the page is called by the flowscript:

var ob = new Object();
ob.collection = someCollection;

cocoon.sendPageAndWait("page.jxt", ob);

To start with, jx:forEach works as expected, and then, for no obvious
reason, it will only process the first element of "collection". I am sure
that the problem is with JXTemplate, because ${collection} just before the
jx:forEach tag will correctly show the whole collection.

I have the same problem with Cocoon 2.1 through 2.1.3. Am running under
JBoss 3.2.1 with embedded Tomcat 4.1.24.

Any ideas?

Thanks,
Pete Bowman.



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


RE: JXTemplate forEach problem

Posted by Antonio Gallardo <ag...@agsoftware.dnsalias.com>.
Peter Bowman dijo:
> Hi Antonio,
>
> After a day of development, I have had no further problems.
>
> Thanks for your help!

I am glad to help. Just one question.

The problem was solved: Without the changes I did or the changes helped to
solve the problem?

Best Regards,

Antonio Gallardo


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


RE: JXTemplate forEach problem

Posted by Antonio Gallardo <ag...@agsoftware.dnsalias.com>.
Hi Peter:

I use the same Java version (1.4.2_03). But my kernel is diferent:
2.4.22-1.2140.nptl (Fedora Core 1).

Anyway, I moved some variables outside the for cycle. Not a total
refactor, but maybe it would help. Can you test it again?

Best Regards,

Antonio Gallardo


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


RE: JXTemplate forEach problem

Posted by Antonio Gallardo <ag...@agsoftware.dnsalias.com>.
Hi Peter:

Based on your post, the code seems to be good. Anyway, I will review the
code again.

Can you tell me what version of Java and Linux are you using?

Best Regards,

Antonio Gallardo

Peter Bowman dijo:
> Hi Antonio,
>
> Thanks for your quick reply.
>
> I spent some time investigating this by adding lots of logging to
> JXTemplateGenerator.java.
>
> The problem appeared to be in the loop in execute() that dealt with
> forEach.
> I could get it to work by changing the "for (; i <= end &&
> iter.hasNext())"
> to a straightforward "while (iter.hasNext())", though as far as I can see
> the original loop should have worked ok. In fact, adding debug logging to
> the class showed that "i <= end && iter.hasNext()" was true just before
> the
> end of the loop, yet the loop still exited after one iteration, as though
> it
> evaluated to false in the for statement.
>
> for (; i <= end && iter.hasNext(); i++) {
> ...
>   System.out.println("Condition is ", new Boolean(i <= end &&
> iter.hasNext()).toString());
> }
>
> This would say "Condition is true", and then exit the loop!
>
> There was no obvious reason why it would work at first and then stop
> working
> permanently after 5-20 impressions. Perhaps it's a problem with Java on my
> platform (Linux), though I tried several versions and I would expect
> failures elsewhere too if that were the case.
>
> I checked out the CVS version, and that seems to work ok. I notice that
> from
> version 1.22, the way the loop is framed is different.
>
> Thanks,
> Pete.
>
>> -----Original Message-----
>> From: Antonio Gallardo [mailto:agallardo@agsoftware.dnsalias.com]
>> Sent: 10 January 2004 00:24
>> To: users@cocoon.apache.org
>> Subject: Re: JXTemplate forEach problem
>>
>>
>> Hi Peter,
>>
>> Can you upgrade to Cocoon CVS version. And check if there is
>> the problem too?
>>
>> Another question. Can you provide the cca. number of
>> impresions before you start to have problems. It would help
>> people to reproduce the error.
>>
>> Also are you looking on the logs? Are there any exceptions?
>> What about the catalina.out?
>>
>> Best Regards,
>>
>> Antonio Gallardo.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>


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


Re: JXTemplate forEach problem

Posted by Antonio Gallardo <ag...@agsoftware.dnsalias.com>.
Hi Peter,

Can you upgrade to Cocoon CVS version. And check if there is the problem too?

Another question. Can you provide the cca. number of impresions before you
start to have problems. It would help people to reproduce the error.

Also are you looking on the logs? Are there any exceptions? What about the
catalina.out?

Best Regards,

Antonio Gallardo.

Peter Bowman dijo:
> Hi,
>
> I have many pages in my application that use the JXTemplateGenerator to
> iterate over collections of Javascript and Java objects passed from a
> Cocoon
> flowscript.
>
> However, after a reasonably short number of page impressions, instead of
> iterating over the whole collection, only the first item in the list is
> processed.
>
> For example,
>
> ${collection}
>
> <jx:forEach var="i" items="collection">
>   ${i}
> </jx:forEach>
>
> Where the page is called by the flowscript:
>
> var ob = new Object();
> ob.collection = someCollection;
>
> cocoon.sendPageAndWait("page.jxt", ob);
>
> To start with, jx:forEach works as expected, and then, for no obvious
> reason, it will only process the first element of "collection". I am sure
> that the problem is with JXTemplate, because ${collection} just before the
> jx:forEach tag will correctly show the whole collection.
>
> I have the same problem with Cocoon 2.1 through 2.1.3. Am running under
> JBoss 3.2.1 with embedded Tomcat 4.1.24.
>
> Any ideas?
>
> Thanks,
> Pete Bowman.


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