Re: Java objects in JX templates

2006-01-31 Thread Ralph Goers

Not without a stack trace.

Bart Molenkamp wrote:


I've had problems with the following expression:

jx:when test=${java.lang.Class.forName( \
'com.bizzdesign.risks.assessment.UploadedEvidence'). \
isAssignableFrom(evidence.getClass())}

(the expression is one line).

This expression works, but somehow after calling the page a few times,
the application hangs. Took me a long time to figure it out. (I've
already solved it, simply by having a method
evidence.isUploadableEvidence() with the expression written in Java).

Does anybody know what might be going wrong? (I'm just curious)

Bart.

   



RE: Java objects in JX templates

2006-01-31 Thread Bart Molenkamp
java.lang.ClassNotFoundException:
com/bizzdesign/risks/assessment/UploadedEvidence

org.apache.cocoon.ProcessingException: Failed to execute pipeline.:
file:/app/was/installedApps/riskmanager/riskmanager.ear/riskmanager-1.1.
0.132.war/content/secure/reports/templates/ineffective-controls.xml:104:
93:org.mozilla.javascript.JavaScriptException:
java.lang.ClassNotFoundException:
com/bizzdesign/risks/assessment/UploadedEvidence
at
org.apache.cocoon.components.pipeline.AbstractProcessingPipeline.process
XMLPipeline(AbstractProcessingPipeline.java:582)
at
org.apache.cocoon.components.pipeline.impl.AbstractCachingProcessingPipe
line.processXMLPipeline(AbstractCachingProcessingPipeline.java:183)

...

Similair exceptions were thrown everywhere, saying that lots of classes
couldn't be found anymore (UploadedEvidence class was only one of them).
The application needed a reboot to get rid of this exception. Seems like
the expression, after being evaluated for several times, messes up the
class loader somehow...

Bart.

 -Oorspronkelijk bericht-
 Van: Ralph Goers [mailto:[EMAIL PROTECTED]
 Verzonden: dinsdag 31 januari 2006 14:48
 Aan: dev@cocoon.apache.org
 Onderwerp: Re: Java objects in JX templates
 
 Not without a stack trace.
 
 Bart Molenkamp wrote:
 
 I've had problems with the following expression:
 
 jx:when test=${java.lang.Class.forName( \
 'com.bizzdesign.risks.assessment.UploadedEvidence'). \
 isAssignableFrom(evidence.getClass())}
 
 (the expression is one line).
 
 This expression works, but somehow after calling the page a few
times,
 the application hangs. Took me a long time to figure it out. (I've
 already solved it, simply by having a method
 evidence.isUploadableEvidence() with the expression written in
Java).
 
 Does anybody know what might be going wrong? (I'm just curious)
 
 Bart.
 
 
 



Re: Java objects in JX templates

2006-01-30 Thread Ugo Cei


Il giorno 27/gen/06, alle ore 21:10, Leszek Gawron ha scritto:


One more thing: this construct

${java.util.StringTokenizer(items, delims)}

will work only when .jx is invoked from flow. This is due to the  
fact that neither JEXL nor JXPath is able to reference packages/ 
create java objects. The functionality in fact is provided by Rhino  
library.


According to my tests, it doesn't work in 2.1.8, regardless of  
whether I use flow or not and whether I prepend Packages. or not.  
Can anyone else confirm this?


Ugo


--
Ugo Cei
Tech Blog: http://agylen.com/
Open Source Zone: http://oszone.org/




Re: Java objects in JX templates

2006-01-30 Thread Fabrizio Sitzia
Hello,

I upgraded two webapps from Coccon 2.1.7 to 2.1.8 lately...

And I found this thread intriguing, so I have added the following to one
of my existing JX templates (which is run through a JX generator pipeline,
invoked by flowscript):

  p
  jx:set var=items value=alpha,beta,gamma/
  jx:set var=delims value=,/
  jx:set var=mytokenizer value=${java.util.StringTokenizer(items,
delims)}/
  jx:forEach var=token begin=1 end=${mytokenizer.countTokens()}
  ${mytokenizer.nextToken()}br/
  /jx:forEach
  /p


The html result:

  p
  alphabr
  betabr
  gammabr
  /p


So, it appears to work fine for flowscript! (Mi spiace, Ugo ;-)
(Don't know about Javaflow, though!)

Fabrizio


BTW. the reason I was intrigued is that I'm using similar constructs in
production webapps - which made me wonder why users haven't been
complaining if indeed this feature had stopped working after migrating to
Cocoon 2.1.8 :-


 ${java.util.StringTokenizer(items, delims)}

 According to my tests, it doesn't work in 2.1.8, regardless of
 whether I use flow or not and whether I prepend Packages. or not.
 Can anyone else confirm this?



Re: Java objects in JX templates

2006-01-30 Thread Sylvain Wallez

Ugo Cei wrote:

Our docs [1] state that something like:

 jx:forEach var=${var}
 items=${java.util.StringTokenizer(items, delims)}
  /jx:forEach

should work. However, that doesn't seem to be the case, at least in 
2.1.8 while it apparently worked before. I did a few more tests and 
discovered that even simple cases like ${java.util.Date()} produce no 
output and no error message. This even if I put Packages. in front 
of the package name. Is this a bug or what?


You can only call methods on existing objects. I had to use a static 
method (only callable using JXPath!) as a workaround in the CForms macros:


jx:set var=cformsHelper 
value=#{org.apache.cocoon.forms.generation.JXMacrosHelper.createHelper($cocoon/consumer,$cocoon/request,$cocoon/parameters/locale)}/


Sylvain

--
Sylvain WallezAnyware Technologies
http://bluxte.net http://www.anyware-tech.com
Apache Software Foundation Member Research  Technology Director



Re: Java objects in JX templates

2006-01-30 Thread Leszek Gawron

Sylvain Wallez wrote:

Ugo Cei wrote:


Our docs [1] state that something like:

 jx:forEach var=${var}
 items=${java.util.StringTokenizer(items, delims)}
  /jx:forEach

should work. However, that doesn't seem to be the case, at least in 
2.1.8 while it apparently worked before. I did a few more tests and 
discovered that even simple cases like ${java.util.Date()} produce no 
output and no error message. This even if I put Packages. in front 
of the package name. Is this a bug or what?



You can only call methods on existing objects. I had to use a static 
method (only callable using JXPath!) as a workaround in the CForms macros:
This is not true. You can call static methods and even constructors. 
Both from JXPath and JEXL.


  jx:set var=buffer value=${java.lang.StringBuffer('Hello ')}/
  jx:set var=ignore value=${buffer.append( 'World!' )}/
hw${buffer.toString()}/hw

Works like a charm in trunk.





jx:set var=cformsHelper 
value=#{org.apache.cocoon.forms.generation.JXMacrosHelper.createHelper($cocoon/consumer,$cocoon/request,$cocoon/parameters/locale)}/ 



Sylvain




--
Leszek Gawron  [EMAIL PROTECTED]
IT Manager MobileBox sp. z o.o.
+48 (61) 855 06 67  http://www.mobilebox.pl
mobile: +48 (501) 720 812   fax: +48 (61) 853 29 65


Java objects in JX templates

2006-01-27 Thread Ugo Cei

Our docs [1] state that something like:

 jx:forEach var=${var}
 items=${java.util.StringTokenizer(items, delims)}
  /jx:forEach

should work. However, that doesn't seem to be the case, at least in  
2.1.8 while it apparently worked before. I did a few more tests and  
discovered that even simple cases like ${java.util.Date()} produce no  
output and no error message. This even if I put Packages. in front  
of the package name. Is this a bug or what?


Ugo

[1] http://cocoon.apache.org/2.1/userdocs/flow/jxtemplate.html


--
Ugo Cei
Tech Blog: http://agylen.com/
Open Source Zone: http://oszone.org/




Re: Java objects in JX templates

2006-01-27 Thread Leszek Gawron

Ugo Cei wrote:

Our docs [1] state that something like:

 jx:forEach var=${var}
 items=${java.util.StringTokenizer(items, delims)}
  /jx:forEach

should work. However, that doesn't seem to be the case, at least in  
2.1.8 while it apparently worked before. I did a few more tests and  
discovered that even simple cases like ${java.util.Date()} produce no  
output and no error message. This even if I put Packages. in front  of 
the package name. Is this a bug or what?


Ugo

[1] http://cocoon.apache.org/2.1/userdocs/flow/jxtemplate.html


Didn't you want to do:
jx:forEach var=varName
  items=${java.util.StringTokenizer(items, delims)}
/jx:forEach


--
Leszek Gawron  [EMAIL PROTECTED]
IT Manager MobileBox sp. z o.o.
+48 (61) 855 06 67  http://www.mobilebox.pl
mobile: +48 (501) 720 812   fax: +48 (61) 853 29 65


Re: Java objects in JX templates

2006-01-27 Thread Ugo Cei


Il giorno 27/gen/06, alle ore 15:54, Leszek Gawron ha scritto:


Ugo Cei wrote:

Our docs [1] state that something like:
 jx:forEach var=${var}
 items=${java.util.StringTokenizer(items, delims)}
  /jx:forEach
should work. However, that doesn't seem to be the case, at least  
in  2.1.8 while it apparently worked before. I did a few more  
tests and  discovered that even simple cases like ${java.util.Date 
()} produce no  output and no error message. This even if I put  
Packages. in front  of the package name. Is this a bug or what?

Ugo
[1] http://cocoon.apache.org/2.1/userdocs/flow/jxtemplate.html


Didn't you want to do:
jx:forEach var=varName
  items=${java.util.StringTokenizer(items, delims)}
/jx:forEach


The code I copied above is straight from our docs, but it doesn't  
make an inch of a difference whether I change to what you suggest or  
not. The problem is that invoking Java class constructors or calling  
static methods does not work.


Ugo


--
Ugo Cei
Tech Blog: http://agylen.com/
Open Source Zone: http://oszone.org/




Re: Java objects in JX templates

2006-01-27 Thread Leszek Gawron

Jens Maukisch wrote:

Hi,



[1] http://cocoon.apache.org/2.1/userdocs/flow/jxtemplate.html




Didn't you want to do:
jx:forEach var=varName
  items=${java.util.StringTokenizer(items, delims)}
/jx:forEach



Have you tried the sample mentioned in the Docs? It does not work
for me either and your corrected code above too (C2.1.8).

So I think it's a bug?

One more thing: this construct

${java.util.StringTokenizer(items, delims)}

will work only when .jx is invoked from flow. This is due to the fact 
that neither JEXL nor JXPath is able to reference packages/create java 
objects. The functionality in fact is provided by Rhino library.


This is already fixed for 2.2-dev (still the dependency on Rhino remains).


--
Leszek Gawron  [EMAIL PROTECTED]
IT Manager MobileBox sp. z o.o.
+48 (61) 855 06 67  http://www.mobilebox.pl
mobile: +48 (501) 720 812   fax: +48 (61) 853 29 65


Re: Java objects in JX templates

2006-01-27 Thread Leszek Gawron

Ugo Cei wrote:


Il giorno 27/gen/06, alle ore 15:54, Leszek Gawron ha scritto:


Ugo Cei wrote:


Our docs [1] state that something like:
 jx:forEach var=${var}
 items=${java.util.StringTokenizer(items, delims)}
  /jx:forEach
should work. However, that doesn't seem to be the case, at least  in  
2.1.8 while it apparently worked before. I did a few more  tests and  
discovered that even simple cases like ${java.util.Date ()} produce 
no  output and no error message. This even if I put  Packages. in 
front  of the package name. Is this a bug or what?

Ugo
[1] http://cocoon.apache.org/2.1/userdocs/flow/jxtemplate.html



Didn't you want to do:
jx:forEach var=varName
  items=${java.util.StringTokenizer(items, delims)}
/jx:forEach



The code I copied above is straight from our docs, but it doesn't  make 
an inch of a difference whether I change to what you suggest or  not. 
The problem is that invoking Java class constructors or calling  static 
methods does not work.

As I replied in another message: referencing any java constructs like:

- packages
- classes
- constructors
- static methods
- constants

is available in jxtg via rhino (org.mozilla.javascript.NativeJavaClass, 
NativeJavaPackage, NativeJavaTopPackage). ${Packages} is simply a 
NativeJavaTopPackage and ${java} is a NativeJavaPackage. They are 
treated as ordinary view data. I have never tried but this should work also:


jx:set var=MyConstantsClass 
value=${Packages.com.mycompany.some.very.long.package.name.MyConstantsClass}/


jx:if test=${bean.status == MyConstantsClass.STATUS_OK}
   ok/
/jx:if

Unfortunatelly in 2.1.x those variables are only properly initialized 
when flowscript is the controller. 2.2 artificialy creates those 
variables no matter if you already have rhino context available or not.




--
Leszek Gawron  [EMAIL PROTECTED]
IT Manager MobileBox sp. z o.o.
+48 (61) 855 06 67  http://www.mobilebox.pl
mobile: +48 (501) 720 812   fax: +48 (61) 853 29 65