You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Stephen Riek <st...@yahoo.co.uk> on 2002/04/08 04:47:09 UTC

Freeing myself from JSP. VelocityServlet support for javabeans.

I love Velocity. It's bloody fast, has an elegant design and most importantly of all, whoever was responsible for documentation did a tremendous job. 

However, I still find prototyping in JSP to be quicker. One of the main reasons is the close integration of Javabeans such as 

<jsp:useBean id="ord" class="orderBean" scope="request">
  <jsp:setProperty name="ord" property="*"/>
</jsp:useBean>


Is there anything in the velocityServlet can do the same ? Or is there boilerplate code that should be able to do similar ?

Thanks in advance,

Stephen.



---------------------------------
Do You Yahoo!?
Get personalised at My Yahoo!.

Re: Freeing myself from JSP. VelocityServlet support for javabeans.

Posted by Terry Steichen <te...@net-frame.com>.
Put the bean in the Velocity context and use it from the template.  What I
often do is initially put all (or at least most) of my business logic in the
template (using context-based tools) and then later move the logic back to
the managing Java module.  This way I start with very fast prototyping, but
can migrate to well-compartmented code when I have time.

Regards,

Terry

----- Original Message -----
From: "Stephen Riek" <st...@yahoo.co.uk>
To: <ve...@jakarta.apache.org>
Sent: Sunday, April 07, 2002 10:47 PM
Subject: Freeing myself from JSP. VelocityServlet support for javabeans.


>
> I love Velocity. It's bloody fast, has an elegant design and most
importantly of all, whoever was responsible for documentation did a
tremendous job.
>
> However, I still find prototyping in JSP to be quicker. One of the main
reasons is the close integration of Javabeans such as
>
> <jsp:useBean id="ord" class="orderBean" scope="request">
>   <jsp:setProperty name="ord" property="*"/>
> </jsp:useBean>
>
>
> Is there anything in the velocityServlet can do the same ? Or is there
boilerplate code that should be able to do similar ?
>
> Thanks in advance,
>
> Stephen.
>
>
>
> ---------------------------------
> Do You Yahoo!?
> Get personalised at My Yahoo!.



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


Re: Freeing myself from JSP. VelocityServlet support for javabeans.

Posted by Ben Peter <bp...@zentropypartners.com>.
Stephen Riek wrote:
> However, I still find prototyping in JSP to be quicker. One of the main
> reasons is the close integration of Javabeans such as 
> 
> <jsp:useBean id="ord" class="orderBean" scope="request">
>   <jsp:setProperty name="ord" property="*"/>
> </jsp:useBean>
> 
> 
> Is there anything in the velocityServlet can do the same ? Or is there
> boilerplate code that should be able to do similar ?
> 

Velocity isn't too much centered around web applications.

You can use jakarta turbine for that. It allows you to build your views in both 
jsp and vm (and many others). It has a lot of convenience code, including above 
functionality, which would be achieved by calling 
runData.getParameters().setProperties(yourBean) in your custom Action. (Turbine 
is following an MVC-concept, in which you would rather have your above code in 
a 'Controller' class than in the view portion, which a JSP basically is.

That said, it should be easy to do much the same using 
jakarta-commons-beanutils - it might even provide what you need. Just put the 
relevant helper into you context and use that.

The following approach is untested:

1.) put the request and org.apache.commons.beanutils.BeanUtils in your context
2.) call $beanUtils.populate( $yourBean, $request.getParameterMap())

Cheers,
Ben

-- 
Benjamin Peter                                          +49-69-96244395
Application Engineer                             Moerfelder Landstr. 55
(zentropy:partners)                            60598 Frankfurt, Germany


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


RE: velstruts ?'s

Posted by "Charles N. Harvey III" <ch...@alloy.com>.
So... is there any way for me to manually configure it now?
Or, is there some way I could do this differently?  I have a lot
of templates and I do not want them in /WEB-INF/...  I would like
to have them elsewhere on the filesystem (possibly on another machine).
So is there currently a way for me to configure this?

Thanks.

Charlie

