On 1 Jul 2004, at 15:02, Peter Velychko wrote:

Hello Jeremy,

Thank you for your reply.

Does you object "image" contain lazy collections?

11 of them

I just accomplish a small experiment. I set up my serializer (that is
inherited from HTMLSerializer but at end has the line
System.out.println("from serializer"))
and added the line
print("from flowscript");
to flowscript just after cocoon.sendPage().
The result is the "from flowscript" message is uppere than
"from serializer" message.
So how can I get elements from lazy collection later than I close
hibernate session after cocoon.sendPage()?

it works ;)

Thank you for advise of using catch (return)
I'll try to using it.

On 1 Jul 2004, at 11:29, Upayavira wrote:

That could work, but it would be working round, rather than working
with, Cocoon. You would also be buffering your output, which is best
avoided.

The solution looks far more complicated than it needs to be, also it
makes lazy loading pointless.

This is an issue that requires a full solution. I believe the
preferred way is something like:

cocoon.sendPageAndWait("url", bizData, function(){session.close()});

I used the HibernateFactory component that is in the Wiki as a basis
for my HibernateFactory.

Most of my flowscripts (for just displaying Beans) look like this:

function imageRecord() {
var factory = cocoon.getComponent (PersistenceFactory.ROLE);
var session = factory.createSession ();
try {
var image = ImagePeer.load (session, new java.lang.Long
(cocoon.parameters["imageid"]));
if (image != null) {
cocoon.sendPage (cocoon.parameters["screen"], { image: image });
} else {
cocoon.sendPage("screen/error", {message: "error.no-record"});
}
} catch (e) {
cocoon.log.error (e);
cocoon.sendPage("screen/error", {message: e});
} finally {
session.close();
cocoon.releaseComponent (factory);
}
}

I use lazy-initialisation but do not have problems using JXTemplate
with it.

If you do get lazy-initialisation errors, I think the thing to try it
to put this line after the cocoon.sendPage:

catch (return) {session.close ()}

and take session.close () out of the finally clause.

if I am editing via CForms ..... I do a session.close() just before and
session = factory.createSession (); just after the form.showForm
statement.

HTH

regards Jeremy

But I think there are some issues with this approach, and I believe it
doesn't work with cocoon.sendPage.

Fancy doing some digging into Cocoon's internals?

Regards, Upayavira

Peter Velychko wrote:

Hello Upayavira,

May be it is off topic.
There was discussion on using lazy loading with Hibernate.
Just a wild idea about it.
In flowscript we have possibility to get OutputStream or even DOM
tree to variable. And we can use the resulting DOM tree to generate
response.
(I'm not clear in my mind how can I use OutputStream in this way.)

function doSomething() {
 var doc;
  if (doc == undefined || doc == null) {
   doc = generateContent();
 }

 // responsing
 cocoon.sendPage("response-pipeline", {doc: doc});
}

function generateContent() {
 // initialization
 var factory = cocoon.getComponent(factoryURI);
 var session = factory.openSession();
 var someThing = doSomeDataWithSession(session);
 var viewData = {someThing: someThing};

 // generating content
 var pipelineUtil =

cocoon.createObject(Packages.org.apache.cocoon.components.flow.util. Pi
pelineUtil);
var doc =
pipelineUtil.processToDOM("generate-content-pipeline", viewData);
// releasing resources
session.close();
cocoon.releaseComponent(factory);

 return doc;
}

So to realize this approach needs 3 sets of pipelines:
1. Set for invoking flowscript function
     <map:match pattern="">
       <map:call function="doSomething"/>
     </map:match>

2. Set for generating content (DOM)
     <map:match pattern="generate-content-pipeline">
       <map:generate type="jx" src="screens/generate.jx">
         <map:parameter name="lenient-xpath" value="true"/>
       </map:generate>
       <map:transform type="i18n"/>
       <map:serialize type="xml"/>
     </map:match>

3. Set for response
     <map:match pattern="response-pipeline">
       <map:generate type="jx" src="screens/response.jx"/>
       <map:serialize type="html"/>
     </map:match>

I think it would be more advantageous to operate with OutputStream but
I don't know how it is possible to respond it from flowscript.


Stephan Coboos wrote:



Upayavira wrote:


<map:match pattern="foo.jxt">
  <map:generate type="jxt" src="foo.jxt"/>
  <map:act type="closeHibernateSession"/>
  <map:serialize type="html"/>
</map:match>


This will not work.

Actions are used when building a pipeline, not when processing it.
So the action will take place before the view is processed, not
after.


Oh, what a pitty. It's a little bit consfusing me why action is executed before processing the pipeline, but OK it is so. I think of process switch within the pipline?



Actually, when understood, it makes complete sense.



So, to explain:



Any pipeline when built, goes generator->transformer...->serializer.
And that is it. Anything else, such as matchers, selectors and
actions, that influence the pipeline, are used when building the
pipeline, not when using it. So imagine a process that goes:
1) Which generator? Which transformers? Which serialiser
2) Okay, I've worked out my pipeline, so: generator, go generate



And the generator then starts up, passing SAX events down the
pipeline until the serialiser has consumed all resulting events and
something has been returned to the user.



Thus, actions are used when _building_ pipelines, not when
_executing_ them.



Hope that makes sense.



Upayavira


--
Best regards,
Peter Velychko
[EMAIL PROTECTED]


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]


--------------------------------------------------------

                  If email from this address is not signed
                                IT IS NOT FROM ME

                        Always check the label, folks !!!!!
--------------------------------------------------------


Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to