turbine-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tony Oslund" <to...@prepare-enrich.com>
Subject Re: [?? Probable Spam] Template execution finished listener
Date Wed, 01 Sep 2010 15:20:03 GMT
Hello  Atti,

One option is to...
- create an object that will do what you want
- drop a reference to it into the context
- reference it from your velocity template

Occasionally I have had a need to execute business logic from within a 
template and this approach works for that.


Another other option is to create a "Tool" (I am using 2.3.1... I think this 
is still available in 2.3.2), and then to register it within your turbine 
props.

For example here is a basic tool that I use that I find handy for string 
manipulation (yours would obviously do something different)

public class StringGoodies implements 
org.apache.turbine.services.pull.ApplicationTool {

    public StringGoodies() {
    }

    public void init(Object data) {
    }

    public void refresh() {
    }

    public String replicate (String str, int qty) {
        return StringFunctions.replicate(str, qty);
    }

...

}


put something like this in your turbine props...

tool.global.strtool=com.somecompany.somelib.StringGoodies


Then it is always available within your velocity templates and can be used 
like (again yours would have different methods)

$strtool.replicate("=",20)



here are some notes from the example turbine props file

#   global:     tool is instantiated once and that instance is available
#               to all templates for all requests. Tool must be threadsafe.
#
#   request:    tool is instantiated once for each request (although the
#               PoolService is used to recycle instances). Tool need not
#               be threadsafe.
#
#   session:    tool is instantiated once for each user session, and is
#               stored in the user's temporary hashtable. Tool should be
#               threadsafe.
#
#   persistent: tool is instantitated once for each use session, and
#               is stored in the user's permanent hashtable. This means
#               for a logged in user the tool will be persisted in the
#               user's objectdata. Tool should be threadsafe and
#               Serializable.


Best of luck
Tony
--------------------------------------------------
From: "Szűcs Attila" <szucs.attila@codespring.ro>
Sent: Wednesday, September 01, 2010 1:19 AM
To: <user@turbine.apache.org>
Subject: [?? Probable Spam]  Template execution finished listener

> Hi,
>
> I am using Turbine 2.3.2 with Hibernate 3. My problem is that the 
> Hibernate session is not active when my (Velocity 1.6.4) template 
> executes, and I am accessing fields from the database for which Hibernate 
> needs lazy initialization. Therefore I get a LazyInitializationException - 
> no Session error. Since I want my Hibernate session to be alive when a 
> velocity template executes I would like to have a class to execute after 
> the velocity vm. This way I could close my Hibernate session properly, 
> only after the velocity template has been rendered. (Disabling lazy 
> initialization in Hibernate is not an option for me). Are there any 
> possibilities that Turbine offers to write a kind of listener (I am not 
> sure how to call it) that would execute right after a velocity screen has 
> been executed?
>
> Thanks ,
>   Atti
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@turbine.apache.org
For additional commands, e-mail: user-help@turbine.apache.org


Mime
View raw message