You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Brian McCallister <mc...@forthillcompany.com> on 2003/11/24 23:22:38 UTC

JXTemplate and Woody

I am trying to do a fairly simple (I think) thing in Cocoon (2.1.3) via  
FlowScript -- put an object in the HttpSession and make it available to  
JXTemplate.

The FlowScript looks like:

cocoon.load("resource://org/apache/cocoon/woody/flow/javascript/ 
woody2.js");

function login()
{
     var form = new Form("forms/login.xml");
     var employee = null;
     var service = new  
Packages.com.forthillcompany.infra.serv.SecurityService();

     while (employee == null)
     {
         form.showForm("login");
         employee = service.login(form.getModel().name,  
form.getModel().password);
         cocoon.session.setAttribute("user", employee);
     }
     cocoon.sendPage("home");
}

And the flow of control works correctly. It passes to a JXTemplate,  
this form displays correctly:

<html xmlns:i18n="http://apache.org/cocoon/i18n/2.1">
     <head>
         <title>Home</title>
     </head>
     <body>
         <i18n:text>greeting</i18n:text>,  
${session.getAttribute("user").getDisplayName()}
     </body>
</html>

however the more natural form:

<html xmlns:i18n="http://apache.org/cocoon/i18n/2.1">
     <head>
         <title>Home</title>
     </head>
     <body>
         <i18n:text>greeting</i18n:text>, ${session.user.displayName}
     </body>
</html>

Does not properly find the attribute (or even the "user").

Is there something obvious that I am missing?

Changing the attribute set call in the FlowScript to  
"cocoon.session.user = employee;" yields identical results (though I do  
like that more).

Thank you!

-Brian



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


Re: JXTemplate and Woody

Posted by Brian McCallister <mc...@forthillcompany.com>.
On Monday, November 24, 2003, at 05:22 PM, Brian McCallister wrote:
> Changing the attribute set call in the FlowScript to 
> "cocoon.session.user = employee;" yields identical results (though I 
> do like that more).
>

Change that, the cocoon.session.user = employee form does NOT work =) 
It was just cached in the session from debugging various forms.

-Brian



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


Re: JXTemplate and Woody

Posted by Brian McCallister <mc...@forthillcompany.com>.
Hmm, not bad. Just pass into each page everything that it needs. I 
would prefer to encapsulate that somehow than pass around maps all the 
time, but... maps an scripting languages do go hand in hand =)

I am still working my noggin around building applications with 
FlowScript. It makes lots of sense conceptually but I don't have the 
mental set quite yet.

Your technique requires a FlowScript control for every page -- I had 
been using it only where it was more than a one-shot render. Need to 
adjust my thinking some.

On Tuesday, November 25, 2003, at 08:09 AM, Reinhard Poetz wrote:
> Yes, you are right. On the other hand you can do something like
>
>
> var user;
>
> function login() {
>    user = new User();
> }
>
> function myFunc() {
>    cocoon.sendPage( "myPipeline", {user : user} );
> }
>
> *one* sitemap. This should also mean that you your persistence layer 
> (in
> your case OJB, isn't it ;-) is not queried any more.

Actually in this case it is an ldap. I haven't used JNDI for very 
complicated things in the past so once I get better at it and grok the 
idioms I may do an ldap backend for OJB ;-)

Thank you!

-Brian



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


Re: JXTemplate and Woody

Posted by Brian McCallister <mc...@forthillcompany.com>.
Yes they do, i am being braindead. Sorry.

-Brian

On Tuesday, November 25, 2003, at 08:09 AM, Reinhard Poetz wrote:

