velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim Diggins <subscri...@red56.co.uk>
Subject Re: Passing data into a Velocity Template from a Spring Controller
Date Fri, 13 May 2005 16:05:08 GMT
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" <jackcholt@gmail.com>
> To: <velocity-user@jakarta.apache.org>
> 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: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
> 
> 


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


Mime
View raw message