You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Andy Whalen <an...@softhome.net> on 2002/07/14 22:59:17 UTC

Velocity Context Objects being dropped

Hi, 

As per the thousands of recommendations scattered throughout this newsgroup, I have stuck with Turbine 2.1 to develop an intranet site. This framework is tremendous!

I'm having one little problem: I'm using VM templates for my front end, but for some reason, whenever I instantiate an object and insert it into the Context, it disappears upon instantiation of the next page. I.e.,

in FooAction.java
    doBuildTemplate( data, context ) {
        context.put( "bar", new Bar() );
    }

then, on the next page that loads, MyFooBar.vm:

$bar.toString()

prints out an error message, "$bar.toString() is an invalid reference." Indeed, if I do a S.o.p. of "context.get( "bar" )" in the class matching MyFooBar.vm, it says "null".

Oh contrare!

The RunData object is there, but that's all - I can't get any other type of object to "stick". In Turbine Velocity, there's no "merge" function like in standalone Velocity, so I'm frankly out of ideas.

Does anyone have any wisdom they could impart upon me? I am in desperation!

Best,

================================
Andy Whalen
http://www.andywhalen.com

RE: Velocity Context Objects being dropped

Posted by Stephen Haberman <st...@chase3000.com>.
> > The context does not automatically persist from page to page. To
achieve
> > that type of functionality, you'd need to put the objects in the
user's
> > session or re-create them on each page load.
> >
> > - Stephen
> 
> Or make a pull tool.
> 

Ah yes, I should have mentioned that. Pull tools are very awesome.

- Stephen


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Velocity Context Objects being dropped

Posted by Scott Eade <se...@backstagetech.com.au>.
> The context does not automatically persist from page to page. To achieve
> that type of functionality, you'd need to put the objects in the user's
> session or re-create them on each page load.
> 
> - Stephen

Or make a pull tool.

Scott


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Velocity Context Objects being dropped

Posted by Stephen Haberman <st...@chase3000.com>.
The context does not automatically persist from page to page. To achieve
that type of functionality, you'd need to put the objects in the user's
session or re-create them on each page load.

- Stephen

> -----Original Message-----
> From: Andy Whalen [mailto:andyman32@softhome.net]
> Sent: Sunday, July 14, 2002 3:59 PM
> To: turbine-user@jakarta.apache.org
> Subject: Velocity Context Objects being dropped
> 
> Hi,
> 
> As per the thousands of recommendations scattered throughout this
newsgroup, I
> have stuck with Turbine 2.1 to develop an intranet site. This
framework is
> tremendous!
> 
> I'm having one little problem: I'm using VM templates for my front
end, but for some
> reason, whenever I instantiate an object and insert it into the
Context, it disappears
> upon instantiation of the next page. I.e.,
> 
> in FooAction.java
>     doBuildTemplate( data, context ) {
>         context.put( "bar", new Bar() );
>     }
> 
> then, on the next page that loads, MyFooBar.vm:
> 
> $bar.toString()
> 
> prints out an error message, "$bar.toString() is an invalid
reference." Indeed, if I do a
> S.o.p. of "context.get( "bar" )" in the class matching MyFooBar.vm, it
says "null".
> 
> Oh contrare!
> 
> The RunData object is there, but that's all - I can't get any other
type of object to
> "stick". In Turbine Velocity, there's no "merge" function like in
standalone Velocity, so
> I'm frankly out of ideas.
> 
> Does anyone have any wisdom they could impart upon me? I am in
desperation!
> 
> Best,
> 
> ================================
> Andy Whalen
> http://www.andywhalen.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Velocity Context Objects being dropped

Posted by Cameron Cole <cw...@rogers.com>.
Hey Andy,

If you are using turbine's built in security and user, the TurbineUser
has a temp Storage that persists for each session but is not persistent
beyond that. You can use the temp storage for each user/session as
TurbineUser.setTemp("key", obj) and Object TurbineUser.getTemp("key")

You can get at the raw HttpSession via the RunData object's getSession()
 method and use it for session storage as well.

HTH's,

-cam.


