roller-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mullan Colm" <Colm.Mul...@uk.fujitsu.com>
Subject RE: obtaining values from a new VelocityContext
Date Tue, 16 Sep 2008 16:01:08 GMT
Thanks Brian,

That has worked a treat.

Colm

-----Original Message-----
From: Brian Levine [mailto:levine_brian@hotmail.com] 
Sent: 15 September 2008 22:42
To: user@roller.apache.org
Subject: RE: obtaining values from a new VelocityContext



One possibility is to have your your class implement the
org.apache.roller.weblogger.ui.rendering.model.Model interface.

Then in your roller-custom.properties, add this:

rendering.pageModels=\
org.apache.roller.weblogger.ui.rendering.model.PageModel,\
org.apache.roller.weblogger.ui.rendering.model.ConfigModel,\
org.apache.roller.weblogger.ui.rendering.model.UtilitiesModel,\
org.apache.roller.weblogger.ui.rendering.model.URLModel,\
org.apache.roller.weblogger.ui.rendering.model.MessageModel,\
org.apache.roller.weblogger.ui.rendering.model.CalendarModel,\
org.apache.roller.weblogger.ui.rendering.model.MenuModel,\
your.class.here

Assuming it's a page model you want to add your functionality to.

The name you return from the getModelName() method (from the Model
interface) is the name you'll use to access the functionality from your
velocity templates.  So if getModelName returns "cookiemodel", then in
your velocity code, you access it like 

$cookiemodel.name

And "name" needs to be a class member so it can be accessed.

Hope that was helpful (and approaches coherence)

/B

> Subject: obtaining values from a new VelocityContext
> Date: Mon, 15 Sep 2008 11:37:18 +0100
> From: Colm.Mullan@uk.fujitsu.com
> To: user@roller.apache.org
> 
> Hi Folks,
> 
>  
> 
> I would like to obtain the user name for comments from a cookie file
> (this will be obtained from a java function), lets not worry about how
> the name is pulled from the cookie I have that under control. But I
need
> to know how in Roller we can display content from a custom java
method,
> For example consider the helloworld example using a different
> VelocityContext.
> 
>  
> 
> If I define a new class i.e. Helloworld.java
> 
>  
> 
> import java.io.StringWriter;
> import org.apache.velocity.app.VelocityEngine;
> import org.apache.velocity.Template;
> import org.apache.velocity.VelocityContext;
> public class HelloWorld
> {
>     public static void main( String[] args )
>         throws Exception
>     {
>         /*  first, get and initialize an engine  */
>         VelocityEngine ve = new VelocityEngine();
>         ve.init();
>         /*  next, get the Template  */
>         Template t = ve.getTemplate( "helloworld.vm" );
>         /*  create a context and add data */
>         VelocityContext context = new VelocityContext();
>         context.put("name", "World");
>         /* now render the template into a StringWriter */
>         StringWriter writer = new StringWriter();
>         t.merge( context, writer );
>         /* show the World */
>         System.out.println( writer.toString() );     
>     }
> }
>  
> And then add the following line to my weblog.wm template file
>  
> Hello $name!  Welcome to Velocity!
>  
> Name is not populated. How do we tell Roller to use the different
> VelocityContext in this case?
>  
> Thanks Colm
> 
>  
> 

_________________________________________________________________
See how Windows Mobile brings your life together-at home, work, or on
the go.
http://clk.atdmt.com/MRT/go/msnnkwxp1020093182mrt/direct/01/

Mime
View raw message