You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Michael Bierenfeld <mi...@atmiralis.de> on 2000/09/28 13:06:27 UTC
Re: Class creation
> I'm probably doing something very very wrong :). But how do I create my
> own class? And where do I have to put it?
>
> Peter
Yes you do ;-)
Store your own Class in a seperate Java-File
Counter.java :
public class Counter
{
private int count;
public int Value()
{
return count;
}
public void Raise()
{
count += 1;
}
public void Reset()
{
count = 0;
}
}
Compile it an put it into the Classpath of your
Servlet-Engine. Then you can simply use it in
<xsp:page>
<xsp:logic>
Counter myCounter = new Counter ();
</xsp:logic>
</xsp:page>
Regards
Michael
Re: Class creation
Posted by Peter Verhage <pe...@ibuildings.nl>.
Hi,
I've solved the problem.
I looked at the compiled page in the repository directory. And I
discoverd that the functions are placed within an other class. So that
will never work because creating a variable in a class is one thing. But
you can't directly call a function on that class without doing that in a
function of the class itself. So I made a function around it:
<xsp:logic>
private static Counter myCounter = new Counter();
public static int test() {
myCounter.Raise();
return myCounter.Value();
}
</xsp:logic>
Now it all works fine :)
Peter
--
Peter Verhage <pe...@ibuildings.nl>
ibuildings.nl BV - information technology
http://www.ibuildings.nl - 0118 41 50 54
Re: Class creation
Posted by Michael Bierenfeld <mi...@atmiralis.de>.
Hello,
hard to tell. Can you post the Parts of the xsp
where you encounter the Problem ?
Michael
Re: Class creation
Posted by Peter Verhage <pe...@ibuildings.nl>.
Michael Bierenfeld wrote a lot of usefull stuff including this:
> <xsp:page>
>
> <xsp:logic>
>
> Counter myCounter = new Counter ();
>
> </xsp:logic>
>
> </xsp:page>
I have tried that, and it works fine. Except if I really want to use the
counter...
If I do something like this: myCounter.Reset();
I get the following error message:
Error found handling the request.
java.lang.Exception: XSP Java Compiler: Compilation failed for
_index.java
28: Invalid method declaration; method name required.
myCounter.Reset();
^
1 error
at
org.apache.cocoon.processor.xsp.language.java.XSPJavaProcessor.compile(XSPJavaProcessor.java,
Compiled Code)
at
org.apache.cocoon.processor.xsp.XSPProcessor.process(XSPProcessor.java,
Compiled Code)
at org.apache.cocoon.Engine.handle(Engine.java, Compiled Code)
at org.apache.cocoon.Cocoon.service(Cocoon.java, Compiled Code)
at javax.servlet.http.HttpServlet.service(HttpServlet.java, Compiled
Code)
at
org.apache.jserv.JServConnection.processRequest(JServConnection.java,
Compiled Code)
at org.apache.jserv.JServConnection.run(JServConnection.java,
Compiled Code)
at java.lang.Thread.run(Thread.java, Compiled Code)
What does this mean? :)
Peter
--
Peter Verhage <pe...@ibuildings.nl>
ibuildings.nl BV - information technology
http://www.ibuildings.nl - 0118 41 50 54