> -----Original Message-----
> From: Gabriel Sidler [mailto:sidler@teamup.ch]
> Sent: Tuesday, April 09, 2002 6:46 AM
> To: Velocity Users List
> Subject: Re: velstruts ?'s
>
>
> You bring up a good point here. Currently, the resource loader is
> hard-coded in VelocityViewServlet. You cannot set it in the
> configuration file.
> It probaly should be changed such that I can be overwritten by
> the configuration file.
>
> Same thing applies to the logger.
>
> Geir, what do you think?
>
> Gabe
>
>
>
> Charles N. Harvey III wrote:
>
> > I have been toying with the VelocityViewServlet with Struts and so far
> > everything looks good.  I am actually understanding it and
> making progress.
> > Thanks Gabe and Geir for a cool product and good docs.
> >
> > I do have a question that I cannot figure out.
> >
> > When I was using VelocityServlet I could do this in the props file:
> >
> >
> ------------------------------------------------------------------
> ---------
> > resource.loader =
> > 		url
> > url.resource.loader.description =
> > 		Velocity Url Resource Loader
> > url.resource.loader.class =
> >
> org.apache.velocity.runtime.resource.loader.URLResourceLoader
> > url.resource.loader.root =
> > 		file:///c:/hosts/pcu/htdocs
> > url.resource.loader.cache =
> > 		false
> >
> ------------------------------------------------------------------
> ---------
> >
> >
> > Now, I want to be able to do the same thing (specify any old
> random place
> > for my templates) but all I see is this:
> >
> >
> ------------------------------------------------------------------
> ---------
> > resource.manager.class =
> > 		org.apache.velocity.runtime.resource.ResourceManagerImpl
> > resource.manager.cache.class =
> > 		org.apache.velocity.runtime.resource.ResourceCacheImpl
> >
> ------------------------------------------------------------------
> ---------
> >
> > And I am just not sure of how to make it work.  I have tried
> all kinds of
> > combinations "resource.manager.root", "url.resource.loader.root".  They
> > don't
> > seem to be working, can't find my template.  Any insight as to
> why what I
> > have doesn't work would be great.
> >
> > Thanks.
> >
> > Charlie
> >
> >
> > --
> > To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
> .
>
>


--
--
Gabriel Sidler
Software Engineer, Eivycom GmbH, Zurich, Switzerland


--
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: velstruts ?'s

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 4/9/02 6:56 PM, "Charles N. Harvey III" <ch...@alloy.com> wrote:

> I went in and made a hard-coded change to VelocityViewServlet and
> put in the url.resource.loader instead of the webapp.resource.loader.
> Works great.  Woo-hoo.  But, hard-coded bad.  If the webapp loader is
> the resource loader of choice I think I would like to know how to use it.

I think that you should have the choice to override that if you want.

I'll put something into VVS tonight for this...

> Basically, how do I specify where I have placed my templates?  Can I?
> Or must I keep templates in /WEB-INF/?  Where can I read up on the
> webapp loader?

You should be able to keep then anywhere in the webapp.

That's the point of it - so you don't have to configure anything, but just
keep the templates in the webapp.

For example, you should be able to keep them in the webapp root, and access
them like

  Template t = getTemplate("mytemplate.vm");

That simple...
 
> Thanks for the info.
> 
> Charlie
> 
>> -----Original Message-----
>> From: Geir Magnusson Jr. [mailto:geirm@optonline.net]
>> Sent: Tuesday, April 09, 2002 8:08 AM
>> To: velocity-user@jakarta.apache.org
>> Subject: Re: velstruts ?'s
>> 
>> 
>> On 4/9/02 6:46 AM, "Gabriel Sidler" <si...@teamup.ch> wrote:
>> 
>>> You bring up a good point here. Currently, the resource loader is
>>> hard-coded in VelocityViewServlet. You cannot set it in the
>>> configuration file.
>>> It probaly should be changed such that I can be overwritten by
>>> the configuration file.
>>> 
>>> Same thing applies to the logger.
>>> 
>>> Geir, what do you think?
>> 
>> I think it's valid and support the idea,  but it does make me think that
>> this takes VVS slightly afield of it's purpose, which was to be a drop in
>> for JspServlet - meaning that in JSP-land, you can just drop
>> things into the
>> webapp and invoke them, with output going to the servlet log.
>> 
>> Now, you would have to know about the local configuration.
>> 
>> While I think this is something we need to explicitly consider, I don't
>> think that it should stand in the way of the changes.  (Which would be
>> really easy...)
>> 
>> On the other hand, it's really cool that unlike JSP, you can move things
>> around like this :)
>> 
>> Geir
>> 
>>> 
>>> Gabe
>>> 
>>> 
>>> 
>>> Charles N. Harvey III wrote:
>>> 
>>>> I have been toying with the VelocityViewServlet with Struts and so far
>>>> everything looks good.  I am actually understanding it and
>> making progress.
>>>> Thanks Gabe and Geir for a cool product and good docs.
>>>> 
>>>> I do have a question that I cannot figure out.
>>>> 
>>>> When I was using VelocityServlet I could do this in the props file:
>>>> 
>>>> 
>> ------------------------------------------------------------------
>> ---------
>>>> resource.loader =
>>>> url
>>>> url.resource.loader.description =
>>>> Velocity Url Resource Loader
>>>> url.resource.loader.class =
>>>> org.apache.velocity.runtime.resource.loader.URLResourceLoader
>>>> url.resource.loader.root =
>>>> file:///c:/hosts/pcu/htdocs
>>>> url.resource.loader.cache =
>>>> false
>>>> 
>> ------------------------------------------------------------------
>> ---------
>>>> 
>>>> 
>>>> Now, I want to be able to do the same thing (specify any old
>> random place
>>>> for my templates) but all I see is this:
>>>> 
>>>> 
>> ------------------------------------------------------------------
>> ---------
>>>> resource.manager.class =
>>>> org.apache.velocity.runtime.resource.ResourceManagerImpl
>>>> resource.manager.cache.class =
>>>> org.apache.velocity.runtime.resource.ResourceCacheImpl
>>>> 
>> ------------------------------------------------------------------
>> ---------
>>>> 
>>>> And I am just not sure of how to make it work.  I have tried
>> all kinds of
>>>> combinations "resource.manager.root", "url.resource.loader.root".  They
>>>> don't
>>>> seem to be working, can't find my template.  Any insight as to
>> why what I
>>>> have doesn't work would be great.
>>>> 
>>>> Thanks.
>>>> 
>>>> Charlie
>>>> 
>>>> 
>>>> --
>>>> To unsubscribe, e-mail:
>>>> <ma...@jakarta.apache.org>
>>>> For additional commands, e-mail:
>>>> <ma...@jakarta.apache.org>
>>>> 
>>>> .
>>>> 
>>>> 
>>> 
>> 
>> --
>> Geir Magnusson Jr.                                     geirm@optonline.net
>> System and Software Consulting
>> My inner cowboy needs to yodel.
>> 
>> 
>> --
>> 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>
> 