Andy Whalen wrote:
> Hey Joe. Thanks for the responses, everyone!
> 
> Indeed, if I put objects in the Context using the Action (I'm using
> ActionEvents - great feature!) it does indeed resolve the template
> references correctly. However, my problem is that I need to "put them in and
> leave them" - i.e., I was under the impression that the Context was supposed
> to be persistent through a session. I guess it's not.
> 
> What I needed to know is, specifically, how to create a custom "Session",
> where exactly one is created per visitor to the website and NOT a lone
> instance or singleton (as appears to be the tactic with Pull Service). I
> need this to be the "base" repository of data associated with one user's
> session with the site - which allows objects fetched from the database to be
> cached in memory and modified with minimal overhead.
> 
> It appears that the best way to go about this is to have my custom User
> class either implement org.apache.turbine.om.security.User or extend
> org.apache.turbine.com.security.TurbineUser. I'm preparing my own User /
> Permissions schema, so I'll probably do the former. Then I'd set the "User"
> field in RunData, which requires an org.apache.turbine.om.security.User.
> That gives me the impression of being session-persistent, and the RunData is
> available globally to the Context.
> 
> Does this seem to be the best solution to everyone out there?
> 
> ~Andy
> 
> ----- Original Message -----
> From: "joeblack" <jo...@vtradex.com>
> To: "'Turbine Users List'" <tu...@jakarta.apache.org>
> Sent: Monday, July 15, 2002 1:02 PM
> Subject: RE: Velocity Context Objects being dropped
> 
> 
> Hi, Andy:
> 
> I put my objects into TemplateContext in Action time and time again,
> they always work. If the request link is
> $link.setAction("FooAction").setPage("MyFooBar.vm"), I think you can get
> the reference in .VM with no problem.
> Use doPerform() or doXxxxxx() method in Action instead of
> doBuildTemplate().
> Good luck.
> 
> 
> Joel
> 
> -----Original Message-----
> From: Andy Whalen [mailto:andyman32@softhome.net]
> Sent: 2002年7月14日 13:59
> To: turbine-user@jakarta.apache.org
> Subject: Velocity Context Objects being dropped
> 
> Hi,
> 
> As per the thousands of recommendations scattered throughout this
> newsgroup, I have stuck with Turbine 2.1 to develop an intranet site.
> This framework is tremendous!
> 
> I'm having one little problem: I'm using VM templates for my front end,
> but for some reason, whenever I instantiate an object and insert it into
> the Context, it disappears upon instantiation of the next page. I.e.,
> 
> in FooAction.java
>     doBuildTemplate( data, context ) {
>         context.put( "bar", new Bar() );
>     }
> 
> then, on the next page that loads, MyFooBar.vm:
> 
> $bar.toString()
> 
> prints out an error message, "$bar.toString() is an invalid reference."
> Indeed, if I do a S.o.p. of "context.get( "bar" )" in the class matching
> MyFooBar.vm, it says "null".
> 
> Oh contrare!
> 
> The RunData object is there, but that's all - I can't get any other type
> of object to "stick". In Turbine Velocity, there's no "merge" function
> like in standalone Velocity, so I'm frankly out of ideas.
> 
> Does anyone have any wisdom they could impart upon me? I am in
> desperation!
> 
> Best,
> 
> ================================
> Andy Whalen
> http://www.andywhalen.com
> 
> 
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Velocity Context Objects being dropped

Posted by Stephen Haberman <st...@chase3000.com>.
> It appears that the best way to go about this is to have my custom
User
> class either implement org.apache.turbine.om.security.User or extend
> org.apache.turbine.com.security.TurbineUser. I'm preparing my own User
/
> Permissions schema, so I'll probably do the former. Then I'd set the
"User"
> field in RunData, which requires an
org.apache.turbine.om.security.User.
> That gives me the impression of being session-persistent, and the
RunData is
> available globally to the Context.
> 
> Does this seem to be the best solution to everyone out there?

No. The RunData is not session-persistent. It's available to each
velocity template within a request, but it's rebuilt on reach request,
given that, by nature, HTTP is a stateless protocol.

As Cameron noted, the TurbineUser's setTemp or the RunData's getSession
are currently the only means of persisting objects across page requests.

- Stephen


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Velocity Context Objects being dropped

Posted by Andy Whalen <an...@softhome.net>.
Hey Joe. Thanks for the responses, everyone!

Indeed, if I put objects in the Context using the Action (I'm using
ActionEvents - great feature!) it does indeed resolve the template
references correctly. However, my problem is that I need to "put them in and
leave them" - i.e., I was under the impression that the Context was supposed
to be persistent through a session. I guess it's not.

