Passing data into a Velocity Template from a Spring Controller

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Passing data into a Velocity Template from a Spring Controller

Jack C. Holt
Can anyone tell me or point me to something that explains how to pass
data from a Spring controller to a Velocity Template?  I know about
using Velocity View Resolvers.  I have successfully called Velocity
Views from Spring Controllers but I'm unable to make the connection
between a Spring model and a Velocity context.
 I've read all the documentation I can find on using Velocity with
Spring (for instance the section starting on page 139 of the Spring
Reference Manual).
 
 How do I make the connection?

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Passing data into a Velocity Template from a Spring Controller

Will Glass-Husain

The controller model should automatically populate the Velocity context.  I
followed the examples in the Spring reference manual and it worked fine.

Let me make a simple example.

WILL


----- Original Message -----
From: "Jack Holt" <[hidden email]>
To: <[hidden email]>
Sent: Friday, May 13, 2005 7:58 AM
Subject: Passing data into a Velocity Template from a Spring Controller


Can anyone tell me or point me to something that explains how to pass
data from a Spring controller to a Velocity Template?  I know about
using Velocity View Resolvers.  I have successfully called Velocity
Views from Spring Controllers but I'm unable to make the connection
between a Spring model and a Velocity context.
 I've read all the documentation I can find on using Velocity with
Spring (for instance the section starting on page 139 of the Spring
Reference Manual).

 How do I make the connection?

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Passing data into a Velocity Template from a Spring Controller

Tim Diggins (Subs)
Hi Jack -

I found the following two bits of reference useful in getting started
with spring :

1) follow the Spring mvc tutorial (which makes it happen for jsps) and
then modify it for velocity (basically just by changing your view
resolver as per the ch 13 (views) of the spring ref.)
http://www.springframework.org/docs/MVC-step-by-step/Spring-MVC-step-by-step.html

2) read the MVC chapter of the the spring docs
(http://www.springframework.org/docs/reference/mvc.html) which will tell
you all about controllers, handlers and viewresolvers.

But the shortcut (I'm a spring novice ("spring chicken?" --groan), so
might be  a bit hack-y):

Make a class to implement Controller
(org.springframework.web.servlet.mvc.Controller)
  and then make sure you return a ModelAndView from the required

public ModelAndView handleRequest(HttpServletRequest request,
             HttpServletResponse response) throws ServletException,
IOException,

the useful constructor (I think) here is

ModelAndView(String viewName, Map model)

so if you make a
Map model = java.util.Hashtable();
and then
model.put("useful", myUsefulObject);

then if you return your ModelAndView("mytemplate", model)

then you refer to  $useful in your "mytemplate.vm" file.

But I would recommend following through the spring mvc tutorial (except
for the last page on db-stuff which has lots of locking problems... at
least when launched from within eclipse ...).

Tim

(Anyone who wants to improve any of my spring stupidity, please do!)



> ----- Original Message ----- From: "Jack Holt" <[hidden email]>
> To: <[hidden email]>
> Sent: Friday, May 13, 2005 7:58 AM
> Subject: Passing data into a Velocity Template from a Spring Controller
>
>
> Can anyone tell me or point me to something that explains how to pass
> data from a Spring controller to a Velocity Template?  I know about
> using Velocity View Resolvers.  I have successfully called Velocity
> Views from Spring Controllers but I'm unable to make the connection
> between a Spring model and a Velocity context.
> I've read all the documentation I can find on using Velocity with
> Spring (for instance the section starting on page 139 of the Spring
> Reference Manual).
>
> How do I make the connection?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Passing data into a Velocity Template from a Spring Controller

Jack C. Holt
Thanks.  It works just like you said. Of course, previously I had
already tried exactly what you said, but it didn't work.  I guess I
needed to reload the app in the server and had neglected to.

On 5/13/05, Tim Diggins <[hidden email]> wrote:

> Hi Jack -
>
> I found the following two bits of reference useful in getting started
> with spring :
>
> 1) follow the Spring mvc tutorial (which makes it happen for jsps) and
> then modify it for velocity (basically just by changing your view
> resolver as per the ch 13 (views) of the spring ref.)
> http://www.springframework.org/docs/MVC-step-by-step/Spring-MVC-step-by-step.html
>
> 2) read the MVC chapter of the the spring docs
> (http://www.springframework.org/docs/reference/mvc.html) which will tell
> you all about controllers, handlers and viewresolvers.
>
> But the shortcut (I'm a spring novice ("spring chicken?" --groan), so
> might be  a bit hack-y):
>
> Make a class to implement Controller
> (org.springframework.web.servlet.mvc.Controller)
>   and then make sure you return a ModelAndView from the required
>
> public ModelAndView handleRequest(HttpServletRequest request,
>              HttpServletResponse response) throws ServletException,
> IOException,
>
> the useful constructor (I think) here is
>
> ModelAndView(String viewName, Map model)
>
> so if you make a
> Map model = java.util.Hashtable();
> and then
> model.put("useful", myUsefulObject);
>
> then if you return your ModelAndView("mytemplate", model)
>
> then you refer to  $useful in your "mytemplate.vm" file.
>
> But I would recommend following through the spring mvc tutorial (except
> for the last page on db-stuff which has lots of locking problems... at
> least when launched from within eclipse ...).
>
> Tim
>
> (Anyone who wants to improve any of my spring stupidity, please do!)
>
>
> > ----- Original Message ----- From: "Jack Holt" <[hidden email]>
> > To: <[hidden email]>
> > Sent: Friday, May 13, 2005 7:58 AM
> > Subject: Passing data into a Velocity Template from a Spring Controller
> >
> >
> > Can anyone tell me or point me to something that explains how to pass
> > data from a Spring controller to a Velocity Template?  I know about
> > using Velocity View Resolvers.  I have successfully called Velocity
> > Views from Spring Controllers but I'm unable to make the connection
> > between a Spring model and a Velocity context.
> > I've read all the documentation I can find on using Velocity with
> > Spring (for instance the section starting on page 139 of the Spring
> > Reference Manual).
> >
> > How do I make the connection?
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Help using velocity tools

Wayne Andersen
I need to be able to do some date processing in my macros, I saw the
velocitytools stuff and it will do what I need, but how do I access/use
the tools in my macros?

Wayne L Andersen
System Administrator
Clima-Tech Corporation
208-947-1849


smime.p7s (4K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Passing data into a Velocity Template from a Spring Controller

Shinobu Kawai
In reply to this post by Tim Diggins (Subs)
TWIMC,

> 1) follow the Spring mvc tutorial (which makes it happen for jsps) and
> then modify it for velocity (basically just by changing your view
> resolver as per the ch 13 (views) of the spring ref.)
> http://www.springframework.org/docs/MVC-step-by-step/Spring-MVC-step-by-step.html

I just started creating a supplemental document for Velocity here:
   http://wiki.apache.org/jakarta-velocity/VelocityAndSpringStepByStep

Best regards,
-- Shinobu

--
Shinobu Kawai <[hidden email]>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Help using velocity tools

Shinobu Kawai
In reply to this post by Wayne Andersen
Hi Wayne,

> I need to be able to do some date processing in my macros, I saw the
> velocitytools stuff and it will do what I need, but how do I access/use
> the tools in my macros?

Just put it in the Context.
   http://jakarta.apache.org/velocity/developer-guide.html#The%20Context

Or if you're using VelocityViewServlet, put it in the toolbox.xml.
   http://jakarta.apache.org/velocity/tools/view/index.html#Toolbox%20Configuration

Best regards,
-- Shinobu

--
Shinobu Kawai <[hidden email]>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Passing data into a Velocity Template from a Spring Controller

Will Glass-Husain
In reply to this post by Shinobu Kawai
Nice idea to build a wiki page.  We need to link Spring into the Wiki
PoweredByVelocity page under Frameworks, too - it's now a very prominent
example.

I'm in the middle of a project combining Spring, Velocity, and Hibernate.
It's a nice combination.

WILL

----- Original Message -----
From: "Shinobu Kawai" <[hidden email]>
To: "Velocity Users List" <[hidden email]>
Sent: Friday, May 13, 2005 11:28 AM
Subject: Re: Passing data into a Velocity Template from a Spring Controller


TWIMC,

> 1) follow the Spring mvc tutorial (which makes it happen for jsps) and
> then modify it for velocity (basically just by changing your view
> resolver as per the ch 13 (views) of the spring ref.)
> http://www.springframework.org/docs/MVC-step-by-step/Spring-MVC-step-by-step.html