-- 
Geir Magnusson Jr.                                     geirm@optonline.net
System and Software Consulting
Java : the speed of Smalltalk with the simple elegance of C++... 


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


RE: velstruts ?'s

Posted by "Charles N. Harvey III" <ch...@alloy.com>.
I went in and made a hard-coded change to VelocityViewServlet and
put in the url.resource.loader instead of the webapp.resource.loader.
Works great.  Woo-hoo.  But, hard-coded bad.  If the webapp loader is
the resource loader of choice I think I would like to know how to use it.
Basically, how do I specify where I have placed my templates?  Can I?
Or must I keep templates in /WEB-INF/?  Where can I read up on the
webapp loader?

Thanks for the info.

Charlie

> -----Original Message-----
> From: Geir Magnusson Jr. [mailto:geirm@optonline.net]
> Sent: Tuesday, April 09, 2002 8:08 AM
> To: velocity-user@jakarta.apache.org
> Subject: Re: velstruts ?'s
>
>
> On 4/9/02 6:46 AM, "Gabriel Sidler" <si...@teamup.ch> wrote:
>
> > You bring up a good point here. Currently, the resource loader is
> > hard-coded in VelocityViewServlet. You cannot set it in the
> > configuration file.
> > It probaly should be changed such that I can be overwritten by
> > the configuration file.
> >
> > Same thing applies to the logger.
> >
> > Geir, what do you think?
>
> I think it's valid and support the idea,  but it does make me think that
> this takes VVS slightly afield of it's purpose, which was to be a drop in
> for JspServlet - meaning that in JSP-land, you can just drop
> things into the
> webapp and invoke them, with output going to the servlet log.
>
> Now, you would have to know about the local configuration.
>
> While I think this is something we need to explicitly consider, I don't
> think that it should stand in the way of the changes.  (Which would be
> really easy...)
>
> On the other hand, it's really cool that unlike JSP, you can move things
> around like this :)
>
> Geir
>
> >
> > Gabe
> >
> >
> >
> > Charles N. Harvey III wrote:
> >
> >> I have been toying with the VelocityViewServlet with Struts and so far
> >> everything looks good.  I am actually understanding it and
> making progress.
> >> Thanks Gabe and Geir for a cool product and good docs.
> >>
> >> I do have a question that I cannot figure out.
> >>
> >> When I was using VelocityServlet I could do this in the props file:
> >>
> >>
> ------------------------------------------------------------------
> ---------
> >> resource.loader =
> >> url
> >> url.resource.loader.description =
> >> Velocity Url Resource Loader
> >> url.resource.loader.class =
> >> org.apache.velocity.runtime.resource.loader.URLResourceLoader
> >> url.resource.loader.root =
> >> file:///c:/hosts/pcu/htdocs
> >> url.resource.loader.cache =
> >> false
> >>
> ------------------------------------------------------------------
> ---------
> >>
> >>
> >> Now, I want to be able to do the same thing (specify any old
> random place
> >> for my templates) but all I see is this:
> >>
> >>
> ------------------------------------------------------------------
> ---------
> >> resource.manager.class =
> >> org.apache.velocity.runtime.resource.ResourceManagerImpl
> >> resource.manager.cache.class =
> >> org.apache.velocity.runtime.resource.ResourceCacheImpl
> >>
> ------------------------------------------------------------------
> ---------
> >>
> >> And I am just not sure of how to make it work.  I have tried
> all kinds of
> >> combinations "resource.manager.root", "url.resource.loader.root".  They
> >> don't
> >> seem to be working, can't find my template.  Any insight as to
> why what I
> >> have doesn't work would be great.
> >>
> >> Thanks.
> >>
> >> Charlie
> >>
> >>
> >> --
> >> To unsubscribe, e-mail:
> >> <ma...@jakarta.apache.org>
> >> For additional commands, e-mail:
> >> <ma...@jakarta.apache.org>
> >>
> >> .
> >>
> >>
> >
>
> --
> Geir Magnusson Jr.                                     geirm@optonline.net
> System and Software Consulting
> My inner cowboy needs to yodel.
>
>
> --
> 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: velstruts ?'s

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 4/9/02 6:46 AM, "Gabriel Sidler" <si...@teamup.ch> wrote:

