cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jason Johnston <>
Subject Re: How to Share objects with Servlets in Same container
Date Wed, 07 Sep 2005 14:12:53 GMT
Sachin Dharmapurikar wrote:
> Hi All,
>    In our company, we have already developed one solution which has
> following use Case:
> 1. Form: To get the input from user about _Something_
> 2. Servlet: Depending on the inputs query to database _do_ some operations,
> and as a side effect of these operations one java bean is created containing
> information and data to create image/charts. Now this image generation is
> done by a dedicated servlet.
> 3. Image generator servlet: As I discussed above, we get the java bean
> containing data to create the image and creates image. This bean is having
> lifetime of session and it's automatically deleted once session is over.
> Since our application is having lot of presentation stuff, I think in our
> application framework Cocoon is best fit. So I am planning to port my
> application on Cocoon. From one-and-half week I am trying cocoon and after
> stretching for long hours, I came to know that its excellent product and
> framework in all. Now the question comes is how I can do it. What I have
> thought is:
> 1. To take input from user: Cocoon Forms (Is it Stable? As in docs said,
> developers are working on stable release of CForms)

This terminology has been discussed on the developers list recently, and 
this is a perfect example of why it should be changed.  In this case 
"unstable" means that the Java API for CForms components is not yet firm 
and may change under developers, *not* that it is crash-prone.  In fact 
many people, including myself, have been using CForms in critical 
production environments for a while with no stability problems 
whatsoever.  So don't be scared when you read it's not marked "stable" yet.

> 2. To process the logic: XSP logic sheets, I will use these sheets to create
> the beans also.

I would suggest you use CForms to bind form values directly to/from your 
JavaBeans (see the binding framework), and the flow controller (either 
flowscript or javaflow) to pass those beans around for processing.  IMO 
this is the cleanest way to handle processing that I've ever seen in a 
web app framework, and one of the main reasons I've become a huge Cocoon 
junkie.  From what I've seen XSP is being phased out (or at least 
discouraged for most uses) now that we have better ways (Control Flow) 
to handle processing.

> 3. to present pages XSLT rendering.

Yes.  CForms already uses XSLT to create the HTML representation of its 
widgets, so you can just extend that to customize your layout or add an 
additional XSLT stage.

> Now I want your input on this design. Please quote on this.
> The above stated design in almost in my vision. How to do it and so but I am
> facing a real problem. The problem is:
> 1. Where to store the bean? In Servlet I used to use
> HttpSessionBindingListner which allowed me to put the value in session and
> forget. It will take care of deleting and clearing persistent objects.

If you're using Control Flow you can put objects on the session, for 
example in flowscript: cocoon.session.setAttribute("name", theBean);.

Flowscript also allows you to get transparent session persistence by 
using global variables, but if you're intending that the object on the 
session be available to other servlets then cocoon.session.setAttribute 
is probably what you want.

> 2. How to pass directly this bean to Imageservlet?????

There may be other ways to do this that I don't know about, but putting 
the bean on the session and issuing a redirect to ImageServlet would 
definitely work (I've done similar things running Cocoon and ColdFusion 
together).  Note that the two servlets (CocoonServlet and ImageServlet) 
will have to be running in  the same servlet container to share session 

Also, I'm not sure what exactly your ImageServlet involves, but Cocoon 
has facilities for generating PNG/JPG images from SVG documents, so if 
you wanted to try porting it over then you'd have a fully-Cocoon app and 
wouldn't have to worry about passing stuff between servlets.  Just a 

Best of luck, you've made an excellent choice moving to Cocoon.  We're 
happy to answer any more questions you have.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message