I just started creating a supplemental document for Velocity here:
   http://wiki.apache.org/jakarta-velocity/VelocityAndSpringStepByStep

Best regards,
-- Shinobu

--
Shinobu Kawai <[hidden email]>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Passing data into a Velocity Template from a Spring Controller

Jack C. Holt
Great! I look forward to seeing the Wiki because I plan to use the
same mix of Spring, Velocity and Hibernate myself!

On 5/13/05, Will Glass-Husain <[hidden email]> wrote:

> Nice idea to build a wiki page.  We need to link Spring into the Wiki
> PoweredByVelocity page under Frameworks, too - it's now a very prominent
> example.
>
> I'm in the middle of a project combining Spring, Velocity, and Hibernate.
> It's a nice combination.
>
> WILL
>
> ----- Original Message -----
> From: "Shinobu Kawai" <[hidden email]>
> To: "Velocity Users List" <[hidden email]>
> Sent: Friday, May 13, 2005 11:28 AM
> Subject: Re: Passing data into a Velocity Template from a Spring Controller
>
> TWIMC,
>
> > 1) follow the Spring mvc tutorial (which makes it happen for jsps) and
> > then modify it for velocity (basically just by changing your view
> > resolver as per the ch 13 (views) of the spring ref.)
> > http://www.springframework.org/docs/MVC-step-by-step/Spring-MVC-step-by-step.html
>
> I just started creating a supplemental document for Velocity here:
>    http://wiki.apache.org/jakarta-velocity/VelocityAndSpringStepByStep
>
> Best regards,
> -- Shinobu
>
> --
> Shinobu Kawai <[hidden email]>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Passing data into a Velocity Template from a Spring Controller

Rob Koberg
In reply to this post by Tim Diggins (Subs)
Tim Diggins wrote:

> But I would recommend following through the spring mvc tutorial (except
> for the last page on db-stuff which has lots of locking problems... at
> least when launched from within eclipse ...).


It seems the tutorial was written for an older version of hsqldb (not
that I know much about it...). I put:

COMMIT;
SHUTDOWN;

before the sql end tag in the following Ant tasks from the tutorial:
createTables, dropTables and loadData

best,
-Rob



>
> Tim
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]