> You bring up a good point here. Currently, the resource loader is
> hard-coded in VelocityViewServlet. You cannot set it in the
> configuration file.
> It probaly should be changed such that I can be overwritten by
> the configuration file.
> 
> Same thing applies to the logger.
> 
> Geir, what do you think?

I think it's valid and support the idea,  but it does make me think that
this takes VVS slightly afield of it's purpose, which was to be a drop in
for JspServlet - meaning that in JSP-land, you can just drop things into the
webapp and invoke them, with output going to the servlet log.

Now, you would have to know about the local configuration.

While I think this is something we need to explicitly consider, I don't
think that it should stand in the way of the changes.  (Which would be
really easy...)

On the other hand, it's really cool that unlike JSP, you can move things
around like this :)

Geir

> 
> Gabe
> 
> 
> 
> Charles N. Harvey III wrote:
> 
>> I have been toying with the VelocityViewServlet with Struts and so far
>> everything looks good.  I am actually understanding it and making progress.
>> Thanks Gabe and Geir for a cool product and good docs.
>> 
>> I do have a question that I cannot figure out.
>> 
>> When I was using VelocityServlet I could do this in the props file:
>> 
>> ---------------------------------------------------------------------------
>> resource.loader =
>> url
>> url.resource.loader.description =
>> Velocity Url Resource Loader
>> url.resource.loader.class =
>> org.apache.velocity.runtime.resource.loader.URLResourceLoader
>> url.resource.loader.root =
>> file:///c:/hosts/pcu/htdocs
>> url.resource.loader.cache =
>> false
>> ---------------------------------------------------------------------------
>> 
>> 
>> Now, I want to be able to do the same thing (specify any old random place
>> for my templates) but all I see is this:
>> 
>> ---------------------------------------------------------------------------
>> resource.manager.class =
>> org.apache.velocity.runtime.resource.ResourceManagerImpl
>> resource.manager.cache.class =
>> org.apache.velocity.runtime.resource.ResourceCacheImpl
>> ---------------------------------------------------------------------------
>> 
>> And I am just not sure of how to make it work.  I have tried all kinds of
>> combinations "resource.manager.root", "url.resource.loader.root".  They
>> don't
>> seem to be working, can't find my template.  Any insight as to why what I
>> have doesn't work would be great.
>> 
>> Thanks.
>> 
>> Charlie
>> 
>> 
>> --
>> To unsubscribe, e-mail:
>> <ma...@jakarta.apache.org>
>> For additional commands, e-mail:
>> <ma...@jakarta.apache.org>
>> 
>> .
>> 
>> 
> 

-- 
Geir Magnusson Jr.                                     geirm@optonline.net
System and Software Consulting
My inner cowboy needs to yodel.


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


Re: velstruts ?'s

Posted by Gabriel Sidler <si...@teamup.ch>.
You bring up a good point here. Currently, the resource loader is
hard-coded in VelocityViewServlet. You cannot set it in the
configuration file.
It probaly should be changed such that I can be overwritten by
the configuration file.

Same thing applies to the logger.

Geir, what do you think?

Gabe



Charles N. Harvey III wrote:

> I have been toying with the VelocityViewServlet with Struts and so far
> everything looks good.  I am actually understanding it and making progress.
> Thanks Gabe and Geir for a cool product and good docs.
> 
> I do have a question that I cannot figure out.
> 
> When I was using VelocityServlet I could do this in the props file:
> 
> ---------------------------------------------------------------------------
> resource.loader =
> 		url
> url.resource.loader.description =
> 		Velocity Url Resource Loader
> url.resource.loader.class =
> 		org.apache.velocity.runtime.resource.loader.URLResourceLoader
> url.resource.loader.root =
> 		file:///c:/hosts/pcu/htdocs
> url.resource.loader.cache =
> 		false
> ---------------------------------------------------------------------------
> 
> 
> Now, I want to be able to do the same thing (specify any old random place
> for my templates) but all I see is this:
> 
> ---------------------------------------------------------------------------
> resource.manager.class =
> 		org.apache.velocity.runtime.resource.ResourceManagerImpl
> resource.manager.cache.class =
> 		org.apache.velocity.runtime.resource.ResourceCacheImpl
> ---------------------------------------------------------------------------
> 
> And I am just not sure of how to make it work.  I have tried all kinds of
> combinations "resource.manager.root", "url.resource.loader.root".  They
> don't
> seem to be working, can't find my template.  Any insight as to why what I
> have doesn't work would be great.
> 
> Thanks.
> 
> Charlie
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 
> .
> 
> 


-- 
--
Gabriel Sidler
Software Engineer, Eivycom GmbH, Zurich, Switzerland


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


velstruts ?'s

Posted by "Charles N. Harvey III" <ch...@alloy.com>.
I have been toying with the VelocityViewServlet with Struts and so far
everything looks good.  I am actually understanding it and making progress.
Thanks Gabe and Geir for a cool product and good docs.

I do have a question that I cannot figure out.

When I was using VelocityServlet I could do this in the props file:

---------------------------------------------------------------------------
resource.loader =
		url
url.resource.loader.description =
		Velocity Url Resource Loader
url.resource.loader.class =
		org.apache.velocity.runtime.resource.loader.URLResourceLoader
url.resource.loader.root =
		file:///c:/hosts/pcu/htdocs
url.resource.loader.cache =
		false
---------------------------------------------------------------------------


Now, I want to be able to do the same thing (specify any old random place
for my templates) but all I see is this:

---------------------------------------------------------------------------
resource.manager.class =
		org.apache.velocity.runtime.resource.ResourceManagerImpl
resource.manager.cache.class =
		org.apache.velocity.runtime.resource.ResourceCacheImpl
---------------------------------------------------------------------------

And I am just not sure of how to make it work.  I have tried all kinds of
combinations "resource.manager.root", "url.resource.loader.root".  They
don't
seem to be working, can't find my template.  Any insight as to why what I
have doesn't work would be great.

Thanks.

Charlie


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


Re: Freeing myself from JSP. VelocityServlet support for javabeans.

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 4/7/02 10:47 PM, "Stephen Riek" <st...@yahoo.co.uk> wrote:

> 
> I love Velocity. It's bloody fast, has an elegant design and most importantly
> of all, whoever was responsible for documentation did a tremendous job.
> 

A new tag line for us :

"Velocity - it's bloody fast..."

:)

> However, I still find prototyping in JSP to be quicker. One of the main
> reasons is the close integration of Javabeans such as
> 
> <jsp:useBean id="ord" class="orderBean" scope="request">
> <jsp:setProperty name="ord" property="*"/>
> </jsp:useBean>
> 
> 
> Is there anything in the velocityServlet can do the same ? Or is there
> boilerplate code that should be able to do similar ?
> 

Yes - most of us seem to cough up our own for this, but there are a few ways
you can do this.  First, modulo the work going on re the toolbox, the
jakarta-velocity-tools project has a servlet VelocityViewServlet and concept
of toolbox loader that allows you to preconfigure tools to be available in
the context on any request, and map urls like  ...../foo.vm to be rendered
by that servlet, just like you map ...../foo.jsp to JspServlet (or it's done
for you...)

Now, that isn't perfect, because the webapps all get the same stuff.   You
could build off of that, putting a bean into the context that lets you load
other beans...

  #set($ord = $beaner.useBean('orderBean')
  $beaner.setProperty($ord, '*')

Gives you the same thing...  Watch out for the MVC police :)

Lastly, take a look at the list of webapp frameworks that support Velocity -
one might be light enough for simple prototyping...

geir

-- 
Geir Magnusson Jr.                                     geirm@optonline.net
System and Software Consulting

The cost of synchronization is much less that the cost of stupidity.


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