What I needed to know is, specifically, how to create a custom "Session",
where exactly one is created per visitor to the website and NOT a lone
instance or singleton (as appears to be the tactic with Pull Service). I
need this to be the "base" repository of data associated with one user's
session with the site - which allows objects fetched from the database to be
cached in memory and modified with minimal overhead.

It appears that the best way to go about this is to have my custom User
class either implement org.apache.turbine.om.security.User or extend
org.apache.turbine.com.security.TurbineUser. I'm preparing my own User /
Permissions schema, so I'll probably do the former. Then I'd set the "User"
field in RunData, which requires an org.apache.turbine.om.security.User.
That gives me the impression of being session-persistent, and the RunData is
available globally to the Context.

Does this seem to be the best solution to everyone out there?

~Andy

----- Original Message -----
From: "joeblack" <jo...@vtradex.com>
To: "'Turbine Users List'" <tu...@jakarta.apache.org>
Sent: Monday, July 15, 2002 1:02 PM
Subject: RE: Velocity Context Objects being dropped


Hi, Andy:

I put my objects into TemplateContext in Action time and time again,
they always work. If the request link is
$link.setAction("FooAction").setPage("MyFooBar.vm"), I think you can get
the reference in .VM with no problem.
Use doPerform() or doXxxxxx() method in Action instead of
doBuildTemplate().
Good luck.


Joel

-----Original Message-----
From: Andy Whalen [mailto:andyman32@softhome.net]
Sent: 2002年7月14日 13:59
To: turbine-user@jakarta.apache.org
Subject: Velocity Context Objects being dropped

Hi,

As per the thousands of recommendations scattered throughout this
newsgroup, I have stuck with Turbine 2.1 to develop an intranet site.
This framework is tremendous!

I'm having one little problem: I'm using VM templates for my front end,
but for some reason, whenever I instantiate an object and insert it into
the Context, it disappears upon instantiation of the next page. I.e.,

in FooAction.java
    doBuildTemplate( data, context ) {
        context.put( "bar", new Bar() );
    }

then, on the next page that loads, MyFooBar.vm:

$bar.toString()

prints out an error message, "$bar.toString() is an invalid reference."
Indeed, if I do a S.o.p. of "context.get( "bar" )" in the class matching
MyFooBar.vm, it says "null".

Oh contrare!

The RunData object is there, but that's all - I can't get any other type
of object to "stick". In Turbine Velocity, there's no "merge" function
like in standalone Velocity, so I'm frankly out of ideas.

Does anyone have any wisdom they could impart upon me? I am in
desperation!

Best,

================================
Andy Whalen
http://www.andywhalen.com


--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Velocity Context Objects being dropped

Posted by joeblack <jo...@vtradex.com>.
Hi, Andy:

I put my objects into TemplateContext in Action time and time again,
they always work. If the request link is
$link.setAction("FooAction").setPage("MyFooBar.vm"), I think you can get
the reference in .VM with no problem.
Use doPerform() or doXxxxxx() method in Action instead of
doBuildTemplate().
Good luck.


Joel

-----Original Message-----
From: Andy Whalen [mailto:andyman32@softhome.net] 
Sent: 2002年7月14日 13:59
To: turbine-user@jakarta.apache.org
Subject: Velocity Context Objects being dropped

Hi, 

As per the thousands of recommendations scattered throughout this
newsgroup, I have stuck with Turbine 2.1 to develop an intranet site.
This framework is tremendous!

I'm having one little problem: I'm using VM templates for my front end,
but for some reason, whenever I instantiate an object and insert it into
the Context, it disappears upon instantiation of the next page. I.e.,

in FooAction.java
    doBuildTemplate( data, context ) {
        context.put( "bar", new Bar() );
    }

then, on the next page that loads, MyFooBar.vm:

$bar.toString()

prints out an error message, "$bar.toString() is an invalid reference."
Indeed, if I do a S.o.p. of "context.get( "bar" )" in the class matching
MyFooBar.vm, it says "null".

Oh contrare!

The RunData object is there, but that's all - I can't get any other type
of object to "stick". In Turbine Velocity, there's no "merge" function
like in standalone Velocity, so I'm frankly out of ideas.

Does anyone have any wisdom they could impart upon me? I am in
desperation!

Best,

================================
Andy Whalen
http://www.andywhalen.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>