>
> From: Brian McCallister
>
>> On Tuesday, November 25, 2003, at 03:40 AM, Reinhard Poetz wrote:
>>>
>>> Hmmm, I can't tell you why this doesn't work as expected for you but
>>> why
>>> don't you pass the objects using
>>>
>>>   cocoon.sendPage( "myPipeline", {user : user} );
>>>
>>
>> I may be wrong, but doesn't that put the user into the
>> request scope? I
>> use a lightweight "Employee" object as a token (really a token
>> container as it is full of keys) for logged in users. I would
>> prefer to
>> avoid having to re-query for it every time.
>
> Yes, you are right. On the other hand you can do something like
>
>
> var user;
>
> function login() {
>    user = new User();
> }
>
> function myFunc() {
>    cocoon.sendPage( "myPipeline", {user : user} );
> }
>
>
> Doing it this way you don't need the session as data container because
> global variables are available (by reference) within all scripts of
> *one* sitemap. This should also mean that you your persistence layer 
> (in
> your case OJB, isn't it ;-) is not queried any more.
>
> Concerning the request object: I think you're right but as you only 
> deal
> with references the overhead is very small and the persistence layer is
> not re-queried. The advantage of this is more explicit code because of 
> a
> clear flow <--> view contract.
>
> ... but of course a matter of taste.
>
> --
> Reinhard
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>



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


Re: JXTemplate and Woody

Posted by Brian McCallister <mc...@forthillcompany.com>.
Okay, I found a big problem in doing it this way. If I organize 
different functions into different files (to make them manageable) they 
don't seem to share globals =/

-Brian

On Tuesday, November 25, 2003, at 08:09 AM, Reinhard Poetz wrote:

>
> From: Brian McCallister
>
>> On Tuesday, November 25, 2003, at 03:40 AM, Reinhard Poetz wrote:
>>>
>>> Hmmm, I can't tell you why this doesn't work as expected for you but
>>> why
>>> don't you pass the objects using
>>>
>>>   cocoon.sendPage( "myPipeline", {user : user} );
>>>
>>
>> I may be wrong, but doesn't that put the user into the
>> request scope? I
>> use a lightweight "Employee" object as a token (really a token
>> container as it is full of keys) for logged in users. I would
>> prefer to
>> avoid having to re-query for it every time.
>
> Yes, you are right. On the other hand you can do something like
>
>
> var user;
>
> function login() {
>    user = new User();
> }
>
> function myFunc() {
>    cocoon.sendPage( "myPipeline", {user : user} );
> }
>
>
> Doing it this way you don't need the session as data container because
> global variables are available (by reference) within all scripts of
> *one* sitemap. This should also mean that you your persistence layer 
> (in
> your case OJB, isn't it ;-) is not queried any more.
>
> Concerning the request object: I think you're right but as you only 
> deal
> with references the overhead is very small and the persistence layer is
> not re-queried. The advantage of this is more explicit code because of 
> a
> clear flow <--> view contract.
>
> ... but of course a matter of taste.
>
> --
> Reinhard
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>



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


RE: JXTemplate and Woody

Posted by Reinhard Poetz <re...@apache.org>.
From: Brian McCallister

> On Tuesday, November 25, 2003, at 03:40 AM, Reinhard Poetz wrote:
> >
> > Hmmm, I can't tell you why this doesn't work as expected for you but
> > why
> > don't you pass the objects using
> >
> >   cocoon.sendPage( "myPipeline", {user : user} );
> >
> 
> I may be wrong, but doesn't that put the user into the 
> request scope? I 
> use a lightweight "Employee" object as a token (really a token 
> container as it is full of keys) for logged in users. I would 
> prefer to 
> avoid having to re-query for it every time.

Yes, you are right. On the other hand you can do something like


var user;

function login() {
   user = new User();
}

function myFunc() {
   cocoon.sendPage( "myPipeline", {user : user} );
}


Doing it this way you don't need the session as data container because
global variables are available (by reference) within all scripts of
*one* sitemap. This should also mean that you your persistence layer (in
your case OJB, isn't it ;-) is not queried any more.

Concerning the request object: I think you're right but as you only deal
with references the overhead is very small and the persistence layer is
not re-queried. The advantage of this is more explicit code because of a
clear flow <--> view contract.

... but of course a matter of taste.

--
Reinhard


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


Re: JXTemplate and Woody

Posted by Brian McCallister <mc...@forthillcompany.com>.
On Tuesday, November 25, 2003, at 03:40 AM, Reinhard Poetz wrote:
>
> Hmmm, I can't tell you why this doesn't work as expected for you but 
> why
> don't you pass the objects using
>
>   cocoon.sendPage( "myPipeline", {user : user} );
>

I may be wrong, but doesn't that put the user into the request scope? I 
use a lightweight "Employee" object as a token (really a token 
container as it is full of keys) for logged in users. I would prefer to 
avoid having to re-query for it every time.

-Brian



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


RE: JXTemplate and Woody

Posted by Reinhard Poetz <re...@apache.org>.

> -----Original Message-----
> From: Brian McCallister [mailto:mccallister@forthillcompany.com] 
> Sent: Monday, November 24, 2003 11:23 PM
> To: users@cocoon.apache.org
> Subject: JXTemplate and Woody
> 
> 
> I am trying to do a fairly simple (I think) thing in Cocoon 
> (2.1.3) via  
> FlowScript -- put an object in the HttpSession and make it 
> available to  
> JXTemplate.
> 
> The FlowScript looks like:
> 
> cocoon.load("resource://org/apache/cocoon/woody/flow/javascript/ 
> woody2.js");
> 
> function login()
> {
>      var form = new Form("forms/login.xml");
>      var employee = null;
>      var service = new  
> Packages.com.forthillcompany.infra.serv.SecurityService();
> 
>      while (employee == null)
>      {
>          form.showForm("login");
>          employee = service.login(form.getModel().name,  
> form.getModel().password);
>          cocoon.session.setAttribute("user", employee);
>      }
>      cocoon.sendPage("home");
> }
> 
> And the flow of control works correctly. It passes to a JXTemplate,  
> this form displays correctly:
> 
> <html xmlns:i18n="http://apache.org/cocoon/i18n/2.1">
>      <head>
>          <title>Home</title>
>      </head>
>      <body>
>          <i18n:text>greeting</i18n:text>,  
> ${session.getAttribute("user").getDisplayName()}
>      </body>
> </html>
> 
> however the more natural form:
> 
> <html xmlns:i18n="http://apache.org/cocoon/i18n/2.1">
>      <head>
>          <title>Home</title>
>      </head>
>      <body>
>          <i18n:text>greeting</i18n:text>, ${session.user.displayName}
>      </body>
> </html>
> 
> Does not properly find the attribute (or even the "user").
> 
> Is there something obvious that I am missing?
> 
> Changing the attribute set call in the FlowScript to  
> "cocoon.session.user = employee;" yields identical results 
> (though I do  
> like that more).
> 
> Thank you!


Hmmm, I can't tell you why this doesn't work as expected for you but why
don't you pass the objects using

  cocoon.sendPage( "myPipeline", {user : user} );

--
Reinhard


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