cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Klaus Malorny <Klaus.Malo...@knipp.de>
Subject Re: Dynamic XML generation
Date Tue, 18 Jul 2000 16:11:53 GMT
Mike Engelhart wrote:
> 
> on 7/18/00 9:36 AM, Patrick Roemer at roemer@cs.uni-bonn.de wrote:
> 
> > Hi,
> >
> > I'm a Cocoon beginner and I'm sure you have read this question before,
> > but I haven't been able to find a consistent answer in all the mailing
> > list archives I've searched, so please help me out.
> >
> > I have a servlet that checks access authorization by username and
> > password, send a database request and outputs the result in HTML.
> > Authorization and database access are handled by separate classes, so
> > the servlet itself is quite lightweight.
> >
> Just use a RequestDispatcher in your servlet and send it to either an XSP
> (if you need the output to be dynamic) or to an .xml file.
> 
> So in your servlet you'd have something like:
> 
> RequestDispatcher rd = request.getRequestDispatcher("/xml/login.xml");
> // if you want you can put objects into the request
> // and pull them out again in an XSP or else just forward the request object
> // this example puts a simple error string into the request object via
> // setAttribute() and then the XSP adds it to the XML document on the fly
> rd.setAtttribute("error", "The user name and password you selected were
> invalid");
> rd.forward(request, response);
> 
> then in say an XSP, you can do this:
> 
> <?xml version="1.0"?>
> 
> <?cocoon-process type="xsp"?>
> <?cocoon-process type="xslt"?>
> 
> <?xml-stylesheet href="error.xsl" type="text/xsl"?>
> 
> <xsp:page language="java" xmlns:xsp="http://www.apache.org/1999/XSP/Core">
>  <document>
>   <error><xsp:expr>(String) request.getAttribute("error")</xsp:expr></error>
>  </document>
> </xsp:page>
> 
> Mike
>


Thanks for this trick, since I am a Cocoon novice similar to Patrick and got
the same questions like him. It nicely solves the problem I have for
multi-page forms with 'next' and 'prev' buttons, since depending on the button
and the contents of the current page I have to display the previous, current
(evenutally with error messages) or next page. It also allows the seperation
of the data processing and the presentation, although I'm not quite sure how
to do this the best way.

BTW, it seems that setAttribute is a method of Request instead of
RequestDispatcher.

regards
Klaus

Mime
View raw message