You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by jantje <ja...@skynet.be> on 2008/08/23 21:19:13 UTC

jXtemplate and Java source: searching an example or tutorial

Hi there, on the internet I can find a lot about jXtemplate (<map:generate
type="jx" src="file.xml"/>).

The information states that in jXtemplate, you can use Java. In cocoon 2.2 I
am searching an alternative for XSP but did not yet succeed. Maybe
jXtemplate is the solution?

What I want for my project is to use real lines of Java source in the
jXtemplate file: like it was in XSP. Is this possible.

For instance, the next line:
    String name;
There are other possibilities in jXtemplate to have a variable "name". But I
use this as an example. The question is: can someone give me an example on
how to use this line in jXtemplate? Just something like this (beaucause the
Java source I will use will be more complex):
  <jx:javaCode>
    String name;
    ...
    ...
  </jx:javaCode>

(info on jexl: http://commons.apache.org/jexl/ and
http://cocoon.apache.org/2.1/userdocs/flow/jxtemplate.html)

Thanks for your replies..
-- 
View this message in context: http://www.nabble.com/jXtemplate-and-Java-source%3A-searching-an-example-or-tutorial-tp19124311p19124311.html
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


Re: jXtemplate and Java source: searching an example or tutorial

Posted by Martin Heiden <ma...@netcologne.de>.
Hi!

Saturday, August 23, 2008, 9:19:13 PM, you wrote:

j> What I want for my project is to use real lines of Java source in the
j> jXtemplate file: like it was in XSP. Is this possible.

j> For instance, the next line:
j>     String name;
j> There are other possibilities in jXtemplate to have a variable "name". But I
j> use this as an example. The question is: can someone give me an example on
j> how to use this line in jXtemplate? Just something like this (beaucause the
j> Java source I will use will be more complex):

If your Java code is complex it shouldn't be part of a view.
JXTemplate offers you all you need for the "view logic" you can
iterate over collections, you can use conditional statements and even
calculate. But if you need more complex logic, you should separate
it. JXTemplate enforces you to do so, and I think that's a good thing.

Take a look at:

http://cocoon.apache.org/2.2/blocks/template/1.0/1215_1_1.html

If you need more complex logic you must decide to what kind of logic
it belongs. If it is "controller logic" (for example a decision which
view should be shown to the user), you should code it as flowscript
(or Javaflow). If it is "business logic" (for example a complex
calculation or database access" you should code it as a plain old
Java Object (POJO) and make that a Spring Bean. Than you can access
it by flowscript and pass a result object or even the Spring Bean to
the template and output the data.

This sounds more complex, but if your application grows, it will be
much easier to maintain and you can reuse the code in other
applications. It's really worth to do it this way!

regards

  Martin


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